コード例 #1
0
ファイル: Board.cs プロジェクト: bibii1/Monopoly
        public Board(string filename)
        {
            gameBoard = new Case[40];
            StreamReader sr    = new StreamReader(filename);
            string       stock = sr.ReadLine();

            string[] stock2 = new string[11];
            int[]    rents  = new int[6];
            for (int i = 0; i < 40; i++)
            {
                stock  = sr.ReadLine();
                stock2 = stock.Split(';');
                if (stock2[1] == "Ville")
                {
                    for (int j = 0; j < 6; j++)
                    {
                        rents[j] = int.Parse(stock2[j + 5]);
                    }
                    gameBoard[i] = new CityCase(stock2[0], stock2[2], int.Parse(stock2[3]), int.Parse(stock2[4]), rents);
                }
                else
                {
                    if (!stock2[0].Equals("Parc Gratuit"))
                    {
                        gameBoard[i] = new ActionCase(stock2[0], stock2[2]);
                    }
                    else
                    {
                        gameBoard[i] = new FreeParking(stock2[0], stock2[2]);
                    }
                }
            }
            this.dices        = new Dice[2];
            this.dices[0]     = new Dice();
            this.dices[1]     = new Dice();
            this.activePlayer = 0;
            this.state        = "";
            this.myView       = new GameView(this);
            this.myController = new GameController(this);
            this.players      = new List <Player>();
        }
コード例 #2
0
        public void LandOnCity(Player activePlayer, CityCase activeCase)
        {
            List <string> answers = new List <string>();

            answers.Add("Yes");
            answers.Add("No");
            int choix = 0;

            if (activeCase.Owner == null)
            {
                Console.WriteLine("You landed on " + activeCase.Name + ", do you want to buy it ?"
                                  + "\nYour balance is " + activePlayer.Balance + ". Price is " + activeCase.PurchasePrice);
                Texte(0, answers);
                choix = DeplacementFleches(choix, answers, ("You landed on " + activeCase.Name + ", do you want to buy it ?"
                                                            + "\nYour balance is " + activePlayer.Balance + ". Price is " + activeCase.PurchasePrice));
                switch (choix)
                {
                case 1:
                    if (activePlayer.Balance >= activeCase.PurchasePrice)
                    {
                        activeCase.Owner = activePlayer;
                        activePlayer.BuyCase(activeCase);
                        Console.WriteLine("Congratulations, you're the new owner of " + activeCase.Name);
                        myBoard.Notify(myBoard.Players[myBoard.ActivePlayer]);
                        System.Threading.Thread.Sleep(2000);
                        Console.Clear();
                        NextAction();
                    }
                    else
                    {
                        Console.WriteLine("Balance is too low to purchase this case");
                        System.Threading.Thread.Sleep(2000);
                        Console.Clear();
                        NextAction();
                    }
                    break;

                case 2:
                    Console.Clear();
                    NextAction();
                    break;
                }
            }
            else
            {
                if (activeCase.Owner.Name.Equals(activePlayer.Name))
                {
                    Console.WriteLine("You landed on your property.");
                    System.Threading.Thread.Sleep(2000);
                    NextAction();
                }
                else
                {
                    Console.WriteLine("You landed on " + activeCase.Owner.Name + "property.\n You owe him " + activeCase.ActiveRent);
                    System.Threading.Thread.Sleep(2000);
                    activePlayer.Balance     -= activeCase.ActiveRent;
                    activeCase.Owner.Balance += activeCase.ActiveRent;
                    Console.Clear();
                    NextAction();
                }
            }
        }