Пример #1
0
 /// <summary>
 /// this method, called everytime the snake moves, will draw the
 /// snake, apple, and score
 /// </summary>
 /// <param name="snake">the player snake</param>
 /// <param name="apple">randomly genereated apple</param>
 static void PrintGame(List <Block> snake, Block apple)
 {
     DrawOrDeleteSnake(Player, PlayerHead, snake);
     Console.SetCursorPosition(apple.GetX(), apple.GetY());
     Console.Write(Apple);
     Console.SetCursorPosition(0, BoardY);
     Console.WriteLine("Score: " + (snake.Count - 3));
 }
Пример #2
0
        /// <summary>
        /// spawns a snake in a random position facing a random direction
        /// </summary>
        /// <param name="rand">random number generator</param>
        /// <returns>snake</returns>
        static List <Block> SpawnSnake(Random rand)
        {
            // spawn in a random block in the middle half of the board
            Block        start = new Block(rand.Next(BoardX / 4, BoardX / 2), rand.Next(BoardY / 4, BoardY / 2));
            List <Block> snake = new List <Block>();

            snake.Add(start);
            // generates a random int. uses this to determine which direction snake faces
            int direction = rand.Next(1, 5);

            switch (direction)
            {
            // facing up
            case 1:
                snake.Add(new Block(start.GetX(), start.GetY() + 1));
                snake.Add(new Block(start.GetX(), start.GetY() + 2));
                break;

            // facing down
            case 2:
                snake.Add(new Block(start.GetX(), start.GetY() - 1));
                snake.Add(new Block(start.GetX(), start.GetY() - 2));
                break;

            // facing left
            case 3:
                snake.Add(new Block(start.GetX() + 1, start.GetY()));
                snake.Add(new Block(start.GetX() + 2, start.GetY()));
                break;

            // facing right
            case 4:
                snake.Add(new Block(start.GetX() - 1, start.GetY()));
                snake.Add(new Block(start.GetX() - 2, start.GetY()));
                break;
            }

            return(snake);
        }