Example #1
0
        public void Run()
        {
            board.InsertNewNumber();
            CopyBoard(board);
            this.renderer.RenderBoard(board);

            while (true)
            {
                try
                {
                    if (CheckEndGame(this.board))
                    {
                        renderer.PrintMessages(ExceptionMessages.GameOverMessage);
                        AskToPlayAgain();
                    }

                    Direction nextDirection = inputProvider.GetDirection();

                    board.Sum(nextDirection);

                    if (HasChanged(board))
                    {
                        board.InsertNewNumber();
                        CopyBoard(board);
                    }

                    this.renderer.RenderBoard(board);
                    Console.WriteLine(board.TotalSum());
                }
                catch (Exception e)
                {
                    renderer.PrintMessages(e.Message);
                }
            }
        }