예제 #1
0
        public void TestStopClientsRemovedAndStatusChanged()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, true);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, true);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);

            game.Stop();

            Assert.AreEqual(GameStates.Created, game.State);
            Assert.AreEqual(0, game.ClientCount);
            Assert.IsNull(client1.Game);
            Assert.IsNull(client2.Game);
            Assert.IsNull(client3.Game);
            Assert.AreEqual(ClientStates.Connected, client1.State);
            Assert.AreEqual(ClientStates.Connected, client2.State);
            Assert.AreEqual(ClientStates.Connected, client3.State);
        }
예제 #2
0
        public void TestFinishContinuousSpecialActionCallbacksCalled()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, true);
            game.StartGame(client1);

            game.FinishContinuousSpecial(client1, Specials.Darkness);
            FlushActionQueue();

            Assert.AreEqual(0, callback1.GetCallCount("OnContinuousSpecialFinished"));
            Assert.AreEqual(1, callback2.GetCallCount("OnContinuousSpecialFinished"));
            Assert.AreEqual(1, callback3.GetCallCount("OnContinuousSpecialFinished"));
        }
예제 #3
0
        public void TestVoteKickAnswerVoteTargetCannotVote()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);

            bool succeed = game.VoteKickAnswer(client2, false);

            Assert.IsFalse(succeed);
        }
예제 #4
0
        public void TestVoteKickCallbackCalled()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);
            CountCallTetriNETCallback callback4 = new CountCallTetriNETCallback();
            IClient client4 = CreateClient("client4", callback4);
            game.Join(client4, true);

            bool succeed = game.VoteKick(client1, client2, "reason");

            Assert.IsTrue(succeed);
            Assert.AreEqual(0, callback1.GetCallCount("OnVoteKickAsked")); // vote initiator automatically answers yes
            Assert.AreEqual(0, callback2.GetCallCount("OnVoteKickAsked")); // target is not warned
            Assert.AreEqual(1, callback3.GetCallCount("OnVoteKickAsked")); // other players are asked about vote
            Assert.AreEqual(0, callback4.GetCallCount("OnVoteKickAsked")); // spectators are not asked about vote
        }
예제 #5
0
        public void TestVoteKickPropertiesModified()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);

            bool succeed = game.VoteKick(client1, client2, "reason");

            Assert.IsTrue(succeed);
            Assert.IsNotNull(client1.LastVoteKickAnswer);
            Assert.IsTrue(client1.LastVoteKickAnswer.Value);
        }
예제 #6
0
        public void TestLeaveClientCallbackCalled()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client = CreateClient("client1", callback1);
            game.Join(client, true);

            game.Leave(client);

            Assert.AreEqual(1, callback1.GetCallCount("OnGameLeft"));
        }
예제 #7
0
        public void TestJoinSpectatorOtherClientsInformed()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client1, true);
            game.Join(client2, false);

            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, true);

            Assert.AreEqual(2, callback1.GetCallCount("OnClientGameJoined"));
            Assert.AreEqual(1, callback2.GetCallCount("OnClientGameJoined"));
            Assert.AreEqual(0, callback3.GetCallCount("OnClientGameJoined"));
            Assert.AreEqual(1, callback1.GetCallCount("OnGameMasterModified"));
            Assert.AreEqual(0, callback2.GetCallCount("OnGameMasterModified"));
            Assert.AreEqual(0, callback3.GetCallCount("OnGameMasterModified"));
        }
예제 #8
0
        public void TestClearLinesActionNotEnqueuedIfClassicMultiplayerRulesNotSet()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            game.Options.ClassicStyleMultiplayerRules = false;
            game.StartGame(client1);

            bool succeed = game.ClearLines(client1, 4);

            Assert.IsTrue(succeed);
            Assert.AreEqual(0, ActionQueue.ActionCount);
        }
예제 #9
0
        public void TestChangeOptionsClientsInformed()
        {
            GameOptions originalOptions = new GameOptions();
            originalOptions.Initialize(GameRules.Custom);
            IGame game = CreateGame("game1", 5, 10, GameRules.Custom, originalOptions);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, true);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);

            GameOptions newOptions = new GameOptions();
            newOptions.Initialize(GameRules.Custom);
            game.ChangeOptions(client1, newOptions);

            Assert.AreEqual(1, callback1.GetCallCount("OnGameOptionsChanged"));
            Assert.AreEqual(1, callback2.GetCallCount("OnGameOptionsChanged"));
            Assert.AreEqual(1, callback3.GetCallCount("OnGameOptionsChanged"));
        }
예제 #10
0
        public void TestResumeGameStatusUpdatedAndCallbacksCalled()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, true);
            game.StartGame(client1);
            game.PauseGame(client1);

            bool succeed = game.ResumeGame(client1);

            Assert.IsTrue(succeed);
            Assert.AreEqual(GameStates.GameStarted, game.State);
            Assert.AreEqual(1, callback1.GetCallCount("OnGameResumed"));
            Assert.AreEqual(1, callback2.GetCallCount("OnGameResumed"));
            Assert.AreEqual(1, callback3.GetCallCount("OnGameResumed"));
        }
예제 #11
0
        public void TestResumeGameFailedIfGameNotPaused()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, true);

            bool succeed = game.ResumeGame(client1);

            Assert.IsFalse(succeed);
            Assert.AreEqual(GameStates.WaitStartGame, game.State);
            Assert.AreEqual(0, callback1.GetCallCount("OnGamePaused"));
            Assert.AreEqual(0, callback1.GetCallCount("OnGamePaused"));
            Assert.AreEqual(0, callback1.GetCallCount("OnGamePaused"));
        }
예제 #12
0
        public void TestStopGameStatusUpdatedAndCallbackCalledIfGameStarted()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, true);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);
            game.StartGame(client1);

            bool succeed = game.StopGame(client1);

            Assert.IsTrue(succeed);
            Assert.AreEqual(GameStates.WaitStartGame, game.State);
            Assert.AreEqual(1, callback1.GetCallCount("OnGameFinished"));
            Assert.AreEqual(1, callback2.GetCallCount("OnGameFinished"));
            Assert.AreEqual(1, callback3.GetCallCount("OnGameFinished"));
            Assert.AreEqual(ClientStates.WaitInGame, client1.State);
            Assert.AreEqual(ClientStates.WaitInGame, client2.State);
            Assert.AreEqual(ClientStates.WaitInGame, client3.State);
        }
예제 #13
0
        public void TestStartGameFailedIfNotWaitingGameStart()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, true);
            game.Stop();

            bool succeed = game.StartGame(client1);

            Assert.IsFalse(succeed);
            Assert.AreEqual(GameStates.Created, game.State);
        }
예제 #14
0
        public void TestEarnAchievementCallbacksCalled()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, true);
            game.StartGame(client1);

            game.EarnAchievement(client1, 5, "achievement");
            FlushActionQueue();

            Assert.AreEqual(0, callback1.GetCallCount("OnAchievementEarned"));
            Assert.AreEqual(1, callback2.GetCallCount("OnAchievementEarned"));
            Assert.AreEqual(1, callback3.GetCallCount("OnAchievementEarned"));
        }
예제 #15
0
        public void TestEarnAchievement()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, true);
            game.StartGame(client1);

            bool succeed = game.EarnAchievement(client1, 5, "achievement");

            Assert.IsTrue(succeed);
        }
예제 #16
0
        public void TestGameLostWithTwoPlayingPlayers()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, true);
            game.StartGame(client1);
            callback1.Reset();
            callback2.Reset();
            callback3.Reset();

            game.GameLost(client2);
            FlushActionQueue();

            Assert.AreEqual(GameStates.WaitStartGame, game.State);
            Assert.AreEqual(ClientStates.WaitInGame, client1.State);
            Assert.AreEqual(ClientStates.GameLost, client2.State);
            Assert.AreEqual(ClientStates.WaitInGame, client3.State);
            Assert.AreEqual(1, callback1.GetCallCount("OnPlayerLost"));
            Assert.AreEqual(0, callback2.GetCallCount("OnPlayerLost"));
            Assert.AreEqual(1, callback3.GetCallCount("OnPlayerLost"));
            Assert.AreEqual(1, callback1.GetCallCount("OnGameFinished"));
            Assert.AreEqual(1, callback2.GetCallCount("OnGameFinished"));
            Assert.AreEqual(1, callback3.GetCallCount("OnGameFinished"));
            Assert.AreEqual(1, callback1.GetCallCount("OnWinListModified"));
            Assert.AreEqual(1, callback2.GetCallCount("OnWinListModified"));
            Assert.AreEqual(1, callback3.GetCallCount("OnWinListModified"));
            Assert.AreEqual(1, callback1.GetCallCount("OnPlayerWon"));
            Assert.AreEqual(1, callback2.GetCallCount("OnPlayerWon"));
            Assert.AreEqual(1, callback3.GetCallCount("OnPlayerWon"));
            //Assert.AreEqual(client1.Id, callback1.GetCallParameters("OnPlayerWon", 0)[0]);
        }
예제 #17
0
        public void TestGameLostWithMultiplePlayingPlayer()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);
            game.StartGame(client1);
            callback1.Reset();
            callback2.Reset();
            callback3.Reset();

            game.GameLost(client2);
            FlushActionQueue();

            Assert.AreEqual(GameStates.GameStarted, game.State);
            Assert.AreEqual(ClientStates.Playing, client1.State);
            Assert.AreEqual(ClientStates.GameLost, client2.State);
            Assert.AreEqual(ClientStates.Playing, client3.State);
            Assert.AreEqual(1, callback1.GetCallCount("OnPlayerLost"));
            Assert.AreEqual(0, callback2.GetCallCount("OnPlayerLost"));
            Assert.AreEqual(1, callback3.GetCallCount("OnPlayerLost"));
        }
예제 #18
0
        public void TestJoinSameClient()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, true);

            bool succeed = game.Join(client1, false);

            Assert.IsFalse(succeed);
        }
예제 #19
0
        public void TestJoinSpectatorCallbackCalled()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback = new CountCallTetriNETCallback();
            IClient client = CreateClient("client1", callback);

            game.Join(client, true);

            Assert.AreEqual(1, callback.GetCallCount("OnGameJoined"));
        }
예제 #20
0
        public void TestResetWinListFailedIfNotInGame()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);

            bool succeed = game.ResetWinList(client1);

            Assert.IsFalse(succeed);
        }
예제 #21
0
        public void TestLeavePlayerChangeGameMaster()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client1, false);
            game.Join(client2, false);
            game.Join(client3, true);

            bool succeed = game.Leave(client1);

            Assert.IsTrue(succeed);
            Assert.AreEqual(2, game.ClientCount);
            Assert.AreEqual(1, game.PlayerCount);
            Assert.AreEqual(1, game.SpectatorCount);
            Assert.AreEqual(client2, game.Clients.First());
            Assert.IsFalse(client1.IsGameMaster);
            Assert.IsTrue(client2.IsGameMaster);
            Assert.AreEqual(0, callback1.GetCallCount("OnGameMasterModified"));
            Assert.AreEqual(1, callback2.GetCallCount("OnGameMasterModified"));
            Assert.AreEqual(1, callback3.GetCallCount("OnGameMasterModified"));
        }
예제 #22
0
        public void TestResetWinListClientsInformed()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);

            game.ResetWinList(client1);

            Assert.AreEqual(1, callback1.GetCallCount("OnWinListModified"));
            Assert.AreEqual(1, callback2.GetCallCount("OnWinListModified"));
            Assert.AreEqual(1, callback3.GetCallCount("OnWinListModified"));
        }
예제 #23
0
        public void TestLeaveClientOtherClientsInformed()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, true);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, true);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);

            game.Leave(client1);

            Assert.AreEqual(1, callback2.GetCallCount("OnClientGameLeft"));
            Assert.AreEqual(1, callback3.GetCallCount("OnClientGameLeft"));
        }
예제 #24
0
        public void TestResetWinListFailedIfNotWaitingGameStart()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);
            game.StartGame(client1);

            bool succeed = game.ResetWinList(client1);

            Assert.AreEqual(0, callback1.GetCallCount("OnWinListModified"));
            Assert.IsFalse(succeed);
        }
예제 #25
0
        public void TestJoinSpectatorWhileGameStarted()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource()); 
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, true);
            game.StartGame(client1);
            callback1.Reset();
            callback2.Reset();
            callback3.Reset();

            CountCallTetriNETCallback callback4 = new CountCallTetriNETCallback();
            IClient client4 = CreateClient("client4", callback4);
            game.Join(client4, true);

            Assert.AreEqual(ClientStates.WaitInGame, client4.State);
            Assert.AreEqual(ClientRoles.Spectator, client4.Roles);
            Assert.AreEqual(1, callback1.GetCallCount("OnClientGameJoined"));
            Assert.AreEqual(1, callback2.GetCallCount("OnClientGameJoined"));
            Assert.AreEqual(1, callback3.GetCallCount("OnClientGameJoined"));
            Assert.AreEqual(1, callback4.GetCallCount("OnGameJoined"));
        }
예제 #26
0
        public void TestLeavePlayingPlayerWhileGameStartedMultiplePlayingPlayerLeft()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource()); 
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);
            game.StartGame(client1);
            callback1.Reset();
            callback2.Reset();
            callback3.Reset();

            game.Leave(client2);

            Assert.AreEqual(GameStates.GameStarted, game.State);
            Assert.AreEqual(ClientStates.Playing, client1.State);
            Assert.AreEqual(ClientStates.Playing, client3.State);
            Assert.AreEqual(0, callback1.GetCallCount("OnGameFinished"));
            Assert.AreEqual(0, callback2.GetCallCount("OnGameFinished"));
            Assert.AreEqual(0, callback3.GetCallCount("OnGameFinished"));
            Assert.AreEqual(0, callback1.GetCallCount("OnWinListModified"));
            Assert.AreEqual(0, callback2.GetCallCount("OnWinListModified"));
            Assert.AreEqual(0, callback3.GetCallCount("OnWinListModified"));
        }
예제 #27
0
        public void TestVoteKickTimeout()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);

            game.VoteKick(client1, client2, "reason");
            Thread.Sleep(10500);

            Assert.IsNull(client1.LastVoteKickAnswer);
            Assert.IsNull(client2.LastVoteKickAnswer);
            Assert.IsNull(client3.LastVoteKickAnswer);
            Assert.AreEqual(0, callback1.GetCallCount("OnClientGameLeft"));
            Assert.AreEqual(0, callback2.GetCallCount("OnGameLeft"));
            Assert.AreEqual(0, callback3.GetCallCount("OnClientGameLeft"));
        }
예제 #28
0
        public void TestGameLostWithOnePlayingPlayer()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            game.StartGame(client1);
            callback1.Reset();

            game.GameLost(client1);
            FlushActionQueue();

            Assert.AreEqual(GameStates.WaitStartGame, game.State);
            Assert.AreEqual(ClientStates.GameLost, client1.State);
            Assert.AreEqual(0, callback1.GetCallCount("OnPlayerLost"));
            Assert.AreEqual(1, callback1.GetCallCount("OnGameFinished"));
            Assert.AreEqual(0, callback1.GetCallCount("OnWinListModified"));
        }
예제 #29
0
        public void TestVoteKickAnswerNoMultipleAnswerForSamePlayer()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            CountCallTetriNETCallback callback2 = new CountCallTetriNETCallback();
            IClient client2 = CreateClient("client2", callback2);
            game.Join(client2, false);
            CountCallTetriNETCallback callback3 = new CountCallTetriNETCallback();
            IClient client3 = CreateClient("client3", callback3);
            game.Join(client3, false);
            CountCallTetriNETCallback callback4 = new CountCallTetriNETCallback();
            IClient client4 = CreateClient("client4", callback4);
            game.Join(client4, false);
            game.VoteKick(client1, client2, "reason");
            game.VoteKickAnswer(client3, false);

            bool succeed = game.VoteKickAnswer(client3, false);

            Assert.IsFalse(succeed);
        }
예제 #30
0
        public void TestFinishContinuousSpecialOkIfGameStarted()
        {
            IGame game = CreateGame("game1", 5, 10);
            game.Start(new CancellationTokenSource());
            CountCallTetriNETCallback callback1 = new CountCallTetriNETCallback();
            IClient client1 = CreateClient("client1", callback1);
            game.Join(client1, false);
            game.StartGame(client1);

            bool succeed = game.FinishContinuousSpecial(client1, Specials.Darkness);

            Assert.IsTrue(succeed);
        }