贪吃蛇小项目

This commit is contained in:
2025-09-21 20:11:21 +08:00
parent 0a1446e7b3
commit 116b65164b
18 changed files with 695 additions and 25 deletions
+49
View File
@@ -0,0 +1,49 @@
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();
}
}
}
}