public Point1 GetNextPoint() { Point1 head = pList.Last(); Point1 nextPoint = new Point1(head); nextPoint.Move(1, direction); return(nextPoint); }
public VerticalLine(int yUp, int yDown, int x, char sym) { pList = new List <Point1>(); for (int y = yUp; y <= yDown; y++) { Point1 p = new Point1(x, y, sym); pList.Add(p); } }
public HorizontalLine(int xLeft, int xRight, int y, char sym) { pList = new List <Point1>(); for (int x = xLeft; x <= xRight; x++) { Point1 p = new Point1(x, y, sym); pList.Add(p); } }
private bool IsHit(Point1 point) { foreach (var p in pList) { if (p.IsHit(point)) { return(true); } } return(false); }
public Snake(Point1 tail, int length, Direction _direction) { direction = _direction; pList = new List <Point1>(); for (int i = 0; i < length; i++) { Point1 p = new Point1(tail); p.Move(i, direction); pList.Add(p); } }
internal void Move() { Point1 tail = pList.First(); pList.Remove(tail); Point1 head = GetNextPoint(); pList.Add(head); tail.Clear(); head.Draw(); }
internal bool Eat(Point1 food) { Point1 head = GetNextPoint(); if (head.IsHit(food)) { food.sym = head.sym; pList.Add(food); return(true); } else { return(false); } }
static void Main(string[] args) { Console.SetWindowSize(1, 1); Console.SetBufferSize(80, 25); Console.SetWindowSize(80, 25); Walls walls = new Walls(80, 25); walls.Draw(); // Отрисовка точек Point1 p = new Point1(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); FoodCreator foodCreator = new FoodCreator(80, 25, '$'); Point1 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); } } }
static void Main(string[] args) { Point1 p1 = new Point1(); p1.x = 1; p1.y = 3; p1.sym = '*'; p1.Draw(); Point1 p2 = new Point1(); p2.x = 4; p2.y = 5; p2.sym = '#'; p2.Draw(); Console.ReadLine(); }
public bool IsHit(Point1 p) { return(p.x == this.x && p.y == this.y); }
public Point1(Point1 p) { x = p.x; y = p.y; sym = p.sym; }