贪吃蛇小项目

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
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
abstract class GameObject : IDraw
{
//当前位置
public Position pos;
//绘制对象
//可以继承接口后,把接口中的方法变成抽象方法,让子类去实现
//因为时抽象行为,所以子类必须实现
public abstract void Draw();
}
}
+13
View File
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
interface IDraw
{
void Draw();
}
}
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace
{
struct Position
{
public int x;
public int y;
public Position(int x, int y)
{
this.x = x;
this.y = y;
}
//重载==和!=运算符来判断两个Position是否相等
public static bool operator == (Position p1, Position p2)
{
return p1.x == p2.x && p1.y == p2.y;
}
public static bool operator !=(Position p1, Position p2)
{
return !(p1 == p2);
}
}
}