示例#1
0
 private void button9_Click(object sender, EventArgs e)
 {
     Scrabble.Game_Objects.GameState state = new Game_Objects.GameState();
     PlayerClass.Player player = new PlayerClass.Player(0001, "username");
     state.AddPlayer(player);
     logger.AddToGameState(state.ToString());
 }
        public void GameStateTest()
        {
            // should be able to create empty game state
            GameState emptyGameState = new GameState();

            var user1 = new Scrabble.PlayerClass.Player(1, "user1");
            emptyGameState.AddPlayer(user1);

            this.AssertPlayerEqual(emptyGameState.PlayerList[0], user1);

            // set up
            Board board = new Board();
            List<Scrabble.PlayerClass.Player> playerList = new List<Scrabble.PlayerClass.Player>();
            Bag tileBag = new Bag();

            var letterTileA = new LetterTile('A', 1);
            var letterTileN = new LetterTile('N', 1);
            var letterTileT = new LetterTile('T', 1);
            var letterTileS = new LetterTile('S', 1);
            List<LetterTile> word = new List<LetterTile> { letterTileA, letterTileN, letterTileT, letterTileS };
            var coordsX = new List<int>() { 6, 7, 8, 9 };
            var coordsY = new List<int>() { 7, 7, 7, 7 };
            Play recentPlay = new Play(word, coordsX, coordsY, 42);

            try
            {
                board.AddPlayToBoard(recentPlay);
            }
            catch (Exception err)
            {
                Assert.Fail();
            }

            for (int i = 1; i <= 3; ++i)
            {
                playerList.Add(new Scrabble.PlayerClass.Player(i, "user" + i));
                playerList[i - 1].AddToScore(i * 10);
            }

            playerList[2].IncrementSkipCount();
            playerList[1].ToggleVote();

            TurnOrder playerOrder = new TurnOrder(playerList);

            GameState gameState = new GameState(board, playerList, tileBag, playerOrder, recentPlay);

            playerList.Add(new Scrabble.PlayerClass.Player(4, "user" + 4));
            playerList[3].AddToScore(4 * 10);

            gameState.AddPlayer(playerList[3]);

            var player5 = new Scrabble.PlayerClass.Player(5, "user" + 5);
            player5.AddToScore(5 * 10);

            gameState.AddPlayer(player5);

            Assert.IsTrue(gameState.PlayerList.Count == 4);

            for (int i = 0; i < playerList.Count; ++i)
            {
                this.AssertPlayerEqual(gameState.PlayerList[i], playerList[i]);
            }

            Assert.IsTrue(board.Equals(gameState.GameBoard));
            Assert.IsTrue(tileBag.Equals(gameState.TileBag));
            Assert.IsTrue(playerOrder.Equals(gameState.PlayerOrder));
            Assert.IsTrue(recentPlay.Equals(gameState.RecentPlay));
        }