예제 #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());
        }
예제 #2
0
        public void GameConstruct()
        {
            Type      gameType    = typeof(Game);
            FieldInfo stagesField = gameType.GetField("stages", BindingFlags.NonPublic | BindingFlags.Instance);
            PhaseList ls          = stagesField.GetValue(game) as PhaseList;

            Assert.IsTrue(ls.isEmpty());
        }
        public void TestPushOneStageList()
        {
            PhaseList ls = new PhaseList();

            ls.add(new PhaseSimple(0));
            Assert.AreEqual(ls.pop().playerID, 0);
            Assert.IsTrue(ls.isEmpty());
        }
예제 #4
0
        public void AttackMissTest()
        {
            Player p1 = mocks.Stub <Player>(0);
            Player p2 = mocks.Stub <Player>(1);

            IGame game = mocks.Stub <IGame>();

            Card attack = new Attack(CardSuit.Spade, 1);
            Miss miss   = new Miss(CardSuit.Diamond, 2);
            // 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 CardAction(miss), game);
            Assert.IsTrue(ret.isEmpty());

            // attackPhase produces nothing
            ret = c2.advance(null, game);
            Assert.IsTrue(ret.isEmpty());
        }
예제 #5
0
        public void HarmTest()
        {
            Attack    card   = new Attack(CardSuit.Club, 1);
            IGame     game   = mocks.Stub <IGame>();
            int       health = 5;
            int       harm   = 2;
            Player    p      = new Player(0, "Name", "Descript", health);
            PhaseList ret    = p.harm(new HarmPhase(p, null, harm, card), game);

            Assert.IsTrue(ret.isEmpty());

            Assert.AreEqual(health - harm, p.health);
        }
예제 #6
0
        public void HarmDyingTest()
        {
            Attack    card   = new Attack(CardSuit.Club, 1);
            IGame     game   = mocks.Stub <IGame>();
            int       health = 5;
            int       harm   = 10;
            Player    p      = new Player(0, "Name", "Descript", health);
            PhaseList ret    = p.harm(new HarmPhase(p, null, harm, card), game);

            Phase x = ret.pop();

            Assert.IsInstanceOfType(x, typeof(AskForHelpPhase));
            Assert.IsTrue(ret.isEmpty());

            Assert.AreEqual(health - harm, p.health);
        }
        public void TestAddPop()
        {
            PhaseList ls = new PhaseList();

            ls.add(new PhaseSimple(0));
            ls.add(new PhaseSimple(1));
            ls.add(new PhaseSimple(2));
            ls.add(new PhaseSimple(3));
            ls.add(new PhaseSimple(4));
            Assert.AreEqual(ls.pop().playerID, 0);
            Assert.AreEqual(ls.pop().playerID, 1);
            Assert.AreEqual(ls.pop().playerID, 2);
            Assert.AreEqual(ls.pop().playerID, 3);
            Assert.AreEqual(ls.pop().playerID, 4);
            Assert.IsTrue(ls.isEmpty());
        }
예제 #8
0
        public void nextStageUtillEmptyTest()
        {
            Type      gameType    = typeof(Game);
            FieldInfo stagesField = gameType.GetField("stages", BindingFlags.NonPublic | BindingFlags.Instance);

            Player     player = mocks.Stub <Player>(0);
            Phase      p1     = mocks.DynamicMock <Phase>(player);
            Phase      p2     = mocks.DynamicMock <Phase>(player);
            Phase      p3     = mocks.DynamicMock <Phase>(player);
            Phase      p4     = mocks.DynamicMock <Phase>(player);
            UserAction x      = mocks.Stub <UserAction>();

            stagesField.SetValue(game, new PhaseList(p1));

            using (mocks.Ordered())
            {
                Expect.Call(p1.advance(null, game)).Return(new PhaseList(p2, p1));
                Expect.Call(p2.advance(null, game)).Return(new PhaseList(p3, p4));
                Expect.Call(p3.advance(null, game)).Return(new PhaseList());
                Expect.Call(p4.advance(null, game)).Return(new PhaseList());
                Expect.Call(p1.advance(x, game)).Return(new PhaseList());
            }

            mocks.ReplayAll();

            game.nextStage(null);
            game.nextStage(null);
            game.nextStage(null);
            game.nextStage(null);
            try
            {
                game.nextStage(x);
                Assert.Fail("No exception thrown");
            }
            catch (EmptyException e)
            {
            }
            PhaseList left = (PhaseList)stagesField.GetValue(game);

            Assert.IsTrue(left.isEmpty());

            mocks.VerifyAll();
        }
        public void TestPushStageListTillEmpty()
        {
            PhaseList ls = new PhaseList();

            ls.add(new PhaseSimple(0));
            ls.add(new PhaseSimple(1));
            ls.add(new PhaseSimple(2));
            PhaseList ls2 = new PhaseList();

            ls2.add(new PhaseSimple(3));
            ls2.add(new PhaseSimple(4));
            ls.pushList(ls2);
            Assert.AreEqual(ls.pop().playerID, 3);
            Assert.AreEqual(ls.pop().playerID, 4);
            Assert.AreEqual(ls.pop().playerID, 0);
            Assert.AreEqual(ls.pop().playerID, 1);
            Assert.AreEqual(ls.pop().playerID, 2);
            Assert.IsTrue(ls.isEmpty());
        }
예제 #10
0
        public void resAdvanceTest3()
        {
            ZhangFei p1     = new ZhangFei(0);
            Card     attack = new Attack(CardSuit.Spade, 1);
            Miss     miss   = new Miss(CardSuit.Diamond, 2);

            p1.handCards.Add(attack);
            p1.handCards.Add(miss);
            p1.health = 1;

            IGame game = mocks.Stub <IGame>();


            // ActionPhase produces attackPhase
            UserActionPhase a  = new ActionPhase(p1);
            PhaseList       ls = a.timeOutAdvance(game);

            Assert.IsInstanceOfType(ls.pop(), typeof(DiscardPhase));
            Assert.IsTrue(ls.isEmpty());
        }