コード例 #1
0
        public void AddEmptyNameToScoreBoard()
        {
            ScoreBoard scoreBoard = new ScoreBoard();
            scoreBoard.Add(string.Empty, 23);

            string str = scoreBoard.Scores().Values.ToString();
            str += scoreBoard.Scores().Keys.ToString();
            Assert.AreEqual(str, "{Anonymous}{23}");
        }
コード例 #2
0
        public void AddToScoreBoard()
        {
            ScoreBoard scoreBoard = new ScoreBoard();

            scoreBoard.Add("Pesho", 23);
            scoreBoard.Add("Gosho", 13);
            scoreBoard.Add("Tosho", 17);
            string str = scoreBoard.Scores().Values.ToString();
            str += scoreBoard.Scores().Keys.ToString();

            Assert.AreEqual(str, "{Gosho,Tosho,Pesho}{13,17,23}");
        }
コード例 #3
0
        public void AddMoreThanFiveOnScoreBoardTest()
        {
            ScoreBoard scoreBoard = new ScoreBoard();

            scoreBoard.Add("Pesho", 23);
            scoreBoard.Add("Gosho", 13);
            scoreBoard.Add("Ivan", 18);
            scoreBoard.Add("Kiro", 17);
            scoreBoard.Add("Stamat", 14);
            scoreBoard.Add("Mimi", 12);
            scoreBoard.Add("Tosho", 10);

            string str = scoreBoard.Scores().Values.ToString();
            str += scoreBoard.Scores().Keys.ToString();
            Assert.AreEqual(str, "{Tosho,Mimi,Gosho,Stamat,Kiro,Ivan,Pesho}{10,12,13,14,17,18,23}");
        }
コード例 #4
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();
            }
        }
コード例 #5
0
ファイル: GameEngine.cs プロジェクト: rosteslav/game-fifteen
        /// <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();
            }
        }
コード例 #6
0
 public void InitializeEmptyScoreBoardTest()
 {
     ScoreBoard scoreBoard = new ScoreBoard();
     string str = scoreBoard.Scores().Values.ToString();
     str += scoreBoard.Scores().Keys.ToString();
     Assert.IsTrue(str == "{}{}");
 }