Пример #1
0
        public void GoToJail()
        {
            Street tmpBoard = this.Position;


            while (!tmpBoard.Name.Equals("Prison"))
            {
                tmpBoard      = tmpBoard.next;
                this.Position = this.Position.next;
            }

            if (this.Position.ID > 11)
            {
                /*
                 * When the player go to Jail, if he goes through the start box
                 * he'l win 200 € nut he shouldn't according to the rules 
                 */
                this.Money -= 200;
            }
        }
Пример #2
0
        public static void CheckBoard(bool verbose = false)
        {
            /*
             *  This function is unit test for the previous function "CreateBoard".
             *  It check if the ringed linked list is well created.
             *  It makes two rounds of the list and check if each next id is an increment
             *  by one of the previous one except for the id 1 where the previous id is 40.
             */
            Street first  = Game.CreateBoard();
            Street actual = first;

            int  cpt    = 0;
            bool result = true;

            while (cpt != 2)
            {
                if (cpt == 0 && verbose)
                {
                    Console.WriteLine(actual.toString());
                }
                if (actual.ID == 40)
                {
                    cpt++;
                    if (actual.next.ID != 1)
                    {
                        result = false;
                    }
                }
                else
                {
                    if (actual.ID != actual.next.ID - 1)
                    {
                        result = false;
                    }
                }
                actual = actual.next;
            }
            displayResult("Board", result);
        }
Пример #3
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
                }
            }
        }
Пример #4
0
        public static Player PayRent(Player pl, int idOwner, String type, int numberDice = 0)
        {
            int amount = 0;
            int idPl   = pl.ID;

            if (type.Equals("Street"))
            {
                if (!pl.Position.Hotel)
                {
                    amount = pl.Position.PriceRentHouse[pl.Position.Nb_house];
                }
                else
                {
                    amount = pl.Position.PriceRentHotel;
                }
            }
            else if (type.Equals("Train"))
            {
                Street tmpBoard       = pl.Position;
                int    nbTrainStation = 1;
                int    id_start       = tmpBoard.ID;

                do
                {
                    // We search all the train stations the owner has
                    if (tmpBoard.Name.Substring(0, 4).Equals("Gare") && tmpBoard.Id_buyer == idOwner)
                    {
                        nbTrainStation++;
                    }
                    tmpBoard = tmpBoard.next;
                }while (tmpBoard.ID != id_start);

                switch (nbTrainStation)
                {
                case 1:
                    amount = 25;
                    break;

                case 2:
                    amount = 50;
                    break;

                case 3:
                    amount = 100;
                    break;

                case 4:
                    amount = 200;
                    break;
                }
            }
            else if (type.Equals("Company"))
            {
                Street tmpBoard        = pl.Position;
                int    nbPublicCompany = 1;
                int    id_start        = tmpBoard.ID;

                while (tmpBoard.next.ID != id_start)
                {
                    // We search all the train stations the owner has
                    if (tmpBoard.Name.Substring(0, 4).Equals("Compagnie") && tmpBoard.Id_buyer == idOwner)
                    {
                        nbPublicCompany++;
                    }
                    tmpBoard = tmpBoard.next;
                }

                if (nbPublicCompany == 1)
                {
                    amount = 4 * numberDice;
                }
                else
                {
                    amount = 10 * numberDice;
                }

                //Console.WriteLine("The amount of the rent is: "+amount+"€");
            }

            pl.Money -= amount;
            while (pl.ID != idOwner)
            {
                pl = pl.next;
            }

            pl.Money += amount;
            while (pl.ID != idPl)
            {
                pl = pl.next;
            }

            return(pl);
        }
Пример #5
0
        public static Street CreateBoard()
        {
            /*
             * This method build the game with all the boxes according to the classes Case, Buyable, Street
             * The output is a ringed linked list
             */
            Street first = null;

            try
            {
                String[] lines = File.ReadAllLines(@"data_cases.txt");

                Street actual = null;
                for (int id_line = 0; id_line < lines.Length; id_line++)
                {
                    String line = lines[id_line];
                    // Is it the last line of data_case.txt which is the resource link?
                    if (!line[0].Equals('#'))
                    {
                        String[] data = line.Split(",");
                        // Is it the first line of data_case.txt which describe the data below

                        if (!data[0].Equals("id"))
                        {
                            int    id   = Convert.ToInt32(data[0]);
                            Street temp = null;
                            switch (data.Length)
                            {
                            case 2:
                                if (id == 0)
                                {
                                    temp  = CaseFactory.getCase("Case", id + 1, data[1]);
                                    first = actual = temp;
                                    // This section is to set the beginning of the ringed chained list
                                }
                                else
                                {
                                    temp = CaseFactory.getCase("Case", id + 1, data[1]);
                                    // Structure: type, id, name
                                }
                                break;

                            case 3:
                                temp = CaseFactory.getCase("Buyable", id + 1, data[1], 0, Convert.ToInt32(data[2]));
                                // Structure: type, id, name, id_buyer, basic_price
                                break;

                            case 12:
                                List <int> price_house = new List <int>();
                                for (int i = 4; i < 9; i++)
                                {
                                    price_house.Add(Convert.ToInt32(data[i]));
                                }
                                temp = CaseFactory.getCase("Street", id + 1, data[1], 0, Convert.ToInt32(data[2]), data[3], price_house, Convert.ToInt32(data[9]), Convert.ToInt32(data[10]), Convert.ToInt32(data[11]));
                                // Structure: type, id, name, id_buyer, basic_price, price_house, price_hotel
                                break;
                            }
                            actual.next = temp;
                            actual      = actual.next;
                        }
                    }
                }
                actual.next = first;
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
            return(first);
        }
Пример #6
0
 public Game()
 {
     this.jackpot = 0;
     this.board   = CreateBoard();
     this.players = getPlayers();
 }