public void StartGame() { snake.SnakeTail = Snake.InitializeSnake(2, this.level); this.points = 20; this.GameOver = false; this.currentKey = ConsoleKey.Delete; this.speed = 300; GenerateFoodCustomLevel(); while (this.GameOver == false) { if (Console.KeyAvailable) { this.currentKey = Console.ReadKey(true).Key; if (this.lastKey == this.currentKey) { if (this.speed > 100) { this.speed -= 40; } else if (this.speed > 30) { this.speed -= 10; } continue; } this.speed = 300; } // Drawing and updating Console.Clear(); Environment.DrawCustomArea(this.customLevel); DrawSpeed(); DrawPoints(); Environment.DrawFood(this.foodPositionX, this.foodPositionY); currentKey = snake.Update(currentKey, lastDirectionKey); snake.Draw(); snake.DrawLength(); if (snake.CollisionWithSnake()) { this.GameOver = true; break; } if (snake.CollisionWithCustomWall(this.customLevel)) { this.GameOver = true; break; } if (snake.CollisionWithFood(this.foodPositionX, this.foodPositionY)) { this.points += 10; GenerateFoodCustomLevel(); } Thread.Sleep(this.speed); this.lastKey = this.currentKey; lastDirectionKey = currentKey; } this.bestScore = int.Parse(File.ReadLines(Directory.GetCurrentDirectory() + @"\scores\" + currentCustomLevelName + "Score" + ".txt").First()); Console.Clear(); if (this.points > this.bestScore) { File.WriteAllText(Directory.GetCurrentDirectory() + @"\scores\" + this.currentCustomLevelName + "Score" + ".txt", this.points.ToString()); Console.WriteLine($"New record: {points}"); Console.WriteLine($"Previus best score: {bestScore}"); } else { Console.WriteLine($"Current score: {points}"); Console.WriteLine($"Best score score: {bestScore}"); } Thread.Sleep(2500); }