public ClassPoint GetNextPoint() { ClassPoint head = pList.Last(); ClassPoint nextPoint = new ClassPoint(head); nextPoint.Move(1, direction); return(nextPoint); }
public VLine(int yTop, int yBottom, int x, char ch) { pList = new List <ClassPoint>(); for (int y = yTop; y <= yBottom; y++) { ClassPoint p = new ClassPoint(x, y, ch); pList.Add(p); } }
public HLine(int xLeft, int xRight, int y, char ch) { pList = new List <ClassPoint>(); for (int x = xLeft; x <= xRight; x++) { ClassPoint p = new ClassPoint(x, y, ch); pList.Add(p); } }
public bool IsHit(ClassPoint point) { foreach (var p in pList) { if (p.IsHit(point)) { return(true); } } return(false); }
public Snake(ClassPoint tail, int lenght, Direction _direction) { direction = _direction; pList = new List <ClassPoint>(); for (int i = 0; i < lenght; i++) { ClassPoint p = new ClassPoint(tail); p.Move(i, direction); pList.Add(p); } }
internal void Move() { ClassPoint tail = pList.First(); pList.Remove(tail); ClassPoint head = GetNextPoint(); pList.Add(head); tail.Clear(); head.pointDraw(); }
internal bool Eat(ClassPoint food) { ClassPoint head = GetNextPoint(); if (head.IsHit(food)) { food.ch = head.ch; pList.Add(food); return(true); } else { return(false); } }
static void Main(string[] args) { Console.SetBufferSize(80, 25); Walls walls = new Walls(80, 25); walls.Draw(); ClassPoint p = new ClassPoint(2, 4, '*'); Snake snake = new Snake(p, 3, Direction.DOWN); snake.Draw(); FoodCreator foodCreator = new FoodCreator(80, 25, '$'); ClassPoint food = foodCreator.CreateFood(); food.pointDraw(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { By bye = new By(); bye.SayBy(); break; } if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.pointDraw(); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } Console.ReadKey(); }
public bool IsHit(ClassPoint p) { return(p.x == this.x && p.y == this.y); }
public ClassPoint(ClassPoint p) { x = p.x; y = p.y; ch = p.ch; }