Ejemplo n.º 1
0
        public void PlayGame()
        {
            bool isPlaying = true;

            wasMoveValid = true;
            BoardMovement moveBoard = new BoardMovement();

            do
            {
                List <EmptyCells> emptyCells = BoardTiles.GetEmpty();

                if (emptyCells.Count != 0 && wasMoveValid)
                {
                    moveBoard.CurrentScore += InsertTwoOrFour(emptyCells);
                }

                DisplayBoard();
                Console.WriteLine("\n Current score: " + moveBoard.CurrentScore);

                var input = Console.ReadKey();
                if (input.Key == ConsoleKey.UpArrow)
                {
                    wasMoveValid = moveBoard.MoveBoard(HelperMethods.Direction.Up, ref BoardTiles);
                }
                if (input.Key == ConsoleKey.DownArrow)
                {
                    wasMoveValid = moveBoard.MoveBoard(HelperMethods.Direction.Down, ref BoardTiles);
                }
                if (input.Key == ConsoleKey.LeftArrow)
                {
                    wasMoveValid = moveBoard.MoveBoard(HelperMethods.Direction.Left, ref BoardTiles);
                }
                if (input.Key == ConsoleKey.RightArrow)
                {
                    wasMoveValid = moveBoard.MoveBoard(HelperMethods.Direction.Right, ref BoardTiles);
                }
                if (BoardTiles.GetEmpty().Count == 0 && isGameOver(BoardTiles, moveBoard))
                {
                    isPlaying = false;
                }
            } while (isPlaying);

            Console.Clear();
            Console.WriteLine("You lose press any key to start again");
        }
Ejemplo n.º 2
0
 public bool isGameOver(int[,] board, BoardMovement moveBoard)
 {
     foreach (HelperMethods.Direction direction in Enum.GetValues(typeof(HelperMethods.Direction)))
     {
         if (moveBoard.MoveBoard(direction, ref board))
         {
             return(false);
         }
     }
     return(true);
 }