Exemplo n.º 1
0
        public void freezeTest()
        {
            THHGame game = TestGameflow.initGameWithoutPlayers(null, new GameOption()
            {
                shuffle = false
            });
            THHPlayer defaultPlayer = game.createPlayer(0, "玩家0", game.getCardDefine <TestMaster2>(), Enumerable.Repeat(game.getCardDefine <DefaultServant>() as CardDefine, 30));
            THHPlayer elusivePlayer = game.createPlayer(1, "玩家1", game.getCardDefine <TestMaster2>(), Enumerable.Repeat(game.getCardDefine <DefaultServant>() as CardDefine, 28)
                                                        .Concat(Enumerable.Repeat(game.getCardDefine <TestFreeze>(), 2)));

            game.skipTurnUntil(() => defaultPlayer.gem >= game.getCardDefine <DefaultServant>().cost&& game.currentPlayer == defaultPlayer);
            defaultPlayer.cmdUse(game, defaultPlayer.hand.First(c => c.define.id == DefaultServant.ID), 0);
            //玩家0拍白板一张

            game.skipTurnUntil(() => elusivePlayer.gem >= game.getCardDefine <TestFreeze>().cost&& game.currentPlayer == elusivePlayer);
            elusivePlayer.cmdUse(game, elusivePlayer.hand.First(c => c.define.id == TestFreeze.ID), 0, defaultPlayer.field);
            //玩家1释放冰环

            game.skipTurnUntil(() => defaultPlayer.gem >= game.getCardDefine <DefaultServant>().cost&& game.currentPlayer == defaultPlayer);
            defaultPlayer.cmdAttack(game, defaultPlayer.field[0], elusivePlayer.master); //被冻结的随从无法攻击
            defaultPlayer.cmdTurnEnd(game);                                              //回合结束,随从解冻

            elusivePlayer.cmdTurnEnd(game);

            game.skipTurnUntil(() => defaultPlayer.gem >= game.getCardDefine <DefaultServant>().cost&& game.currentPlayer == defaultPlayer);
            defaultPlayer.cmdAttack(game, defaultPlayer.field[0], elusivePlayer.master);//已解除冰冻的随从可以攻击
            Assert.AreEqual(29, elusivePlayer.master.getCurrentLife(game));

            game.Dispose();
        }
Exemplo n.º 2
0
        public void ElusiveTest()
        {
            THHGame game = TestGameflow.initGameWithoutPlayers(null, new GameOption()
            {
                shuffle = false
            });
            THHPlayer defaultPlayer = game.createPlayer(0, "玩家0", game.getCardDefine <TestMaster2>(), Enumerable.Repeat(game.getCardDefine <DefaultServant>() as CardDefine, 28)
                                                        .Concat(Enumerable.Repeat(game.getCardDefine <TestSpellCard>(), 2)));
            THHPlayer elusivePlayer = game.createPlayer(1, "玩家1", game.getCardDefine <TestMaster2>(), Enumerable.Repeat(game.getCardDefine <DefaultServant>() as CardDefine, 29)
                                                        .Concat(Enumerable.Repeat(game.getCardDefine <ElusiveServant>(), 1)));

            game.skipTurnUntil(() => defaultPlayer.gem >= game.getCardDefine <DefaultServant>().cost&& game.currentPlayer == defaultPlayer);
            defaultPlayer.cmdUse(game, defaultPlayer.hand.First(c => c.define.id == DefaultServant.ID), 0);

            game.skipTurnUntil(() => elusivePlayer.gem >= game.getCardDefine <ElusiveServant>().cost&& game.currentPlayer == elusivePlayer);
            elusivePlayer.cmdUse(game, elusivePlayer.hand.First(c => c.define.id == ElusiveServant.ID), 0);

            game.skipTurnUntil(() => defaultPlayer.gem >= game.getCardDefine <TestSpellCard>().cost&& game.currentPlayer == defaultPlayer);
            defaultPlayer.cmdUse(game, defaultPlayer.hand.First(c => c.define.id == TestSpellCard.ID), 0, defaultPlayer.field[0]);
            Assert.AreEqual(6, defaultPlayer.field[0].getCurrentLife(game)); //没有魔免的可以被法术指定
            defaultPlayer.cmdUse(game, defaultPlayer.hand.First(c => c.define.id == TestSpellCard.ID), 0, elusivePlayer.field[0]);
            Assert.AreEqual(3, elusivePlayer.field[0].getCurrentLife(game)); //魔免无法被法术指定

            game.skipTurnUntil(() => elusivePlayer.gem >= game.getCardDefine <TestDamageSkill>().cost&& game.currentPlayer == elusivePlayer);
            elusivePlayer.cmdUse(game, elusivePlayer.skill, 0, defaultPlayer.field[0]);
            Assert.AreEqual(5, defaultPlayer.field[0].getCurrentLife(game));//没有魔免的可以被技能指定
            elusivePlayer.cmdTurnEnd(game);

            game.skipTurnUntil(() => elusivePlayer.gem >= game.getCardDefine <TestDamageSkill>().cost&& game.currentPlayer == elusivePlayer);
            elusivePlayer.cmdUse(game, elusivePlayer.skill, 0, elusivePlayer.field[0]);
            Assert.AreEqual(3, elusivePlayer.field[0].getCurrentLife(game));//魔免无法被技能指定

            game.Dispose();
        }
Exemplo n.º 3
0
        public void setGame(THHGame game, THHPlayer player)
        {
            InitReplaceDialog.hide();
            TurnTipImage.hide();
            SelfHandList.clearItems();
            SelfFieldList.clearItems();
            EnemyFieldList.clearItems();
            EnemyHandList.clearItems();
            AttackArrowImage.hide();
            Fatigue.hide();
            _animationQueue.Clear();

            if (game != null)
            {
                game.triggers.onEventBefore -= onEventBefore;
                game.triggers.onEventAfter  -= onEventAfter;
            }
            this.game = game;
            if (game != null)
            {
                game.triggers.onEventBefore += onEventBefore;
                game.triggers.onEventAfter  += onEventAfter;
            }
            if (player != null)
            {
                SelfSkill.asButton.onClick.RemoveAllListeners();
                TurnEndButton.onClick.RemoveAllListeners();
            }
            this.player = player;
            if (player != null)
            {
                SelfSkill.asButton.onClick.AddListener(() =>
                {
                    if (selectableTargets != null)
                    {
                        return;
                    }
                    player.cmdUse(game, SelfSkill.card, 0);
                });
                TurnEndButton.onClick.AddListener(() =>
                {
                    player.cmdTurnEnd(game);

                    //SelfHandList.stopPlacing(true);
                    resetUse(true, true);
                    selectableTargets = null;
                });
            }
        }
        public void PatchouliTrilithonShakeTest()
        {
            THHGame game = TestGameflow.initGameWithoutPlayers(null, new GameOption()
            {
                shuffle = false
            });
            THHPlayer defaultPlayer = game.createPlayer(0, "玩家0", game.getCardDefine <TestMaster2>(), Enumerable.Repeat(game.getCardDefine <DefaultServant>() as CardDefine, 30));
            THHPlayer elusivePlayer = game.createPlayer(1, "玩家1", game.getCardDefine <TestMaster2>(), Enumerable.Repeat(game.getCardDefine <DefaultServant>() as CardDefine, 28)
                                                        .Concat(Enumerable.Repeat(game.getCardDefine <RockElement>(), 2)));

            defaultPlayer.cmdTurnEnd(game);

            game.skipTurnUntil(() => elusivePlayer.gem >= game.getCardDefine <RockElement>().cost&& game.currentPlayer == elusivePlayer);
            elusivePlayer.cmdUse(game, elusivePlayer.hand.First(c => c.define.id == RockElement.ID), 0);

            game.skipTurnUntil(() => defaultPlayer.gem >= game.getCardDefine <DefaultServant>().cost&& game.currentPlayer == defaultPlayer);
            defaultPlayer.cmdUse(game, defaultPlayer.hand.First(c => c.define.id == DefaultServant.ID), 0);

            game.skipTurnUntil(() => elusivePlayer.gem >= game.getCardDefine <TrilithonShake>().cost&& game.currentPlayer == elusivePlayer);
            elusivePlayer.cmdAttack(game, elusivePlayer.field[0], defaultPlayer.field[0]);
            game.Dispose();
        }
Exemplo n.º 5
0
        public IEnumerator remotePVPSimulTest()
        {
            UnityLogger logger = new UnityLogger();
            HostManager host   = new GameObject(nameof(HostManager)).AddComponent <HostManager>();

            host.logger = logger;
            ClientManager local = new GameObject(nameof(ClientManager)).AddComponent <ClientManager>();

            local.logger = logger;
            //开房,打开Host,自己加入自己,房间应该有Option
            RoomInfo roomInfo = new RoomInfo();

            roomInfo.setOption(new GameOption());
            THHGame localGame = null;

            local.onConnected += () =>
            {
                //发送玩家信息
                RoomPlayerInfo playerInfo = new RoomPlayerInfo()
                {
                    id   = local.id,
                    name = "玩家" + local.id,
                };
                playerInfo.setDeck(new int[] { Reimu.ID }.Concat(Enumerable.Repeat(DrizzleFairy.ID, 30)).ToArray());
                return(local.send(playerInfo));
            };
            local.onReceive += (id, obj) =>
            {
                if (obj is RoomPlayerInfo newPlayerInfo)
                {
                    //收到玩家信息
                    RoomInfo newRoomInfo = new RoomInfo()
                    {
                        playerList = new List <RoomPlayerInfo>(roomInfo.playerList)
                    };
                    newRoomInfo.setOption(roomInfo.getOption());
                    newRoomInfo.playerList.Add(newPlayerInfo);
                    //发送房间信息
                    return(local.send(newRoomInfo));
                }
                else if (obj is RoomInfo newRoomInfo)
                {
                    roomInfo = newRoomInfo;
                    //收到房间信息
                    if (newRoomInfo.playerList.Count > 1)
                    {
                        localGame = TestGameflow.initGameWithoutPlayers("本地游戏", newRoomInfo.getOption());
                        (localGame.answers as AnswerManager).client = local;
                        foreach (var playerInfo in newRoomInfo.playerList)
                        {
                            localGame.createPlayer(playerInfo.id, "玩家" + playerInfo.id, localGame.getCardDefine <MasterCardDefine>(playerInfo.getDeck()[0]), playerInfo.getDeck().Skip(1).Select(did => localGame.getCardDefine(did)));
                        }
                        localGame.run();
                    }
                }
                return(Task.CompletedTask);
            };
            host.start();
            local.start();
            yield return(local.join(host.ip, host.port).wait());

            Assert.AreEqual(1, roomInfo.playerList.Count);

            ClientManager remote = new GameObject(nameof(ClientManager)).AddComponent <ClientManager>();

            remote.logger = logger;
            THHGame remoteGame = null;

            remote.onConnected += () =>
            {
                //发送玩家信息
                RoomPlayerInfo playerInfo = new RoomPlayerInfo()
                {
                    id   = remote.id,
                    name = "玩家" + remote.id
                };
                playerInfo.setDeck(new int[] { Reimu.ID }.Concat(Enumerable.Repeat(DrizzleFairy.ID, 30)).ToArray());
                return(remote.send(playerInfo));
            };
            remote.onReceive += (id, obj) =>
            {
                if (obj is RoomInfo newRoomInfo)
                {
                    //收到房间信息
                    if (newRoomInfo.playerList.Count > 1)
                    {
                        remoteGame = TestGameflow.initGameWithoutPlayers("远端游戏", newRoomInfo.getOption());
                        (remoteGame.answers as AnswerManager).client = remote;
                        foreach (var playerInfo in newRoomInfo.playerList)
                        {
                            remoteGame.createPlayer(playerInfo.id, "玩家" + playerInfo.id, remoteGame.getCardDefine <MasterCardDefine>(playerInfo.getDeck()[0]), playerInfo.getDeck().Skip(1).Select(did => remoteGame.getCardDefine(did)));
                        }
                        remoteGame.run();
                    }
                }
                return(Task.CompletedTask);
            };
            //加入房间
            remote.start();
            yield return(remote.join(host.ip, host.port).wait());

            //连接了,远程玩家把玩家信息发给本地,本地更新房间信息发给远端和开始游戏。
            yield return(new WaitUntil(() => localGame != null && remoteGame != null));

            Assert.True(localGame.isRunning);
            Assert.AreEqual(local.id, localGame.players[0].id);
            Assert.AreEqual(remote.id, localGame.players[1].id);
            Assert.True(remoteGame.isRunning);
            Assert.AreEqual(local.id, remoteGame.players[0].id);
            Assert.AreEqual(remote.id, remoteGame.players[1].id);

            THHPlayer localPlayer = localGame.getPlayer(local.id);

            Assert.AreEqual(0, localPlayer.id);
            yield return(new WaitUntil(() => localGame.answers.getRequests(localPlayer.id).FirstOrDefault() is InitReplaceRequest));

            Assert.Greater(localPlayer.init.count, 0);
            localPlayer.cmdInitReplace(localGame);
            yield return(new WaitUntil(() => localGame.answers.getResponse(localPlayer.id, localGame.answers.getRequests(localPlayer.id).FirstOrDefault()) is InitReplaceResponse));

            THHPlayer remotePlayer = remoteGame.getPlayer(remote.id);

            Assert.AreEqual(1, remotePlayer.id);
            yield return(new WaitUntil(() => remoteGame.answers.getRequests(remotePlayer.id).FirstOrDefault() is InitReplaceRequest));

            Assert.Greater(remotePlayer.init.count, 0);
            remotePlayer.cmdInitReplace(remoteGame);
            yield return(new WaitUntil(() => remoteGame.triggers.getRecordedEvents().Any(e => e is THHGame.StartEventArg)));

            //拍怪
            if (localGame.sortedPlayers[0] == localPlayer)
            {
                yield return(new WaitUntil(() => localGame.answers.getRequests(localPlayer.id).FirstOrDefault() is FreeActRequest));

                localPlayer.cmdUse(localGame, localPlayer.hand[0], 0);
                yield return(new WaitUntil(() => localPlayer.field.count > 0));

                localPlayer.cmdTurnEnd(localGame);
                yield return(new WaitUntil(() => localGame.currentPlayer != localPlayer));
            }
            yield return(new WaitUntil(() => remoteGame.answers.getRequests(remotePlayer.id).FirstOrDefault() is FreeActRequest));

            remotePlayer.cmdUse(remoteGame, remotePlayer.hand[0], 0);
            yield return(new WaitUntil(() => remotePlayer.field.count > 0));

            remotePlayer.cmdTurnEnd(remoteGame);
            yield return(new WaitUntil(() => remoteGame.currentPlayer != remotePlayer));

            if (localGame.sortedPlayers[0] != localPlayer)
            {
                yield return(new WaitUntil(() => localGame.answers.getRequests(localPlayer.id).FirstOrDefault() is FreeActRequest));

                localPlayer.cmdUse(localGame, localPlayer.hand[0], 0);
                yield return(new WaitUntil(() => localPlayer.field.count > 0));

                localPlayer.cmdTurnEnd(localGame);
                yield return(new WaitUntil(() => localGame.currentPlayer != localPlayer));
            }
            do
            {
                yield return(new WaitUntil(() => localGame.currentPlayer == localPlayer || remoteGame.currentPlayer == remotePlayer));

                if (localGame.currentPlayer == localPlayer)
                {
                    localPlayer.cmdAttack(localGame, localPlayer.field[0], localGame.getOpponent(localPlayer).master);
                    yield return(new WaitUntil(() => localPlayer.field[0].getAttackTimes(localGame) > 0));

                    localPlayer.cmdTurnEnd(localGame);
                    yield return(new WaitUntil(() => localGame.currentPlayer != localPlayer));
                }
                else if (remoteGame.currentPlayer == remotePlayer)
                {
                    remotePlayer.cmdAttack(remoteGame, remotePlayer.field[0], remoteGame.getOpponent(remotePlayer).master);
                    yield return(new WaitUntil(() => remotePlayer.field[0].getAttackTimes(remoteGame) > 0));

                    remotePlayer.cmdTurnEnd(remoteGame);
                    yield return(new WaitUntil(() => remoteGame.currentPlayer != remotePlayer));
                }
            }while (localGame.isRunning && remoteGame.isRunning);

            local.disconnect();
            remote.disconnect();
            yield break;
        }