public CPoint GetNextPoint() { CPoint head = pList.Last(); CPoint nextPoint = new CPoint(head); ; nextPoint.Move(1, direction); return nextPoint; }
public HorizontalLine(int xLeft, int xRight, int y, char sym) { pList = new List<CPoint>(); for (int x = xLeft; x <= xRight; x++) { CPoint p = new CPoint(x, y, sym); pList.Add(p); } }
public VerticalLine(int yUp, int yDown, int x, char sym) { pList = new List<CPoint>(); for (int y = yUp; y <= yDown; y++) { CPoint p = new CPoint(x, y, sym); pList.Add(p); } }
internal bool Eat(CPoint food) { CPoint head = GetNextPoint(); if (head.IsHit(food)) { food.sym = head.sym; pList.Add(food); return true; } else return false; }
public Snake(CPoint tail, int length, Direction _direction) { direction = _direction; pList = new List<CPoint>(); for (int i = 0; i < length; i++) { CPoint p = new CPoint(tail); p.Move(i, direction); pList.Add(p); } }
private bool IsHit(CPoint point) { foreach (var p in pList) { if (point.IsHit(p)) { return true; } } return false; }
static void Main(string[] args) { Console.SetBufferSize(80, 25); Walls walls = new Walls(80, 25); walls.Draw(); //отрисовка змейки CPoint p = new CPoint(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); //food FoodCreator foodCreator = new FoodCreator(80, 25, '$'); CPoint food = foodCreator.CreateFood(); food.Draw(); //цикл игры while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } //Console.ReadKey(); }
internal bool IsHit(CPoint p) { return this.x == p.x && this.y == p.y; }
public CPoint(CPoint p) { x = p.x; y = p.y; sym = p.sym; }