예제 #1
0
        public static void doTurn(Player p)
        {
            Console.WriteLine("--------------------------------");
            Console.WriteLine(p.ShowName());
            Console.WriteLine("");
            if (p.getMonopolies().Count != 0)
            {
                bool checkForHouses = true;
                while (checkForHouses)
                {
                    Console.WriteLine("Would you like to buy a house?");
                    string houseAnswer = Console.ReadLine();
                    switch (houseAnswer)
                    {
                    case "no":
                    case "NO":
                    case "No":
                    case "n":
                    case "N":
                        checkForHouses = false;
                        break;

                    case "yes":
                    case "YES":
                    case "Yes":
                    case "y":
                    case "Y":
                        bool checkForMonopolyColor = true;
                        while (checkForMonopolyColor)
                        {
                            Console.WriteLine("Which monopoly would you like to buy a house on?");
                            foreach (string color in p.getMonopolies())
                            {
                                Console.WriteLine(color);
                            }
                            string colorAnswer = Console.ReadLine();
                            foreach (string color in p.getMonopolies())
                            {
                                if (colorAnswer == color)
                                {
                                    checkForMonopolyColor = false;
                                    bool propertyAnswerCheck = true;
                                    while (propertyAnswerCheck)
                                    {
                                        Console.WriteLine("Which property would you like to buy a house on?");
                                        foreach (Space s in Spaces)
                                        {
                                            if (s.GetColor() == color)
                                            {
                                                Console.WriteLine(s.getName());
                                            }
                                        }
                                        string propertyAnswer = Console.ReadLine();
                                        foreach (string name in p.getProperties())
                                        {
                                            if (propertyAnswer == name)
                                            {
                                                propertyAnswerCheck = false;
                                                p.BuyHouse();
                                                foreach (Space s in Spaces)
                                                {
                                                    if (s.getName() == propertyAnswer)
                                                    {
                                                        s.addHouse();
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    }
                    // if (houseAnswer == "no")
                    // {
                    //     checkForHouses = false;
                    // }
                    // else if (houseAnswer == "yes")
                    // {
                    //     bool checkForMonopolyColor = true;
                    //     while (checkForMonopolyColor)
                    //     {
                    //         Console.WriteLine("Which monopoly would you like to buy a house on?");
                    //         foreach (string color in p.getMonopolies())
                    //         {
                    //             Console.WriteLine(color);
                    //         }
                    //         string colorAnswer = Console.ReadLine();
                    //         foreach (string color in p.getMonopolies())
                    //         {
                    //             if (colorAnswer == color)
                    //             {
                    //                 checkForMonopolyColor = false;
                    //                 bool propertyAnswerCheck = true;
                    //                 while (propertyAnswerCheck)
                    //                 {
                    //                     Console.WriteLine("Which property would you like to buy a house on?");
                    //                     foreach (Space s in Spaces)
                    //                     {
                    //                         if (s.GetColor() == color)
                    //                         {
                    //                             Console.WriteLine(s.getName());
                    //                         }
                    //                     }
                    //                     string propertyAnswer = Console.ReadLine();
                    //                     foreach (string name in p.getProperties())
                    //                     {
                    //                         if (propertyAnswer == name)
                    //                         {
                    //                             propertyAnswerCheck = false;
                    //                             p.BuyHouse();
                    //                             foreach (Space s in Spaces)
                    //                             {
                    //                                 if (s.getName() == propertyAnswer)
                    //                                 {
                    //                                     s.addHouse();
                    //                                 }
                    //                             }
                    //                         }
                    //                     }
                    //                 }
                    //             }
                    //         }
                    //     }
                    // }
                }
            }
            p.RollDice();
            int    test = p.getPosition();
            string potentialNewOwner = "blank";

            foreach (Space s in Spaces)
            {
                if (test == s.getPosition())
                {
                    s.showData();
                    if ((s.getType() == "Property" || s.getType() == "Utility") && s.CheckOwned() == false)
                    {
                        bool insideProperty = true;
                        while (insideProperty)
                        {
                            Console.WriteLine("***********************");
                            Console.WriteLine("Do you want to buy this? yes or no");
                            string userInput = Console.ReadLine();
                            // if(userInput == "yes"){
                            //     p.BuySpace(s.getName(), s.getPrice());
                            //     s.updateOwner(p.ShowName());
                            //     insideProperty = false;
                            // }else if(userInput == "no"){
                            //     insideProperty = false;
                            // }
                            switch (userInput)
                            {
                            case "yes":
                            case "YES":
                            case "Yes":
                            case "y":
                            case "Y":
                                p.BuySpace(s.getName(), s.getPrice());
                                s.updateOwner(p.ShowName());
                                insideProperty = false;
                                break;

                            case "no":
                            case "NO":
                            case "No":
                            case "n":
                            case "N":
                                insideProperty = false;
                                break;
                            }
                            CheckForMonopoly(s, p);
                        }
                    }
                    else if ((s.getType() == "Property" || s.getType() == "Utility") && s.CheckOwned() == true)
                    {
                        p.PayRent(s.getRent());
                        string PlayerName = s.getOwner();
                        foreach (Player p1 in Players)
                        {
                            if (PlayerName == p1.ShowName())
                            {
                                p1.getRent(s.getRent());
                            }
                        }
                    }
                    else if (s.getType() == "OtherSpace")
                    {
                        s.performAction(p);
                    }
                }
                potentialNewOwner = s.getOwner();
            }
            if (p.getPlyrMoney() <= 0)
            {
                foreach (Player p1 in Players)
                {
                    if (p1.ShowName() == potentialNewOwner)
                    {
                        p1.receiveProperty(p.transferOwner());
                    }
                }

                Players.Remove(p);
            }
        }