public static void Init() { isActive = true; snake = new Snake(); food = new Food(); wall = new Wall(); // bastapkida paida bolatin jerler snake.body.Add(new Point { x = 1, y = 1 }); food.body.Add(new Point { x = 1, y = 2 }); food.color = ConsoleColor.Green; wall.color = ConsoleColor.White; snake.color = ConsoleColor.Yellow; Console.SetWindowSize(90, 20); // oin otetin bolikterdi rewetkalarmen korwau for (int i = 0; i <= 40; i++) { wall.body.Add(new Point { x = i, y = 0 }); wall.body.Add(new Point { x = i, y = 15 }); } for (int i = 0; i <= 15; i++) { wall.body.Add(new Point { x = 0, y = i }); wall.body.Add(new Point { x = 40, y = i }); } for (int i = 43; i <= 65; i++) { wall.body.Add(new Point { x = i, y = 0 }); wall.body.Add(new Point { x = i, y = 5 }); } for (int i = 0; i <= 5; i++) { wall.body.Add(new Point { x = 43, y = i }); wall.body.Add(new Point { x = 65, y = i }); } }
public void Play() { Thread t = new Thread(Movesnake); t.Start(); while (!gameover) { if (Game.snake.body.Count() == 2 + level) { level += 1; speed -= 40; wall = new Wall(level); int a = Game.snake.body[0].x; int b = Game.snake.body[0].y; Game.snake.body.Clear(); Game.food.body.Clear(); Console.Clear(); Game.wall.Draw(); Init(); Game.snake.body.Add(new Point(a, b)); } ConsoleKeyInfo button = Console.ReadKey(); if (button.Key == ConsoleKey.LeftArrow) { if ((Game.snake.body.Count > 1 && Game.snake.body[0].x - 1 != Game.snake.body[1].x) || Game.snake.body.Count == 1) dir = Direction.left; } if (button.Key == ConsoleKey.RightArrow) { if ((Game.snake.body.Count > 1 && Game.snake.body[0].x + 1 != Game.snake.body[1].x) || Game.snake.body.Count == 1) dir = Direction.right; } if (button.Key == ConsoleKey.UpArrow) { if ((Game.snake.body.Count > 1 && Game.snake.body[0].y - 1 != Game.snake.body[1].y) || Game.snake.body.Count == 1) dir = Direction.up; } if (button.Key == ConsoleKey.DownArrow) { if ((Game.snake.body.Count > 1 && Game.snake.body[0].y + 1 != Game.snake.body[1].y) || Game.snake.body.Count == 1) dir = Direction.down; } if (button.Key == ConsoleKey.Escape) break; if (button.Key == ConsoleKey.F2) Save(); if (button.Key == ConsoleKey.F3) Resume(); } if (gameover == true) { Console.SetCursorPosition(30, 15); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("GAME OVER"); ConsoleKeyInfo newgame = Console.ReadKey(); if (newgame.Key == ConsoleKey.F10) { gameover = false; Console.Clear(); Draw(); Game.wall.Draw(); Play(); } } else{} }