Пример #1
0
        public void setUpPlayers()
        {
            //Add players to the board
            Console.WriteLine("How many players are playing?");
            Console.Write("(2-8)>");
            int playerCount = this.inputInteger();

            //if it is out of range then display msg and redo this method
            if ((playerCount < 2) || (playerCount > 8))
            {
                Console.WriteLine("That is an invalid amount. Please try again.");
                this.setUpPlayers();
            }

            //Ask for players names
            for (int i = 0; i < playerCount; i++)
            {
                Console.WriteLine("Please enter the name for Player {0}:", i + 1);
                Console.Write(">");
                string sPlayerName = Console.ReadLine();
                Player player      = new Player(sPlayerName);
                //subscribe to events
                player.playerBankrupt += playerBankruptHandler;
                player.playerPassGo   += playerPassGoHandler;
                //add player
                Board.access().addPlayer(player);
                Console.WriteLine("{0} has been added to the game.", Board.access().getPlayer(i).getName());
            }

            Console.WriteLine("Players have been setup");
        }
Пример #2
0
        public void setUpProperties()
        {
            //Create instances of property factories
            LuckFactory        luckFactory    = new LuckFactory();
            ResidentialFactory resFactory     = new ResidentialFactory();
            TransportFactory   transFactory   = new TransportFactory();
            UtilityFactory     utilFactory    = new UtilityFactory();
            PropertyFactory    genericFactory = new PropertyFactory();

            //Create properties and add them to the board
            //Loading property details from file has not been implemented
            //Property names are taken from the "Here and Now" New Zealand version of monopoly
            //Rents are tenth of cost of property
            //Colours have not been implemented
            Board.access().addProperty(luckFactory.create("Go", false, 200));
            Board.access().addProperty(resFactory.create("Ohakune Carrot", 60, 6, 50));
            Board.access().addProperty(luckFactory.create("Community Chest", false, 50)); // not properly implemented just 50 benefit
            Board.access().addProperty(resFactory.create("Te Puke, Giant Kiwifruit", 60, 6, 50));
            Board.access().addProperty(luckFactory.create("Income Tax", true, 200));
            Board.access().addProperty(transFactory.create("Auckland International Airport"));
            Board.access().addProperty(resFactory.create("Te Papa", 100, 10, 50));
            Board.access().addProperty(luckFactory.create("Chance", true, 50)); // not properly implemented just 50 penalty
            Board.access().addProperty(resFactory.create("Waitangi Treaty Grounds", 100, 10, 50));
            Board.access().addProperty(resFactory.create("Larnach Castle", 120, 12, 50));
            Board.access().addProperty(genericFactory.create("Jail")); //not properly implemented just a property that does nothing
            Board.access().addProperty(resFactory.create("Cape Reinga Lighthouse", 140, 14, 100));
            Board.access().addProperty(utilFactory.create("Mobile Phone Company"));
            Board.access().addProperty(resFactory.create("Lake Taupo", 140, 14, 100));
            Board.access().addProperty(resFactory.create("Queenstown Ski Fields", 160, 16, 100));
            Board.access().addProperty(transFactory.create("Dunedin Railway Station"));
            Board.access().addProperty(resFactory.create("Fox Glacier", 180, 18, 100));
            Board.access().addProperty(luckFactory.create("Community Chest", false, 50)); // not properly implemented just 50 benefit
            Board.access().addProperty(resFactory.create("Milford Sound", 180, 18, 100));
            Board.access().addProperty(resFactory.create("Mt Cook", 200, 20, 100));
            Board.access().addProperty(genericFactory.create("Free Parking"));  //not properly implemented just a property that does nothing
            Board.access().addProperty(resFactory.create("Ninety Mile Beach", 220, 22, 150));
            Board.access().addProperty(luckFactory.create("Chance", true, 50)); // not properly implemented just 50 penalty
            Board.access().addProperty(resFactory.create("Golden Bay", 220, 22, 150));
            Board.access().addProperty(resFactory.create("Moeraki Boulders, Oamaru", 240, 24, 150));
            Board.access().addProperty(transFactory.create("Port Tauranga"));
            Board.access().addProperty(resFactory.create("Waitomo Caves", 260, 26, 150));
            Board.access().addProperty(resFactory.create("Mt Maunganui", 260, 26, 150));
            Board.access().addProperty(utilFactory.create("Internet Service Provider"));
            Board.access().addProperty(resFactory.create("Art Deco Buildings, Napier", 280, 28, 150));
            Board.access().addProperty(genericFactory.create("Go to Jail")); //not properly implemented just a property that does nothing
            Board.access().addProperty(resFactory.create("Cable Cars Wellington", 300, 30, 200));
            Board.access().addProperty(resFactory.create("Cathedral Square", 300, 30, 200));
            Board.access().addProperty(luckFactory.create("Community Chest", false, 50)); // not properly implemented just 50 benefit
            Board.access().addProperty(resFactory.create("The Square, Palmerston North", 320, 32, 200));
            Board.access().addProperty(transFactory.create("Picton Ferry"));
            Board.access().addProperty(luckFactory.create("Chance", true, 50)); // not properly implemented just 50 penalty
            Board.access().addProperty(resFactory.create("Pukekura Park, Festival of Lights", 350, 35, 200));
            Board.access().addProperty(luckFactory.create("Super Tax", true, 100));
            Board.access().addProperty(resFactory.create("Rangitoto", 400, 40, 200));


            Console.WriteLine("Properties have been setup");
        }
Пример #3
0
        public override void makePlay(int iPlayerIndex)
        {
            Console.Clear();
            //make variable for player
            Player player = Board.access().getPlayer(iPlayerIndex);

            //Change the colour for the player
            Console.ForegroundColor = this.colors[iPlayerIndex];

            //if inactive skip turn
            if (player.isNotActive())
            {
                Console.WriteLine("\n{0} is inactive.\n", player.getName());
                //check players to continue
                //check that there are still two players to continue
                int activePlayerCount = 0;
                foreach (Player p in Board.access().getPlayers())
                {
                    //if player is active
                    if (!p.isNotActive())
                    {
                        //increment activePlayerCount
                        activePlayerCount++;
                    }
                }

                //if less than two active players display winner
                if (activePlayerCount < 2)
                {
                    this.printWinner();
                }

                return;
            }



            //prompt player to make move
            Console.WriteLine("{0}Your turn. Press Enter to make move", playerPrompt(iPlayerIndex));
            Console.ReadLine();
            //move player
            player.move();

            //Display making move
            Console.WriteLine("*****Move for {0}:*****", player.getName());
            //Display rolling
            Console.WriteLine("{0}{1}\n", playerPrompt(iPlayerIndex), player.diceRollingToString());

            Property propertyLandedOn = Board.access().getProperty(player.getLocation());

            //landon property and output to console
            Console.WriteLine(propertyLandedOn.landOn(ref player));
            //Display player details
            Console.WriteLine("\n{0}{1}", playerPrompt(iPlayerIndex), player.BriefDetailsToString());
            //display player choice menu
            displayPlayerChoiceMenu(player);
        }
Пример #4
0
        public void testAddGetPlayer()
        {
            Player p = new Player("Go");

            Board.access().addPlayer(p);

            //check that the player is equal to a new player with name "Go"
            Assert.AreEqual(Board.access().getPlayer("Go"), p);
        }
Пример #5
0
        public void tradeProperty(Player player)
        {
            //create prompt
            string sPropPrompt = String.Format("{0}Please select a property to trade:", this.playerPrompt(player));
            //create prompt
            string sPlayerPrompt = String.Format("{0}Please select a player to trade with:", this.playerPrompt(player));

            //get the property to trade
            TradeableProperty propertyToTrade = (TradeableProperty)this.displayPropertyChooser(player.getPropertiesOwnedFromBoard(), sPropPrompt);

            //if dont own any properties
            if (propertyToTrade == null)
            {
                //write message
                Console.WriteLine("{0}You do not own any properties.", playerPrompt(player));
                //return from method
                return;
            }

            //get the player wishing to trade with
            Player playerToTradeWith = this.displayPlayerChooser(Board.access().getPlayers(), player, sPlayerPrompt);

            //get the amount wanted

            string inputAmtMsg = string.Format("{0}How much do you want for this property?", playerPrompt(player));

            decimal amountWanted = inputDecimal(inputAmtMsg);

            //confirm with playerToTradeWith


            //set console color
            ConsoleColor origColor = Console.ForegroundColor;
            int          i         = Board.access().getPlayers().IndexOf(playerToTradeWith);

            Console.ForegroundColor = this.colors[i];

            //get player response
            bool agreesToTrade = getInputYN(playerToTradeWith, string.Format("{0} wants to trade '{1}' with you for ${2}. Do you agree to pay {2} for '{1}'", player.getName(), propertyToTrade.getName(), amountWanted));

            //resent console color
            Console.ForegroundColor = origColor;
            if (agreesToTrade)
            {
                Player playerFromBoard = Board.access().getPlayer(playerToTradeWith.getName());
                //player trades property

                player.tradeProperty(ref propertyToTrade, ref playerFromBoard, amountWanted);
                Console.WriteLine("{0} has been traded successfully. {0} is now owned by {1}", propertyToTrade.getName(), playerFromBoard.getName());
            }
            else
            {
                //display rejection message
                Console.WriteLine("{0}{1} does not agree to trade {2} for ${3}", playerPrompt(player), playerToTradeWith.getName(), propertyToTrade.getName(), amountWanted);
            }
        }
Пример #6
0
 public void playGame()
 {
     while (Board.access().getPlayerCount() >= 2)
     {
         for (int i = 0; i < Board.access().getPlayerCount(); i++)
         {
             this.makePlay(i);
         }
     }
 }
Пример #7
0
        public void addGetProperty()
        {
            Property p = new Property();

            Board.access().addProperty(p);

            Assert.AreEqual(p, Board.access().getProperty(0));

            ArrayList props = Board.access().getProperties();

            CollectionAssert.Contains(props, p);
        }
Пример #8
0
        public ArrayList getPropertiesOwnedFromBoard()
        {
            ArrayList propertiesOwned = new ArrayList();

            //go through all the properties
            for (int i = 0; i < Board.access().getProperties().Count; i++)
            {
                //owned by this player
                if (Board.access().getProperty(i).getOwner() == this)
                {
                    //add to arraylist
                    propertiesOwned.Add(Board.access().getProperty(i));
                }
            }
            return(propertiesOwned);
        }
Пример #9
0
        public void setLocation(int location)
        {
            //if set location is greater than number of squares then move back to beginning
            if (location >= Board.access().getSquares())
            {
                location = (location - Board.access().getSquares());
                //raise the pass go event if subscribers
                if (playerPassGo != null)
                {
                    this.playerPassGo(this, new EventArgs());
                }
                //add 200 for passing go
                this.receive(200);
            }

            this.location = location;
        }
Пример #10
0
 public void purchaseProperty(Player player)
 {
     //if property available give option to purchase else so not available
     if (Board.access().getProperty(player.getLocation()).availableForPurchase())
     {
         TradeableProperty propertyLocatedOn = (TradeableProperty)Board.access().getProperty(player.getLocation());
         bool respYN = getInputYN(player, string.Format("'{0}' is available to purchase for ${1}. Are you sure you want to purchase it?", propertyLocatedOn.getName(), propertyLocatedOn.getPrice()));
         if (respYN)
         {
             propertyLocatedOn.purchase(ref player);//purchase property
             Console.WriteLine("{0}You have successfully purchased {1}.", playerPrompt(player), propertyLocatedOn.getName());
         }
     }
     else
     {
         Console.WriteLine("{0}{1} is not available for purchase.", playerPrompt(player), Board.access().getProperty(player.getLocation()).getName());
     }
 }
Пример #11
0
        public override void printWinner()
        {
            Player winner = null;

            //get winner who is last active player
            foreach (Player p in Board.access().getPlayers())
            {
                //if player is active
                if (!p.isNotActive())
                {
                    winner = p;
                }
            }
            //display winner
            Console.WriteLine("\n\n{0} has won the game!\n\n", winner.getName());
            //end the game
            this.endOfGame();
        }
Пример #12
0
        public void move()
        {
            die1.roll();
            die2.roll();
            //move distance is total of both throws
            int iMoveDistance = die1.roll() + die2.roll();

            //increase location
            this.setLocation(this.getLocation() + iMoveDistance);
            this.lastMove = iMoveDistance;

            //2.7 Extend use of Delegates and Events by adding at least two new Events to the game.
            this.luckyDiceEvent(this, new EventArgs());
            this.doubleDiceEvent(this, new EventArgs());

            //2.6 Demonstrate use of generics in the project
            Board.access().record(die1.numberLastRolled(), die2.numberLastRolled(), this.sName);
            Console.WriteLine("The player has moved the sum steps: " + Board.access().showStep(this.sName));
        }
Пример #13
0
        public void testGetPlayerCount()
        {
            //test that is 0 when no players
            Assert.AreEqual(0, Board.access().getPlayerCount());

            //add a player
            Board.access().addPlayer(new Player());

            //count should be 1
            Assert.AreEqual(1, Board.access().getPlayerCount());

            //add 5 more players
            for (int i = 0; i < 5; i++)
            {
                //add a player
                Board.access().addPlayer(new Player());
            }

            //count should be 6
            Assert.AreEqual(6, Board.access().getPlayerCount());
        }
Пример #14
0
        public void displayPlayerChoiceMenu(Player player)
        {
            int resp = 0;

            Console.WriteLine("\n{0}Please make a selection:\n", playerPrompt(player));
            Console.WriteLine("1. Finish turn");
            Console.WriteLine("2. View your details");
            Console.WriteLine("3. Purchase This Property");
            Console.WriteLine("4. Buy House for Property");
            Console.WriteLine("5. Trade Property with Player");
            Console.WriteLine("6. Save ALL Game");

            // 3.2-Serialisation add a method to open Binary File and Deserialize to object

            Console.Write("(1-6)>");
            //read response
            resp = inputInteger();
            //if response is invalid redisplay menu
            if (resp == 0)
            {
                this.displayPlayerChoiceMenu(player);
            }

            //perform choice according to number input
            switch (resp)
            {
            case 1:
                break;

            case 2:
                Console.WriteLine("==================================");
                Console.WriteLine(player.FullDetailsToString());
                Console.WriteLine("==================================");
                this.displayPlayerChoiceMenu(player);
                break;

            case 3:
                this.purchaseProperty(player);
                this.displayPlayerChoiceMenu(player);
                break;

            case 4:
                this.buyHouse(player);
                this.displayPlayerChoiceMenu(player);
                break;

            case 5:
                this.tradeProperty(player);
                this.displayPlayerChoiceMenu(player);
                break;

            // 3.2-Serialisation add a method to open Binary File and Deserialize to object
            case 6:
            {
                ArrayList properties = Board.access().getProperties();
                ArrayList players    = Board.access().getPlayers();

                WriteRead savetoBinary = new WriteRead();
                //savetoBinary.savePositionToBinary(board);


                savetoBinary.savePropertyToBinary(properties);
                savetoBinary.savePlayerToBinary(players);
                break;
            }

            default:
                Console.WriteLine("That option is not avaliable. Please try again.");
                this.displayPlayerChoiceMenu(player);
                break;
            }
        }
Пример #15
0
 public string playerPrompt(int playerIndex)
 {
     return(string.Format("{0}:\t", Board.access().getPlayer(playerIndex).getName()));
 }
Пример #16
0
        public void setUpPlayers()
        {
            //Add players to the board
            Console.WriteLine("How many players are playing?");
            Console.Write("(2-8)>");
            int playerCount = this.inputInteger();



            int a = 0;

            //3.1-Load game initial set up from file.
            do
            {
                // Ask Initial money for each player
                // Console.WriteLine("Would you like to setup initial money ( if no, you will just use 2000$) ? (Y/N)");

                // 2.2 add a new  design pattern_Adapter
                Console.OutputEncoding = Encoding.GetEncoding(936);

                //Console.OutputEncoding = Encoding.UTF8;
                new Adapter().WriteLine("Would you like to setup initial money ( if no, you will just use 2000$) ? (Y/N)");

                //judge the player's input
                string r = Console.ReadLine();

                if (r.Equals("Y"))
                {
                    // how much money will pay to each player
                    Console.WriteLine("Please enter the money of players :");



                    // read the money player input
                    string m = Console.ReadLine();

                    // write into the txt file
                    WriteRead writer = new WriteRead();

                    writer.Write(m);

                    setD = false;

                    break;
                }
                else if (r.Equals("N"))
                {
                    setD = true;
                    Console.WriteLine("Congratulations! You have set 2000$ to every players .");

                    WriteRead writer = new WriteRead();

                    writer.Write("2000");
                    break;
                }
                else
                {
                    Console.WriteLine("Please enter the Y or N");
                }
            }while (a == 0);


            //if it is out of range then display msg and redo this method
            if ((playerCount < 2) || (playerCount > 8))
            {
                Console.WriteLine("That is an invalid amount. Please try again.");
                this.setUpPlayers();
            }

            //Ask for players names
            for (int i = 0; i < playerCount; i++)
            {
                Console.WriteLine("Please enter the name for Player {0}:", i + 1);
                Console.Write(">");
                string sPlayerName = Console.ReadLine();

                Player player = new Player(sPlayerName, setD);

                //subscribe to events
                player.playerBankrupt += playerBankruptHandler;
                player.playerPassGo   += playerPassGoHandler;
                // 2.7 Extend use of Delegates and Events by adding at least two new Events to the game.
                player.luckyDiceEvent  += playerluckyDiceHanler;
                player.doubleDiceEvent += playerdoubleDiceHandler;
                //add player
                Board.access().addPlayer(player);
                Console.WriteLine("{0} has been added to the game.", Board.access().getPlayer(i).getName());
            }

            Console.WriteLine("Players have been setup");
        }
Пример #17
0
 public string BriefDetailsToString()
 {
     return(String.Format("You are on {0}.\tYou have ${1}.", Board.access().getProperty(this.getLocation()).getName(), this.getBalance()));
 }
Пример #18
0
        public void displayMainChoiceMenu()
        {
            int resp = 0;

            Console.WriteLine("Please make a selection:\n");
            Console.WriteLine("1. Setup Monopoly Game");
            Console.WriteLine("2. Start New Game");
            Console.WriteLine("3. Exit");
            Console.WriteLine("4. Load the former Game progress");
            // 3.2-Serialisation add a method to open Binary File and Deserialize to object
            //use of object serialisation to save and load game from file
            Console.Write("(1-4)>");
            //read response
            resp = inputInteger();
            //if response is invalid redisplay menu
            if (resp == 0)
            {
                this.displayMainChoiceMenu();
            }

            //perform choice according to number input
            try
            {
                switch (resp)
                {
                case 1:
                    this.setUpGame();
                    this.gameSetUp = true;
                    this.displayMainChoiceMenu();
                    break;

                case 2:
                    if (this.gameSetUp)
                    {
                        this.playGame();
                    }
                    else
                    {
                        Console.WriteLine("The Game has not been set up yet.\n");
                        this.displayMainChoiceMenu();
                    }
                    break;

                case 3:
                    Environment.Exit(0);
                    break;

                // 3.2-Serialisation add a method to open Binary File and Deserialize to object
                case 4:
                    WriteRead writeRead = new WriteRead();

                    ArrayList list1 = writeRead.openPropertyBinaryFile();

                    ArrayList list2 = writeRead.openPlayerBinaryFile();

                    Board.access().getProperties().AddRange(list1);
                    Board.access().getPlayers().AddRange(list2);
                    //foreach (Property l in list1)
                    //{
                    //    Board.access().addProperty(l);

                    //}

                    //foreach (Player l in list2)
                    //{
                    //    Board.access().addPlayer(l);
                    //}

                    for (int i = 0; i < list2.Count; i++)
                    {
                        // Console.WriteLine("The Former Player Status:" + );
                        Console.WriteLine("The Former Player Status:\n{0}{1}", playerPrompt(i), Board.access().getPlayer(i).BriefDetailsToString());
                    }
                    Console.ReadLine();
                    this.playGame();
                    break;

                default:
                    throw new ApplicationException("That option is not avaliable. Please try again.");
                }
            }
            catch (ApplicationException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #19
0
 public void testSingleton()
 {
     //Access twice and tests that it is the same object
     Assert.AreSame(Board.access(), Board.access());
 }
Пример #20
0
 public string FullDetailsToString()
 {
     return(String.Format("Player:{0}.\nBalance: ${1}\nLocation: {2} (Square {3}) \nProperties Owned:\n{4}", this.getName(), this.getBalance(), Board.access().getProperty(this.getLocation()), this.getLocation(), this.PropertiesOwnedToString()));
 }