Ejemplo n.º 1
0
        public void AttackHitTest()
        {
            Player p1   = mocks.Stub <Player>(0);
            Player p2   = mocks.Stub <Player>(1);
            IGame  game = mocks.Stub <IGame>();

            Card attack = new Attack(CardSuit.Spade, 1);

            // ActionPhase produces attackPhase
            Phase     a   = new ActionPhase(p1);
            PhaseList ret = a.advance(new UseCardAction(attack, p2), game);
            Phase     b   = ret.pop();

            Assert.IsInstanceOfType(b, typeof(AttackPhase));
            AttackPhase b2 = b as AttackPhase;

            Assert.AreEqual(attack, b2.attack);
            Assert.AreEqual(a, b2.actionPhase);
            Assert.AreEqual(p1, b2.player);
            Assert.AreEqual(p2, b2.targets[0]);
            Assert.AreEqual(a, ret.pop());
            Assert.IsTrue(ret.isEmpty());
            // AttackPhase produces responsePhase
            ret = b.advance(null, game);
            Phase c = ret.pop();

            Assert.IsInstanceOfType(c, typeof(ResponsePhase));
            ResponsePhase c_ = c as ResponsePhase;

            Assert.AreEqual(p2, c_.player);
            Phase c2 = ret.pop();

            Assert.IsInstanceOfType(c2, typeof(AttackPhase));
            Assert.AreEqual(b, c2);
            Assert.IsTrue(ret.isEmpty());

            // response with cancel
            ret = c.advance(new YesOrNoAction(false), game);
            Assert.IsTrue(ret.isEmpty());

            // attackPhase produces harmPhase
            ret = c2.advance(null, game);
            Phase d = ret.pop();

            Assert.IsInstanceOfType(d, typeof(HarmPhase));
            HarmPhase d2 = d as HarmPhase;

            Assert.AreEqual(p2, d2.player);
            Assert.AreEqual(p1, d2.source);
            Assert.AreEqual(1, d2.harm);
            Assert.IsTrue(ret.isEmpty());

            ret = d.advance(null, game);
            Assert.IsTrue(ret.isEmpty());
        }
Ejemplo n.º 2
0
        private Phase randomPhase()
        {
            Phase phase;
            int   r = random.Next();

            switch (r % 10)
            {
            case 1:
                phase = new JudgePhase(randomPlayer());
                break;

            case 2:
                phase = new DrawingPhase(randomPlayer());
                break;

            case 3:
                phase = new ActionPhase(randomPlayer());
                break;

            case 4:
                phase = new DiscardPhase(randomPlayer());
                break;

            case 5:
                phase = new HarmPhase(randomPlayer(), randomPlayer(), random.Next(), randomAttack());
                break;

            case 6:
                phase = new AskForHelpPhase(randomPlayer(), new HarmPhase(randomPlayer(), randomPlayer(), random.Next(), randomAttack()));
                break;

            case 7:
                phase = new RecoverPhase(randomPlayer(), random.Next());
                break;

            default:
                phase = new DeadPhase(randomPlayer(), new HarmPhase(randomPlayer(), randomPlayer(), random.Next(), randomAttack()));
                break;
            }

            return(phase);
        }
Ejemplo n.º 3
0
        public void CaoCaoAbtestmock()
        {
            Player    p        = new CaoCao(1);
            Player    p2       = new ZhangFei(2);
            int       harm     = 1;
            Attack    fakeCard = mocks.DynamicMock <Attack>(CardSuit.Club, (byte)1);
            IGame     fakeGame = mocks.DynamicMock <IGame>();
            HarmPhase fakeharm = mocks.DynamicMock <HarmPhase>(p, p2, harm, fakeCard);


            int old = p.handCards.Count;

            using (mocks.Ordered())
            {
                p.handCards.Add(fakeCard);
            }
            mocks.ReplayAll();
            PhaseList ret  = p.harm(new HarmPhase(p, null, harm, fakeCard), fakeGame);
            int       newc = p.handCards.Count;

            Assert.IsTrue(old != newc);
        }
Ejemplo n.º 4
0
        public void DyingAskForHelpRejectTest()
        {
            Player dying   = new Player(0, "dying", "dying", 1);
            Player source  = mocks.Stub <Player>(1);
            Player player2 = mocks.Stub <Player>(2);
            Player player3 = mocks.Stub <Player>(3);

            Player[]  players = new Player[4];
            Phase     p1, p2, p3, p4, p5;
            PhaseList ls;

            players[0] = dying;
            players[1] = source;
            players[2] = player2;
            players[3] = player3;

            Attack card = new Attack(CardSuit.Club, 1);
            Wine   wine = new Wine(CardSuit.Heart, 2);

            Assert.AreEqual(1, dying.healthLimit);
            ICardSet cardStack = MockRepository.GenerateStub <ICardSet>();

            IGame game = MockRepository.GenerateStub <IGame>();

            game.Stub(x => x.players).Return(players);
            game.Stub(x => x.nextPlayer(source, 0)).Return(source);
            game.Stub(x => x.nextPlayer(source, 1)).Return(player2);
            game.Stub(x => x.nextPlayer(source, 2)).Return(player3);
            game.Stub(x => x.nextPlayer(source, 3)).Return(dying);
            game.Stub(x => x.curRoundPlayer).Return(source);
            game.Stub(s => s.cards).Return(cardStack);
            game.Stub(s => s.Num_Player).Return(4);

            HarmPhase harm = new HarmPhase(dying, source, 1, card);

            ls = harm.advance(null, game);
            p1 = ls.pop();
            Assert.IsInstanceOfType(p1, typeof(AskForHelpPhase));
            Assert.IsTrue(ls.isEmpty());

            ls = p1.advance(null, game);
            p2 = ls.pop();
            p3 = ls.pop();
            Assert.IsTrue(ls.isEmpty());
            Assert.IsInstanceOfType(p2, typeof(ResponsePhase));
            Assert.AreEqual(source, p2.player);
            Assert.AreSame(p1, p3);

            ls = p2.advance(new YesOrNoAction(false), game);
            Assert.IsTrue(ls.isEmpty());

            ls = p3.advance(null, game);
            p4 = ls.pop();
            p5 = ls.pop();
            Assert.IsTrue(ls.isEmpty());
            Assert.IsInstanceOfType(p4, typeof(ResponsePhase));
            Assert.AreEqual(player2, p4.player);
            Assert.AreSame(p1, p5);

            ls = p4.advance(new YesOrNoAction(false), game);
            Assert.IsTrue(ls.isEmpty());

            ls = p5.advance(null, game);
            p4 = ls.pop();
            p5 = ls.pop();
            Assert.IsTrue(ls.isEmpty());
            Assert.IsInstanceOfType(p4, typeof(ResponsePhase));
            Assert.AreEqual(player3, p4.player);
            Assert.AreSame(p1, p5);

            ls = p4.advance(new YesOrNoAction(false), game);
            Assert.IsTrue(ls.isEmpty());

            ls = p5.advance(null, game);
            p4 = ls.pop();
            p5 = ls.pop();
            Assert.IsTrue(ls.isEmpty());
            Assert.IsInstanceOfType(p4, typeof(ResponsePhase));
            Assert.AreEqual(dying, p4.player);
            Assert.AreSame(p1, p5);

            ls = p4.advance(new CardAction(wine), game);
            Assert.IsTrue(ls.isEmpty());

            ls = p5.advance(null, game);
            p4 = ls.pop();
            p5 = ls.pop();
            Assert.IsTrue(ls.isEmpty());
            Assert.IsInstanceOfType(p4, typeof(RecoverPhase));
            Assert.AreEqual(dying, p4.player);
            Assert.AreSame(p1, p5);

            Assert.AreEqual(0, dying.health);
            ls = p4.advance(null, game);
            Assert.IsTrue(ls.isEmpty());
            Assert.AreEqual(1, dying.health);

            ls = p5.advance(null, game);
            Assert.IsTrue(ls.isEmpty());
            // ActionPhase produces attackPhase
        }