📄 floor.cs
字号:
using System;
using System.Drawing;
namespace WindowsApplication9
{
public class Floor
{
public Floor(Point p)
{
vertex = p;
s = new Snake(p, 10);
currentBean = new Bean();
currentBean.Origin = new Point(p.X +30,p.Y + 30);
}
private static int unitLength = 5;
private int width = 60 * unitLength;
private int height = 30 * unitLength;
private Point vertex;
private Snake s;
public Snake S
{
get { return s; }
}
private Bean currentBean;
public void DisplayNextBean(Graphics g)
{
currentBean.UnDisplay(g);
currentBean = getRandomBean();
currentBean.Display(g);
}
private Bean getRandomBean()
{
Random random = new Random();
int x = random.Next(width/unitLength);
int y = random.Next(height/unitLength);
Point p = new Point(vertex.X + x * 5, vertex.Y + y * 5);
Bean newB = new Bean();
newB.Origin = p;
return newB;
}
public void ReSet(Graphics g)
{
s.UnDisplay(g);
s.Reset(vertex, 10);
}
public void initFloor(Graphics g)
{
Pen p = new Pen(Color.Red);
g.DrawRectangle(p, vertex.X,vertex.Y,width,height);
}
public void Display(Graphics g)
{
Pen p = new Pen(Color.Red);
g.DrawRectangle(p, vertex.X,vertex.Y,width,height);
currentBean.Display(g);
CheckBean(g);
CheckSnake();
s.Display(g);
}
public void CheckBean(Graphics g)
{
if (currentBean.Origin.Equals(s.getHeadPoint))
{
currentBean.Function(s);
this.DisplayNextBean(g);
}
}
public void CheckSnake()
{
if ((vertex.X <= s.getHeadPoint.X && s.getHeadPoint.X < (vertex.X + width)) &&
(vertex.Y <= s.getHeadPoint.Y && s.getHeadPoint.Y < (vertex.Y + height)) && !s.getHitSelf)
{
return;
}
else
{
s.SnakeDie();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -