Beispiel #1
0
        //We may want to investigate setting the window size.

        //DrawBoard is the turn mechanism for the game.
        public void DrawBoard(GameOptions gameOptions)
        {
            bool dead = false;

            while (dead == false)
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine($"     Score: {score}     High Score: xxxxx");
                DrawBoardTop(gameOptions.BoardWidth);
                DrawBoardLine(gameOptions.BoardWidth, gameOptions.BoardHeight);
                DrawBoardBottom(gameOptions.BoardWidth);
                if (Console.KeyAvailable) //This is true if a key has been pressed. This prevents the game for waiting for a key stroke.
                {
                    var changeDirection = Console.ReadKey(true).Key;
                    switch (changeDirection)
                    {
                    case ConsoleKey.LeftArrow:
                        snakeRepo.GetSnake(0).Direction = MoveDirection.Left;
                        break;

                    case ConsoleKey.UpArrow:
                        snakeRepo.GetSnake(0).Direction = MoveDirection.Up;
                        break;

                    case ConsoleKey.RightArrow:
                        snakeRepo.GetSnake(0).Direction = MoveDirection.Right;
                        break;

                    case ConsoleKey.DownArrow:
                        snakeRepo.GetSnake(0).Direction = MoveDirection.Down;
                        break;
                    }
                }
                snakeRepo.AddSnake(snakeRepo.CreateNewHead(snakeRepo.GetSnake(0))); //Creates a new snake object and ADDs it at index 0 to the _gameSnake List, so its the first object in the list.
                snakeRepo.RemoveSnake();                                            //Removes the highest index snake object from the _gameSnake list

                dead = CheckCollision(snakeRepo.GetSnake(0), gameOptions);          // Checks for snake collision and death
                //Remove Fruit, add a new random fruit, and increase score by fruit value.
                bool EatFruit = CheckForFruit(snakeRepo.GetSnake(0), gameOptions);
                if (EatFruit)
                {
                    ItemLocations itemToRemove = GetItem(snakeRepo.GetSnake(0).XAxis, snakeRepo.GetSnake(0).YAxis);
                    gameItems.Remove(itemToRemove);
                    while (gameItems.Count < 3)
                    {
                        gameItems.Add(AddGameItems(gameOptions));
                        RemoveNullItems();
                    }

                    snakeRepo.AddSnake(snakeRepo.CreateNewHead(snakeRepo.GetSnake(0)));
                }

                Thread.Sleep(gameSpeed); // <- Needs to be set with the difficulty paramater #################################
                Console.Clear();
            }
            Console.WriteLine("You DEAD!"); // Needs to implement Rochelles menu and replace lines 86 & 87

            Console.WriteLine("Congratulations! You've achieved a high score. Please enter your name:");
            var    UserNameInput = Console.ReadLine();
            string userScore     = HighScore.ShowPlayerScore(UserNameInput, score);

            Console.WriteLine("??");
            Console.WriteLine($"{userScore}");
            Console.ReadLine();
        }