Example #1
0
        public static void Action(Player pl, int numberDice)
        {
            Player actualPlayer   = pl; // Peut être deep copy à faire
            Street actualPosition = actualPlayer.Position;


            if (actualPosition.Basic_price != -1)
            {
                if (actualPosition.Name.Substring(0, 6).Equals("Impôts") || actualPosition.Name.Substring(0, 4).Equals("Taxe"))
                {
                    actualPlayer.Money -= actualPosition.Basic_price;
                }
                else
                {
                    // If the player can buy this box
                    if (!actualPlayer.FirstRound)
                    {
                        // The player cannot buy on the first round
                        if (actualPosition.Id_buyer == 0)
                        {
                            char action = 'a';
                            while (!action.Equals('y') && !action.Equals('Y') && !action.Equals('n') && !action.Equals('N'))
                            {
                                Console.Write("Do you want to buy this property? [y/n]");
                                String input = Console.ReadLine();
                                if (input.Length == 1)
                                {
                                    action = Convert.ToChar(input);
                                }
                                // If id_buyer = 0, nobody own this box
                            }

                            if (action.Equals('y') || action.Equals('Y'))
                            {
                                actualPlayer.Buy();
                            }
                        }
                        else
                        {
                            if (actualPosition.Id_buyer == actualPlayer.ID)
                            {
                                // If the actual player bought thi box before
                                if (!actualPosition.Name.Substring(0, 4).Equals("Gare") &&   !actualPosition.Name.Substring(0, 6).Equals("Impôts") && !actualPosition.Name.Substring(0, 4).Equals("Taxe") && !actualPosition.Name.Substring(0, 9).Equals("Compagnie"))
                                {
                                    char actionAdd = 'a';
                                    while (!actionAdd.Equals('y') && !actionAdd.Equals('Y') && !actionAdd.Equals('n') && !actionAdd.Equals('N'))
                                    {
                                        Console.Write("Do you want to add an element (house, hotel)? [y/n]");
                                        String input = Console.ReadLine();
                                        if (input.Length == 1)
                                        {
                                            actionAdd = Convert.ToChar(input);
                                        }
                                    }

                                    if (actionAdd.Equals('y') ||  actionAdd.Equals('Y'))
                                    {
                                        int answer = -1;
                                        while (answer != 0 && answer != 1 && answer != 2)
                                        {
                                            Console.WriteLine("n0 - Continue\n1 - Add House\n2 - Replace by Hotel");
                                            Console.WriteLine(">>> ");
                                        }
                                        answer = Convert.ToInt32(Console.ReadLine());
                                        switch (answer)
                                        {
                                        case 0:
                                            break;

                                        case 1:
                                            actualPlayer.AddHouse();
                                            Console.WriteLine("House added on " + actualPlayer.Position.Name);
                                            break;

                                        case 2:
                                            actualPlayer.AddHotel();
                                            Console.WriteLine("Hotel added on " + actualPlayer.Position.Name);
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (actualPosition.Nb_house != -1)
                                {
                                    actualPlayer = PayRent(actualPlayer, actualPlayer.Position.Id_buyer, "Street");
                                }
                                else
                                {
                                    if (actualPosition.Name.Substring(0, 4).Equals("Gare"))
                                    {
                                        actualPlayer = PayRent(actualPlayer, actualPlayer.Position.Id_buyer, "Train");
                                    }
                                    else if (actualPosition.Name.Substring(0, 9).Equals("Compagnie"))
                                    {
                                        actualPlayer = PayRent(actualPlayer, actualPlayer.Position.Id_buyer, "Company", numberDice);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (actualPosition.Name.Equals("Caisse de communauté"))
                {
                    actualPlayer.Card("community");
                }
                else if (actualPosition.Name.Equals("Chance"))
                {
                    actualPlayer.Card("chance");
                }
                else if (actualPosition.Name.Equals("Allez en Prison"))
                {
                    actualPlayer.GoToJail();
                    actualPlayer.InJail = true;
                }
                else if (actualPosition.Name.Equals("Parc Gratuit"))
                {
                    // Gratuit
                }
            }
        }