Exemplo n.º 1
0
 public Game()
 {
     _turtle    = new Turtle();
     _gameBoard = new GameBoard();
     _quit      = false;
     _pen       = Pen.PenActions.Up;
     _direction = Directions.TurtleDirections.South;
 }
Exemplo n.º 2
0
        internal void GameLoop()
        {
            _gameBoard.InitiateGameBoard();

            do
            {
                Console.Clear();

                Console.WriteLine(Messages.ErrorMessage);
                Messages.ErrorMessage = string.Empty;

                _gameBoard.DrawGameBoard(_turtle.PositionX, _turtle.PositionY, _turtle.TurtleSymbol);
                Messages.Instructions();
                Console.WriteLine("Pen is " + (_pen == Pen.PenActions.Down ? "drawing" : "not drawing") + ".");
                Console.WriteLine($"Turtle is moving {_direction}.");

                Console.Write("Select your option: ");
                if (int.TryParse(Console.ReadLine(), out _option))
                {
                    if (_option > 0 && _option < 3)
                    {
                        _pen = (Pen.PenActions)_option;
                    }
                    else if (_option > 2 && _option < 7)
                    {
                        _direction = (Directions.TurtleDirections)_option;
                        Console.WriteLine($"Turtle is moving {_direction}.");
                        Console.Write("Enter number of spaces to move: ");
                        int spaces;
                        if (int.TryParse(Console.ReadLine(), out spaces))
                        {
                            _turtle.Walk(_direction, spaces, _pen);
                        }
                        else
                        {
                            Messages.InvalidInput();
                        }
                    }
                    else if (_option == 7)
                    {
                        _quit = true;
                    }
                    else
                    {
                        Messages.InvalidInput();
                    }
                }
                else
                {
                    Messages.InvalidInput();
                }
            } while (!_quit);
        }
Exemplo n.º 3
0
        public void GameLoop()
        {
            _gameBoard.InitGameBoard();

            do
            {
                Console.Clear();                                     //prepare screen for next display
                Console.WriteLine(Messages.ErrorMessage);            //display any erro message (or blank if no error message)
                Messages.ErrorMessage = "";                          //reset error message for next input
                _gameBoard.DrawGameBoard(_turtle.PositionX, _turtle.PositionY, _turtle.TurtleSymbol);
                Messages.Instructions();                             //display game instructions
                Console.WriteLine("Pen is " + (_pen == Pen.PenActions.Down ? "DRAWING" : "NOT DRAWING"));
                Console.WriteLine($"Turtle is moving {_direction}"); //display what direction was selected
                Console.WriteLine("Select your option: ");

                if (int.TryParse(Console.ReadLine(), out _option))  //make sure input is an integer
                {
                    if (_option > 0 && _option < 3)
                    {
                        _pen = (Pen.PenActions)_option;
                    }
                    else if (_option > 2 && _option < 7)
                    {
                        _direction = (Directions.TurtleDirections)_option;
                        Console.WriteLine($"Turtle is moving {_direction}");  //display what direction was selected
                        Console.WriteLine("Enter number of spaces to move: ");
                        int spaces;
                        if (int.TryParse(Console.ReadLine(), out spaces))
                        {
                            _turtle.Walk(_direction, spaces, _pen);
                        }
                        else
                        {
                            Messages.InvalidInput();
                        }
                    }
                    else if (_option == 7)
                    {
                        _quit = true;
                    }
                    else
                    {
                        Messages.InvalidInput();
                    }
                }
                else
                {
                    Messages.InvalidInput();
                }
            } while (!_quit);
        }
        internal void Walk(Directions.TurtleDirections direction, int spaces, Pen.PenActions pen)
        {
            if (ValidateMove(direction, spaces))
            {
                bool toDraw = (pen == Pen.PenActions.Down);

                switch (direction)
                {
                case Directions.TurtleDirections.North:
                    if (toDraw)
                    {
                        GameBoard.UpdateGameBoardX(PositionX, spaces, -1, PositionY);
                    }
                    PositionX -= spaces;
                    break;

                case Directions.TurtleDirections.South:
                    if (toDraw)
                    {
                        GameBoard.UpdateGameBoardX(PositionX, spaces, 1, PositionY);
                    }
                    PositionX += spaces;
                    break;

                case Directions.TurtleDirections.East:
                    if (toDraw)
                    {
                        GameBoard.UpdateGameBoardY(PositionY, spaces, 1, PositionX);
                    }
                    PositionY += spaces;
                    break;

                case Directions.TurtleDirections.West:
                    if (toDraw)
                    {
                        GameBoard.UpdateGameBoardY(PositionY, spaces, -1, PositionX);
                    }
                    PositionY -= spaces;
                    break;
                }
            }
        }