static public void Update() { ConsoleKeyInfo key; key = new ConsoleKeyInfo(); while (key.Key != ConsoleKey.Spacebar && !SnakePointsManager.OnCollisionWalls() & !SnakePointsManager.OnCollisionSelf()) { if (Console.KeyAvailable) { key = Console.ReadKey(true); CheckKeyPressed(key); if (!pause) { SnakePointsManager.MoveController(key); } } if (!pause) { Thread.Sleep(UpdateTime); Console.ForegroundColor = ConsoleColor.Red; SnakePointsManager.EatingFruit(); SnakePointsManager.MoveSnake(); Console.ForegroundColor = ConsoleColor.White; SnakePointsManager.ShowSceneSnake(); } } }
public SnakePoint(int x, int y, bool isHead = false) { X = x; Y = y; this.isHead = isHead; prevPoint = SnakePointsManager.EndElement(this); SnakePointsManager.AddInList(this); }
public static void GeneratePoint() { int x, y; Random random = new Random(); x = random.Next(1, WallPointsManager.Width - 1); y = random.Next(1, WallPointsManager.Height - 1); if (!SnakePointsManager.CheckedList(x, y) && !WallPointsManager.CheckedList(x, y) && !CheckedList(x, y)) { FruitPoint fruitPoint = new FruitPoint(x, y); } else { GeneratePoint(); } }
static public void StartGame() { WallPointsManager.BuildSceneWalls(0, 0, 79, 79); SnakePointsManager.StartGame(10, 40); WallPointsManager.ShowSceneWalls(); Console.ForegroundColor = ConsoleColor.Red; ShowLabel("Нажмите \"Escape\" чтобы начать игру", 20, 20); ShowLabel("Чтобы поставить игру на паузу нажмите \"Escape\"", 20, 21); ShowLabel("Чтобы убрать паузу нажмите \"Escape\"", 20, 22); ShowLabel("Чтобы принудительно закончить игру нажмите \"Space\"", 20, 23); Console.SetWindowSize(79, 79); Console.SetWindowPosition(0, 0); Console.SetBufferSize(79, 79); while (Console.ReadKey(true).Key != ConsoleKey.Escape) { } pause = !pause; ShowLabel(" ", 20, 20); ShowLabel(" ", 20, 21); ShowLabel(" ", 20, 22); ShowLabel(" ", 20, 23); FruitPointManager.GenerateFruits(); FruitPointManager.ShowSceneFruit(); }