示例#1
0
 /// <summary>
 /// Adds user to scoreboard, asking his name and getting his score.
 /// </summary>
 /// <param name="score">Number of moves.</param>
 private void AddUserToScoreBoard(ScoreBoard scoreBoard, int score, IRenderable render)
 {
     string name = render.Read("Please enter your name for the top scoreboard: ");
     scoreBoard.Add(name, score);
 }
示例#2
0
        /// <summary>
        /// Method that is responsible for communication between the user and the engine.
        /// Handles user input and outputs game response.
        /// </summary>
        private void BeginGame(IRenderable render)
        {
            ScoreBoard scoreBoard = new ScoreBoard();
            render.PrintField(this.gameField.GetFieldNumbers());
            bool gameIsFinished = false;
            int moves = 0;

            string inputCommand = render.Read("give me command: ").Trim();

            while (inputCommand != "exit")
            {
                switch (inputCommand)
                {
                    case "top":
                        render.PrintScoreboard(scoreBoard.Scores());
                        break;
                    case "restart":
                        this.StartNewGame(render, true);
                        break;
                    default:
                        moves = MoveNumberIfValid(render, moves, inputCommand);
                        break;
                }

                render.PrintField(this.gameField.GetFieldNumbers());
                gameIsFinished = this.gameField.IsSolved();

                if (gameIsFinished)
                {
                    string message = string.Format("Congratulations! You won the game in {0} moves.", moves);
                    render.Write(message);

                    this.AddUserToScoreBoard(scoreBoard, moves, render);
                    moves = 0;
                    this.StartNewGame(render);
                }

                inputCommand = render.Read("give me command: ").Trim();
            }
        }
示例#3
0
        /// <summary>
        /// Adds user to scoreboard, asking his name and getting his score.
        /// </summary>
        /// <param name="score">Number of moves.</param>
        private void AddUserToScoreBoard(ScoreBoard scoreBoard, int score, IRenderable render)
        {
            string name = render.Read("Please enter your name for the top scoreboard: ");

            scoreBoard.Add(name, score);
        }