//3.1-Load game initial set up from file.
 static public decimal getPlayerStartingBalance(bool setD)
 {
     if (setD == true)
     {
         return(2000);
     }
     else
     {
         //read money from the "InitialMoney.txt" File
         WriteRead reader  = new WriteRead();
         decimal   InMoney = decimal.Parse(reader.Read());
         return(InMoney);
     }
     //3.1-Load game initial set up from file.
     //  WriteRead reader = new WriteRead();
     //decimal InMoney = decimal.Parse(reader.Read());
     // return InMoney;
 }
Beispiel #2
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;
            }
        }
Beispiel #3
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");
        }
Beispiel #4
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);
            }
        }