예제 #1
0
        public void TestInitialize()
        {
            dice   = new Dice();
            banker = new Banker();
            board  = new Board(banker, dice);
            player = new Player("test");
            owner  = new Player("Owner");
            banker.AddAccount(owner, 1500);

            railRoad1 = new RailRoadProperty(5, banker, "railRoad1", 200);
            railRoad2 = new RailRoadProperty(15, banker, "railRoad2", 200);
            railRoad3 = new RailRoadProperty(25, banker, "railRoad3", 200);
            railRoad4 = new RailRoadProperty(35, banker, "railRoad4", 200);
            var groupedSpaces = new List <IOwnableProperty>()
            {
                railRoad1, railRoad2, railRoad3, railRoad4
            };

            railRoad1.GroupedSpaces = groupedSpaces;
            railRoad2.GroupedSpaces = groupedSpaces;
            railRoad3.GroupedSpaces = groupedSpaces;
            railRoad4.GroupedSpaces = groupedSpaces;

            dice.Roll();
        }
예제 #2
0
        public void AddPropertyResultsInAddedProperty()
        {
            var railRoad = new RailRoadProperty(5, banker, "RailRoad", 50);

            player.AddProperty(railRoad);

            Assert.IsTrue(player.OwnsProperty(railRoad));
        }
예제 #3
0
        public void OwnsPropertyCorrectlyIdentifiesIfPropertyIsOwned()
        {
            var playerOwns       = new RailRoadProperty(5, banker, "playerOwns", 50);
            var playerDoesNotOwn = new UtilityProperty(12, banker, "playerDoesNotOwn", 75, dice);

            player.AddProperty(playerOwns);

            Assert.IsTrue(player.OwnsProperty(playerOwns));
            Assert.IsFalse(player.OwnsProperty(playerDoesNotOwn));
        }
예제 #4
0
        public void TestInitialize()
        {
            var dice = new Dice();

            board                = new Board(banker, dice);
            readingRailRoad      = board.GetNextSpace(4) as RailRoadProperty;
            pennsylvaniaRailRoad = board.GetNextSpace(14) as RailRoadProperty;
            bAndORailRoad        = board.GetNextSpace(24) as RailRoadProperty;
            shortLineRailRoad    = board.GetNextSpace(34) as RailRoadProperty;

            var turnHandler  = new TurnHandler(board, banker, dice);
            var roundHandler = new RoundHandler(turnHandler);

            game = new Game(banker, roundHandler);

            player = game.CreatePlayerAccount("Car");
            horse  = game.CreatePlayerAccount("Horse");
        }
예제 #5
0
        public Board(int NumberOfPlayers)
        {
            /* Creating all of the spaces on the board*/
            IProperty[] prop = new IProperty[40];
            prop[0] = new MiscSpace("GO", 0, MiscSpace.MiscType.GO);
            int[] MediteraneanRent = new int[6] {
                2, 10, 30, 90, 160, 250
            };
            prop[1] = new RegularProperty("Mediterranean Avenue", 60, 1, 50, MediteraneanRent, RegularProperty.ColorGroup.DarkPurple);
            int [] CommChestDeck = RandomDeck();
            prop[2] = new ChanceAndCommChest("Community Chest", "CC", 2, CommChestDeck);
            int[] BalticRent = new int[6] {
                4, 20, 60, 180, 320, 500
            };
            prop[3] = new RegularProperty("Baltic Avenue", 60, 3, 50, BalticRent, RegularProperty.ColorGroup.DarkPurple);
            prop[4] = new RegularProperty("Income Tax", 200, 4, 0, null, RegularProperty.ColorGroup.Tax);
            int[] RRRent = new int[4] {
                25, 50, 100, 200
            };
            prop[5] = new RailRoadProperty("Reading Railroad", 5, RRRent);
            int[] OriAndVerRent = new int[6] {
                6, 30, 90, 270, 400, 550
            };
            prop[6] = new RegularProperty("Oriental Avenue", 100, 6, 50, OriAndVerRent, RegularProperty.ColorGroup.LightBlue);
            int[] ChanceDeck = RandomDeck();
            prop[7] = new ChanceAndCommChest("Chance", "Chance", 7, ChanceDeck);
            prop[8] = new RegularProperty("Vermont Avenue", 100, 8, 50, OriAndVerRent, RegularProperty.ColorGroup.LightBlue);
            int[] ConnectRent = new int[6] {
                8, 40, 100, 300, 450, 600
            };
            prop[9]  = new RegularProperty("Connecticut Avenue", 120, 9, 50, ConnectRent, RegularProperty.ColorGroup.LightBlue);
            prop[10] = new MiscSpace("Just Visiting Jail", 10, MiscSpace.MiscType.Visiting);
            int[] CharAndStateRent = new int[6] {
                10, 50, 150, 450, 625, 750
            };
            prop[11] = new RegularProperty("St.Charles Avenue", 140, 11, 100, CharAndStateRent, RegularProperty.ColorGroup.Violet);
            prop[12] = new UtilityProperty("Electric Company", 12, null, null);
            prop[13] = new RegularProperty("States Avenue", 140, 13, 100, CharAndStateRent, RegularProperty.ColorGroup.Violet);
            int[] VirgRent = new int[6] {
                12, 60, 180, 500, 700, 900
            };
            prop[14] = new RegularProperty("Virginia Avenue", 160, 14, 100, VirgRent, RegularProperty.ColorGroup.Violet);
            prop[15] = new RailRoadProperty("Pennsylvania Railroad", 15, RRRent);
            int[] JamesAndTennRent = new int[6] {
                14, 70, 200, 550, 750, 950
            };
            prop[16] = new RegularProperty("St.James Place", 180, 16, 100, JamesAndTennRent, RegularProperty.ColorGroup.Orange);
            prop[17] = new ChanceAndCommChest("Community Chest", "CC", 17, CommChestDeck);
            prop[18] = new RegularProperty("Tennessee Avenue", 180, 18, 100, JamesAndTennRent, RegularProperty.ColorGroup.Orange);
            int[] NYRent = new int[6] {
                16, 80, 220, 600, 800, 100
            };
            prop[19] = new RegularProperty("New York Avenue", 200, 19, 100, NYRent, RegularProperty.ColorGroup.Orange);
            prop[20] = new MiscSpace("Free Parking", 20, MiscSpace.MiscType.Parking);
            int[] KentAndIndiRent = new int[6] {
                18, 90, 250, 700, 875, 1050
            };
            prop[21] = new RegularProperty("Kentucky Avenue", 220, 21, 150, KentAndIndiRent, RegularProperty.ColorGroup.Red);
            prop[22] = new ChanceAndCommChest("Chance", "Chance", 22, ChanceDeck);
            prop[23] = new RegularProperty("Indiana Avenue", 220, 23, 150, KentAndIndiRent, RegularProperty.ColorGroup.Red);
            int[] IllRent = new int[6] {
                20, 100, 300, 750, 925, 1100
            };
            prop[24] = new RegularProperty("Illinois Avenue", 240, 24, 150, IllRent, RegularProperty.ColorGroup.Red);
            prop[25] = new RailRoadProperty("B & O Railroad", 25, RRRent);
            int[] AtlAndVentRent = new int[6] {
                22, 110, 330, 800, 975, 1150
            };
            prop[26] = new RegularProperty("Atlantic Avenue", 260, 26, 150, AtlAndVentRent, RegularProperty.ColorGroup.Yellow);
            prop[27] = new RegularProperty("Ventnor Avenue", 260, 27, 150, AtlAndVentRent, RegularProperty.ColorGroup.Yellow);
            prop[28] = new UtilityProperty("Water Works", 28, null, null);
            int[] MarvRent = new int[6] {
                24, 120, 360, 850, 1025, 1200
            };
            prop[29] = new RegularProperty("Marvin Gardens", 280, 29, 150, MarvRent, RegularProperty.ColorGroup.Yellow);
            prop[30] = new MiscSpace("Go To Jail", 30, MiscSpace.MiscType.GoToJail);
            int[] PacAndNCRent = new int[6] {
                26, 130, 390, 900, 1100, 1275
            };
            prop[31] = new RegularProperty("Pacific Avenue", 300, 31, 200, PacAndNCRent, RegularProperty.ColorGroup.Green);
            prop[32] = new RegularProperty("North Carolina Avenue", 300, 32, 200, PacAndNCRent, RegularProperty.ColorGroup.Green);
            prop[33] = new ChanceAndCommChest("Community Chest", "CC", 33, CommChestDeck);
            int[] PennRent = new int[6] {
                28, 150, 450, 100, 1200, 1400
            };
            prop[34] = new RegularProperty("Pennsylvania Avenue", 320, 34, 200, PennRent, RegularProperty.ColorGroup.Green);
            prop[35] = new RailRoadProperty("Short Line", 35, RRRent);
            prop[36] = new ChanceAndCommChest("Chance", "Chance", 36, ChanceDeck);
            int[] PPRent = new int[6] {
                35, 175, 500, 1100, 1300, 1500
            };
            prop[37] = new RegularProperty("Park Place", 350, 37, 200, PPRent, RegularProperty.ColorGroup.DarkBlue);
            prop[38] = new RegularProperty("Income Tax", 100, 38, 0, null, RegularProperty.ColorGroup.Tax);
            int[] BWRent = new int[6] {
                50, 200, 600, 1400, 1700, 2000
            };
            prop[39]   = new RegularProperty("Boardwalk", 400, 39, 200, BWRent, RegularProperty.ColorGroup.DarkBlue);
            Properties = prop;

            /* Creates the sets of houses and hotels*/
            HAndH = new HousesAndHotels();
        }
예제 #6
0
        public void RentCalculatorTest()
        {
            Board board = new Board(1);
            int   roll  = 1;

            IProperty[] owned      = null;
            Player      testPlayer = new Player("Chris", Player.Token.RaceCar, 1500, owned);
            Player      testOwner  = new Player("Bob", Player.Token.Battleship, 1500, owned);

            /* Mediterranean Ave Not Owned */
            testPlayer.Location = 1;
            int rent = Monopoly.RentCalculator(board, testPlayer, roll);

            Assert.AreEqual(rent, -1);
            /* Owned */
            board.Properties[1].Owner = testOwner;
            rent = Monopoly.RentCalculator(board, testPlayer, roll);
            Assert.AreEqual(rent, 2);
            Assert.AreEqual(testOwner.Funds, 1502);
            Assert.AreEqual(testPlayer.Funds, 1498);
            /* Mortgaged Mediterranean*/
            board.Properties[1].IsMortgaged = true;
            rent = Monopoly.RentCalculator(board, testPlayer, roll);
            Assert.AreEqual(rent, 0);
            Assert.AreEqual(testOwner.Funds, 1500);
            Assert.AreEqual(testPlayer.Funds, 1500);
            /* Monopoly 0 Houses Medit*/
            RegularProperty mediterranean = (RegularProperty)board.Properties[1];

            mediterranean.Monopoly = true;
            rent = Monopoly.RentCalculator(board, testPlayer, roll);
            Assert.AreEqual(rent, 4);
            /* 1 House */
            mediterranean.NumOfHouses = 1;
            rent = Monopoly.RentCalculator(board, testPlayer, roll);
            Assert.AreEqual(rent, 10);
            testPlayer.Funds = 1500;
            testOwner.Funds  = 1500;
            /* Community Chest */
            testPlayer.Location = 2;
            rent = Monopoly.RentCalculator(board, testPlayer, roll);
            Assert.AreEqual(rent, -2);
            /* Reading RR */
            testPlayer.Location       = 5;
            board.Properties[5].Owner = testOwner;
            rent = Monopoly.RentCalculator(board, testPlayer, roll);
            Assert.AreEqual(rent, 25);
            Assert.AreEqual(testOwner.Funds, 1525);
            Assert.AreEqual(testPlayer.Funds, 1475);
            /* Second RR */
            RailRoadProperty reading = (RailRoadProperty)board.Properties[5];

            reading.NumOfRRs = 2;
            rent             = Monopoly.RentCalculator(board, testPlayer, roll);
            Assert.AreEqual(rent, 50);
            testPlayer.Funds = 1500;
            testOwner.Funds  = 1500;
            /* Electric Company */
            testPlayer.Location        = 12;
            board.Properties[12].Owner = testOwner;
            rent = Monopoly.RentCalculator(board, testPlayer, roll);
            Assert.AreEqual(rent, 4);
            Assert.AreEqual(testOwner.Funds, 1504);
            Assert.AreEqual(testPlayer.Funds, 1496);
            testPlayer.Funds = 1500;
            testOwner.Funds  = 1500;
            /* Both Utilities Owned By Own*/
            UtilityProperty electric = (UtilityProperty)board.Properties[12];

            electric.Monopoly = true;
            rent = Monopoly.RentCalculator(board, testPlayer, roll);
            Assert.AreEqual(rent, 10);
            Assert.AreEqual(testOwner.Funds, 1510);
            Assert.AreEqual(testPlayer.Funds, 1490);
            testPlayer.Funds = 1500;
            testOwner.Funds  = 1500;
        }
예제 #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Console Monopoly!");
            bool   isPlayerCountWrong = true;
            string stringPlayers      = "";

            while (isPlayerCountWrong)
            {
                Console.WriteLine("How many players do you want to play with?(Max 8 players)");
                stringPlayers = Console.ReadLine();
                try
                {
                    int numberofPlayers = int.Parse(stringPlayers);
                    if (numberofPlayers > 1 && numberofPlayers < 8)
                    {
                        isPlayerCountWrong = false;
                    }
                    else
                    {
                        Console.WriteLine("Please enter a number between 2-8");
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine("Unable to convert '{0}'.", stringPlayers);
                    Console.WriteLine("Please try again with a valid number");
                }
                catch (OverflowException)
                {
                    Console.WriteLine("'{0}' is out of range of the Int32 type.", stringPlayers);
                    Console.WriteLine("Please try again with a valid number");
                }
                catch (ArgumentNullException)
                {
                    Console.WriteLine("This is either a '' or null");
                    Console.WriteLine("Please try again with a valid number");
                }
            }
            int numOfPlayers = int.Parse(stringPlayers);

            Player[] listOfPlayers = new Player[numOfPlayers];
            int      playerNumber  = 0;

            Console.WriteLine("The max length for names is 32 characters.");
            for (int i = 0; i < numOfPlayers; i++)
            {
                bool   isNameGood = true;
                string name       = "";
                while (isNameGood)
                {
                    Console.WriteLine("Please enter the name of Player {0}", i + 1);
                    name = Console.ReadLine();
                    if (name != "" && name != null)
                    {
                        isNameGood = false;
                    }
                    else
                    {
                        Console.WriteLine("This is either a '' or null");
                        Console.WriteLine("Please try again with a valid string");
                    }
                }
                if (name.Length > 32)
                {
                    name = name.Substring(0, 32);
                }
                bool         uniqueToken = true;
                Player.Token token       = Player.Token.Null;
                while (uniqueToken)
                {
                    Console.WriteLine("Please choose a token by using the number next to the token");
                    int j = 0;
                    foreach (var token1 in Enum.GetValues(typeof(Player.Token)))
                    {
                        Console.WriteLine("{0}:{1}", j, token1);
                        j++;
                    }
                    int playerChoice = 0;
                    try
                    {
                        playerChoice = Convert.ToInt32(Console.ReadLine());
                    }
                    catch (FormatException)
                    {
                        Console.WriteLine("Unable to convert '{0}'.", stringPlayers);
                        Console.WriteLine("Please try again with a valid number");
                    }
                    switch (playerChoice)
                    {
                    case 0:
                        Console.WriteLine("You chose Null.");
                        break;

                    case 1:
                        Console.WriteLine("You chose Scottish Terrier");
                        token = Player.Token.ScottishTerrier;
                        break;

                    case 2:
                        Console.WriteLine("You chose Battleship");
                        token = Player.Token.Battleship;
                        break;

                    case 3:
                        Console.WriteLine("You chose Race Car");
                        token = Player.Token.RaceCar;
                        break;

                    case 4:
                        Console.WriteLine("You chose Top Hat");
                        token = Player.Token.TopHat;
                        break;

                    case 5:
                        Console.WriteLine("You chose Thimble");
                        token = Player.Token.Thimble;
                        break;

                    case 6:
                        Console.WriteLine("You chose Shoe");
                        token = Player.Token.Shoe;
                        break;

                    case 7:
                        Console.WriteLine("You chose Wheel Barrow");
                        token = Player.Token.WheelBarrow;
                        break;

                    case 8:
                        Console.WriteLine("You chose Howitzer");
                        token = Player.Token.Howitzer;
                        break;

                    case 9:
                        Console.WriteLine("You chose Iron");
                        token = Player.Token.Iron;
                        break;

                    default:
                        Console.WriteLine("You chose an invalid number. ");
                        Console.WriteLine("You get to play as Null now.");
                        break;
                    }
                    /*This part needs fixing, does not catch copy tokens.*/
                    for (int k = 0; k < (listOfPlayers.Length - 1); k++)
                    {
                        Player player1 = listOfPlayers[k];
                        if (player1 != null)
                        {
                            if (token == Player.Token.Null)
                            {
                                uniqueToken = false;
                                break;
                            }
                            else if (token == player1.PlayerToken)
                            {
                                Console.WriteLine("Please choose a unique token");
                                Console.WriteLine("Someone has already picked {0}", player1.PlayerToken.ToString());
                            }
                            else
                            {
                                uniqueToken = false;
                            }
                        }
                        else
                        {
                            uniqueToken = false;
                        }
                    }
                }
                IProperty[] ownedProperties = new IProperty[0];
                Player      player          = new Player(name, token, 1500, ownedProperties);
                listOfPlayers[playerNumber] = player;
                playerNumber++;
            }
            Console.WriteLine("Creating new board...");
            Board board = new Board(numOfPlayers);

            Console.WriteLine("Choosing who goes first. The order will be the same as when you added them.");
            int[]    rolls = new int[listOfPlayers.Length];
            DiceRoll dice  = new DiceRoll();

            for (int player = 0; player < listOfPlayers.Length; player++)
            {
                rolls[player] = dice.Roll();
            }
            int max   = rolls.Max();
            int index = Array.IndexOf(rolls, max);

            Console.WriteLine("Congratulations {0}! You get to go first", listOfPlayers[index].Name);

            bool   isGameStillGoing = true;
            int    turn             = index;
            Player currentPlayer    = listOfPlayers[index];
            int    chanceCard       = 0;
            int    commChestCard    = 0;

            while (isGameStillGoing)
            {
                bool endTurn = true;
                while (endTurn)
                {
                    Console.WriteLine("It is {0}'s turn. What would you like to do?", listOfPlayers[turn]);
                    if (currentPlayer.isJail)
                    {
                        Console.WriteLine("You are currently in jail. Your actions are limited to");
                    }
                    int j = 0;
                    foreach (var action in Enum.GetValues(typeof(Action)))
                    {
                        Console.WriteLine("{0}:{1}", j, action);
                    }
                    int playerAction = 0;
                    try
                    {
                        playerAction = Convert.ToInt32(Console.ReadLine());
                    }
                    catch (FormatException)
                    {
                        Console.WriteLine("Unable to convert '{0}'.", stringPlayers);
                        Console.WriteLine("Please try again with a valid number");
                    }
                    switch (playerAction)
                    {
                    case 0:     /* End turn */
                        Console.WriteLine("You have chosen to end your turn");
                        endTurn = false;
                        break;

                    case 1:     /* Roll */
                        max = dice.Roll();
                        currentPlayer.Location += max;
                        if (currentPlayer.Location > 39)
                        {
                            currentPlayer.Location -= 40;
                        }
                        IProperty currentProperty = board.Properties[currentPlayer.Location];
                        Console.WriteLine("You have moved forward {0} spaces and landed on {1}", max, currentProperty.Name);
                        /* Now that they have landed do something*/
                        int rentDue = RentCalculator(board, currentPlayer, max);     /* Rent is due. Handled in the function */
                        PropertyChecker(rentDue, board, listOfPlayers, currentProperty, currentPlayer, commChestCard, chanceCard);
                        break;

                    case 4:     /* Funds */
                        Console.WriteLine("You currently have ${0} in your funds.", currentPlayer.Funds);
                        break;

                    case 5:     /*Properties */
                        foreach (IProperty property in currentPlayer.OwnedProperties)
                        {
                            if (property.Type == "Util")
                            {
                                Console.WriteLine("Name: {0}", property.Name);
                            }
                            else if (property.Type == "RR")
                            {
                                RailRoadProperty RRproperty = (RailRoadProperty)property;
                                Console.WriteLine("Name: {0} Rent: {1}", property.Name, (int)RRproperty.RentArray.GetValue(RRproperty.NumOfRRs));
                            }
                            else
                            {
                                RegularProperty regularProperty = (RegularProperty)property;
                                Console.WriteLine("Name: {0} Rent: {1} House Cost: {2}", regularProperty.Name, (int)regularProperty.RentArray.GetValue(regularProperty.NumOfHouses), regularProperty.HouseCost);
                            }
                        }
                        break;
                    }
                }
            }
        }