Files
Csharp/C#核心实践/贪吃蛇/Lesson5/Map.cs
T
2025-09-21 20:11:21 +08:00

50 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 贪吃蛇
{
class Map : IDraw
{
public Wall[] walls; //存放墙位置的数组
public Map()
{
//初始化墙
walls = new Wall[Game.w + (Game.h -3) * 2];
int index = 0;
//上边墙
for (int x = 0; x < Game.w; x+=2)
{
walls[index++] = new Wall(x, 0);
}
//下边墙
for (int x = 0; x < Game.w; x+=2)
{
walls[index++] = new Wall(x, Game.h - 2);
}
//左边墙
for (int y = 1; y < Game.h - 2; y++)
{
walls[index++] = new Wall(0, y);
}
//右边墙
for (int y = 1; y < Game.h - 2; y++)
{
walls[index++] = new Wall(Game.w - 2, y);
}
}
public void Draw()
{
for (int x = 0; x < walls.Length; x++)
{
walls[x].Draw();
}
}
}
}