public point OtherPoint(point p) { if (p == pList.First()) return pList.Last(); else return pList.First(); }
point NextPoint() { point head = pList.Last(); point NextPoint = new point(head); NextPoint.Move(1, Direction); return NextPoint; }
public new point IsHit(point head) { if (head.IsHit(pList.First())) return pList.First(); if (head.IsHit(pList.Last())) return pList.Last(); return null; }
public portal(int x1, int y1, int x2, int y2) { pList = new List<point>(); point port1 = new point(x1, y1, 5); pList.Add(port1); point port2 = new point(x2, y2, 5); pList.Add(port2); Draw(); }
public bool IsHit(point p) { foreach (var point in pList) { if (p.IsHit(point)) return true; } return false; }
public line_vertical(int yu, int yd, int x, int s) { pList = new List<point>(); for (int y = yu; y <= yd; y++) { point p = new point(x, y, s); pList.Add(p); } }
public line_horizontal(int xl, int xr, int y, int s) { pList = new List<point>(); for (int x = xl; x <= xr; x++) { point p = new point(x, y, s); pList.Add(p); } }
public snake(point pos, int length, direction dir) { Direction = dir; pList = new List<point>(); for (int i = 0; i < length; i++) { point p = new point(pos); p.Move(i, dir); pList.Add(p); } Draw(); }
public bool Eat(point food) { point head = NextPoint(); if (head.IsHit(food)) { pList.Add(food); food.ChangeChar(3); score++; return true; } else return false; }
public point Next(snake Snake, walls wall) { int x; int y; point p; do { x = rnd.Next(1, whidth - 1); y = rnd.Next(1, height - 1); p = new point(x, y, s); } while (Snake.IsHit(p) || wall.IsHit(p)); return p; }
public Game(int width, int height, int speed) { this.width = width; this.height = height; if (speed == 1) delay = 300; else if (speed == 2) delay = 200; else if (speed == 3) delay = 100; else if (speed == 4) delay = 50; else if (speed == 5) delay = 25; this.speed = speed; pos = new point(11, 11, 3); }
public bool IsHit(point p) { foreach (var wall in wallList) { if (wall.IsHit(p)) return true; } return false; }
public bool IsHit(point p) { return p.x == this.x && p.y == this.y; }
public point(point p, int s) { x = p.x; y = p.y; SetChar(s); }
public point(point p) { x = p.x; y = p.y; s = p.s; }
public void Teleport(point port) { var tail = pList.Last(); pList.Remove(tail); tail.Clear(); var head = new point(port, 3); head.Move(1, Direction); pList.Add(head); }
public int Start(int lvl) { Console.Clear(); Console.SetCursorPosition(width / 2 - 5, height / 2); Console.Write("Уровень " + lvl.ToString()); Thread.Sleep(1000); Console.Clear(); Console.SetCursorPosition(3, height + 2); Console.Write("Счет:"); Console.SetCursorPosition(10, height + 2); Console.Write("Уровень:"); Console.SetCursorPosition(13, height + 3); Console.Write(lvl); Snake = new snake(pos, 4, direction.RIGHT); Console.SetCursorPosition(5, height + 3); Console.Write(Snake.GetScore() * speed); wall = new walls(width, height, lvl); fp = new foodpoint(width, height, 2); food = fp.Next(Snake, wall); food.Draw(); Play(1); int sc = Snake.GetScore() * speed; Snake.ResetScore(); return sc; }
bool Play(int lvl) { while (true) { wall.Draw(); food.Draw(); if (Snake.GetScore() == 10 * lvl) return true; if (wall.IsHit(Snake) || Snake.IsHitTail()) { return false; } if (wall.Portal != null) { point p = wall.Portal.IsHit(Snake.GetHead()); if (p != null) { Snake.Teleport(wall.Portal.OtherPoint(p)); } } if (Snake.Eat(food)) { Console.SetCursorPosition(5, height + 3); Console.Write(Snake.GetScore() * speed); food = fp.Next(Snake, wall); food.Draw(); } else { Snake.Move(); } Thread.Sleep(delay); ctrl CtrlRes = Ctrl.GetCtrl(); if (CtrlRes == ctrl.Spacebar) { while (true) { CtrlRes = Ctrl.GetCtrl(); if (CtrlRes == ctrl.Spacebar) break; } } else if (CtrlRes == ctrl.Escape) { return false; } else if (CtrlRes == ctrl.Insert) { food = fp.Next(Snake, wall); food.Draw(); } else Snake.HandleSnake(CtrlRes); } }