示例#1
0
        public void PlayerRankingShouldContainTheNumberOfWins()
        {
            var round1 = new Round(1);
            round1.AddSelection(1, PaperStoneScissorsGameObject.Scissors);
            round1.AddSelection(2, PaperStoneScissorsGameObject.Paper);

            var round2 = new Round(2);
            round2.AddSelection(1, PaperStoneScissorsGameObject.Scissors);
            round2.AddSelection(2, PaperStoneScissorsGameObject.Paper);

            var round3 = new Round(3);
            round3.AddSelection(1, PaperStoneScissorsGameObject.Scissors);
            round3.AddSelection(2, PaperStoneScissorsGameObject.Paper);

            var players = HelperExtensions.GeneratePlayers(2);

            var game = new Game<Round>(players, new FirstToGamePlayingStrategy(3));

            game.AddRoundResult(round1);
            game.AddRoundResult(round2);
            game.AddRoundResult(round3);

            var ranking = game.GetRanking().ToList();

            Assert.That(ranking.Count, Is.EqualTo(2));
            Assert.That(ranking[0].Player.Wins, Is.EqualTo(3));
            Assert.That(ranking[1].Player.Wins, Is.EqualTo(0));
        }
示例#2
0
        public void GameShouldNotAllowAdditionalRoundsOnceComplete()
        {
            var round1 = new Round(1);
            round1.AddSelection(1, PaperStoneScissorsGameObject.Scissors);
            round1.AddSelection(2, PaperStoneScissorsGameObject.Paper);

            var round2 = new Round(2);
            round2.AddSelection(1, PaperStoneScissorsGameObject.Scissors);
            round2.AddSelection(2, PaperStoneScissorsGameObject.Paper);

            var players = HelperExtensions.GeneratePlayers(2);

            var game = new Game<Round>(players, new FirstToGamePlayingStrategy(1));

            game.AddRoundResult(round1);

            Assert.That(() => game.AddRoundResult(round2), Throws.An<GameAlreadyCompletedException>());
        }
示例#3
0
        public ActionResult SaveRound(PaperStoneScissorsGameObject chosenObject)
        {
            if (Game == null)
                return RedirectToAction("NewGame");

            var autoCompleted = GameObjectHelper.ChoseRandom();

            var round = new Round(Game.Rounds.Count + 1);
            round.AddSelection(1, chosenObject);
            round.AddSelection(2, autoCompleted);
            Game.AddRoundResult(round);

            if (Game.Complete)
            {
                return RedirectToAction("Results");
            }

            return View(Game.Rounds);
        }
示例#4
0
 public void WhenTheFollowingRoundsArePlayed(Table table)
 {
     int roundNumber = 0;
     foreach (var row in table.Rows)
     {
         roundNumber++;
         // TODO: Adapt this for multiple sets of players
         var round = new Round(roundNumber);
         round.AddSelection(1, row["Player 1"].ToRoundResult().MakeupObjectFromResult());
         round.AddSelection(2, row["Player 2"].ToRoundResult().MakeupObjectFromResult());
         round.AddSelection(3, row["Player 3"].ToRoundResult().MakeupObjectFromResult());
         Game.AddRoundResult(round);
     }
 }
示例#5
0
 public void WhenIWinXRounds(int rounds)
 {
     for (int i = 0; i < rounds; i++)
     {
         var round = new Round(i + 1);
         round.AddSelection(1, RoundResult.Win.MakeupObjectFromResult());
         round.AddSelection(2, RoundResult.Lose.MakeupObjectFromResult());
         Game.AddRoundResult(round);
     }
 }
示例#6
0
 public void WhenILoseXRounds()
 {
     var round = new Round(1);
     round.AddSelection(1, RoundResult.Lose.MakeupObjectFromResult());
     round.AddSelection(2, RoundResult.Win.MakeupObjectFromResult());
     Game.AddRoundResult(round);
 }