贪吃蛇小项目
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user