コード例 #1
0
        public static Game CreateGame(IEnumerable <IPlayer> players)
        {
            var dice = new MonopolyDice();

            var banker            = new Banker(players);
            var realEstateHandler = new OwnableHandler(BoardFactory.CreateRealEstate(dice), banker);
            var spaces            = BoardFactory.CreateNonRealEstateSpaces(banker);
            var spaceHandler      = new UnownableHandler(spaces);

            var boardHandler = new BoardHandler(players, realEstateHandler, spaceHandler, banker);
            var jailHandler  = new JailHandler(dice, boardHandler, banker);
            var turnHandler  = new TurnHandler(dice, boardHandler, jailHandler, realEstateHandler, banker);

            var deckFactory    = new DeckFactory(players, jailHandler, boardHandler, realEstateHandler, banker);
            var communityChest = deckFactory.BuildCommunityChestDeck();
            var chance         = deckFactory.BuildChanceDeck(dice);

            foreach (var space in spaces.Values.OfType <DrawCard>())
            {
                if (space.ToString() == "Community Chest")
                {
                    space.AddDeck(communityChest);
                }
                else
                {
                    space.AddDeck(chance);
                }
            }

            return(new Game(players, turnHandler, banker));
        }
コード例 #2
0
        public void RollBetweenOneAndTwelve()
        {
            var dice  = new MonopolyDice();
            var rolls = new List <Int32>();

            for (var i = 0; i < 1000000; i++)
            {
                dice.RollTwoDice();
                rolls.Add(dice.Value);
            }

            var max = rolls.Max();
            var min = rolls.Min();

            Assert.IsTrue(min > 0);
            Assert.IsTrue(max <= 12);
        }