public void ResPhasetest() { Player p1 = new Player(0); Player p2 = new Player(1); IGame game = mocks.Stub <IGame>(); Card attack = new Attack(CardSuit.Spade, 1); Phase a = new ActionPhase(p1); PhaseList ret = a.advance(new UseCardAction(attack, p2), game); Phase b = ret.pop(); AttackPhase b2 = b as AttackPhase; Miss miss = new Miss(CardSuit.Diamond, 2); p1.handCards.Add(attack); p2.handCards.Add(miss); p1.health = 1; Player[] p = new Player[1]; p[0] = p1; ret = b.advance(null, game); Phase c = ret.pop(); ResponsePhase c_ = c as ResponsePhase; Assert.IsNull(c_.responseYesOrNo(true, game)); }
public ActionResult Index() { var model = new PhaseList(); model.Phases = Context.Phases.GetAllPhases(); return(View(model)); }
public void Res3Phasetest() { // ActionPhase produces attackPhase 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 ActionPhase a = new ActionPhase(p1); PhaseList ret = a.advance(new UseCardAction(attack, p2), game); Phase b = ret.pop(); AttackPhase b2 = b as AttackPhase; Miss miss = new Miss(CardSuit.Diamond, 2); p1.handCards.Add(attack); p1.handCards.Add(miss); p1.health = 1; Player[] p = new Player[1]; p[0] = p1; // AttackPhase produces responsePhase ret = b.advance(null, game); Phase c = ret.pop(); ResponsePhase c_ = c as ResponsePhase; Assert.AreEqual(c_.ToString(), "Response Phase of 1"); }
public bool AddPhase(string name) { try { var phase = new MissionPhase(name) { ID = Guid.NewGuid().ToString("D") }; if (PhaseList.Count > 0) { var lastTimeExtent = PhaseList.Last().VisibleTimeExtent; phase.VisibleTimeExtent = new TimeExtent(lastTimeExtent.End.AddSeconds(1.0), lastTimeExtent.Offset(new TimeSpan(1, 0, 0)).End); } else { // set default time extent phase.VisibleTimeExtent = new TimeExtent(DateTime.Now, DateTime.Now.AddSeconds(3599)); } PhaseList.Add(phase); } catch { return(false); } return(true); }
public void Res5Phasetest() { SunQuan p1 = new SunQuan(0); LiuBei p2 = new LiuBei(1); List <Card> x = new List <Card>(); Player[] p = new SunQuan[1]; p[0] = p1; Miss miss = new Miss(CardSuit.Diamond, 2); Card attack = new Attack(CardSuit.Spade, 1); x.Add(miss); x.Add(attack); Game game = new Game(p, new CardSet(x)); // ActionPhase produces attackPhase ActionPhase a = new ActionPhase(p1); PhaseList ret = a.advance(new UseCardAction(attack, p2), game); Phase b = ret.pop(); AttackPhase b2 = b as AttackPhase; p1.handCards.Add(attack); p1.handCards.Add(miss); p1.health = 1; // AttackPhase produces responsePhase ret = b.advance(null, game); Phase c = ret.pop(); ResponsePhase c_ = c as ResponsePhase; Assert.IsInstanceOfType(a.responseAbilityActionSun(new AbilityActionSun(attack), game), typeof(PhaseList)); }
public void TestEnumerator() { List <Phase> list = new List <Phase>(); list.Add(new PhaseSimple(0)); list.Add(new PhaseSimple(1)); list.Add(new PhaseSimple(2)); list.Add(new PhaseSimple(3)); list.Add(new PhaseSimple(4)); PhaseList ls = new PhaseList(); ls.add(list[0]); ls.add(list[1]); ls.add(list[2]); ls.add(list[3]); ls.add(list[4]); int i = 0; foreach (Phase p in ls) { Assert.AreEqual(list[i], p); i++; } }
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 phaselistpush() { PhaseList p = new PhaseList(); ActionPhase a = new ActionPhase(new ZhangFei(1)); p.push(a); Assert.AreEqual(p.top(), a); }
public void TestPushOneStageList() { PhaseList ls = new PhaseList(); ls.add(new PhaseSimple(0)); Assert.AreEqual(ls.pop().playerID, 0); Assert.IsTrue(ls.isEmpty()); }
public void phaselistenum() { PhaseList p = new PhaseList(); p.add(new ActionPhase(new ZhangFei(1))); Assert.IsInstanceOfType(p.GetEnumerator(), typeof(IEnumerator <Phase>)); }
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()); }
public void CaoCaoAbtestnomockBVATest() { 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); int old = p.handCards.Count; PhaseList ret = p.harm(new HarmPhase(p, null, harm, card), game); int newc = p.handCards.Count; Assert.IsTrue(old == newc); }
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); }
public void CaoCaoAbtestnomockhealthless0() { { Attack card = new Attack(CardSuit.Club, 1); IGame game = mocks.Stub <IGame>(); int health = -1; int harm = 1; Player p = new CaoCao(1); int old = p.handCards.Count; p.health = -1; PhaseList ret = p.harm(new HarmPhase(p, null, harm, card), game); int newc = p.handCards.Count; } }
public Mission DeepCopy() { Mission mission = (Mission)MemberwiseClone(); mission.Name = String.Copy(Name); var pl = PhaseList.Select(mp => new MissionPhase { ID = String.Copy(mp.ID), Name = String.Copy(mp.Name), VisibleTimeExtent = new TimeExtent(mp.VisibleTimeExtent.Start, mp.VisibleTimeExtent.End) }).ToList(); mission.PhaseList = pl; return(mission); }
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 CaoCaoAbtestnomocknull() { { Attack card = new Attack(CardSuit.Club, 1); IGame game = mocks.Stub <IGame>(); int health = 5; int harm = 1; Player p = new CaoCao(1); int old = p.handCards.Count; PhaseList ret = p.harm(null, game); int newc = p.handCards.Count; Assert.IsTrue(old + 1 == newc); } }
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()); }
public void processUserInputTest() { MockRepository mocks = new MockRepository(); mocks.Stub <UserAction>(); Game g = new Game(players, cardList); Type stage = typeof(Game); FieldInfo stinfo = stage.GetField("stages", BindingFlags.NonPublic | BindingFlags.Instance); PhaseList p = new PhaseList(); p.add(new DiscardPhase(players[0])); p.add(new DiscardPhase(players[0])); stinfo.SetValue(g, p); g.processUserInput(0, mocks.Stub <UserAction>()); }
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()); }
public void TestPushStageList() { 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); }
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 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()); }
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); }
public PhaseViewerVm(IContest contest) { if (contest == null) { throw new ArgumentNullException(nameof(contest)); } PhaseList = contest.PhaseList.Select(_ => new PhaseViewItem(_)).ToList(); contest.NewPhaseLaunch += (sender, phase) => PhaseList.Add(new PhaseViewItem(phase)); var timer = new DispatcherTimer(); timer.Tick += RefreshClock; timer.Interval = TimeSpan.FromSeconds(1); timer.Start(); WatchNextPhase(); timer = new DispatcherTimer(); timer.Tick += ChangePhase; timer.Interval = TimeSpan.FromSeconds(60); timer.Start(); }
private void WatchNextPhase() { while (true) { if (_index >= PhaseList.Count) { _index = 0; } if (PhaseList.Count == 0) { return; } var next = PhaseList[_index]; if (next.IsFinished) { PhaseList.Remove(next); continue; } Current = PhaseList[_index]; _index++; break; } }
public void TestConstruct() { PhaseList ls = new PhaseList(); }
public void phaselistpop() { PhaseList p = new PhaseList(); p.pop(); }