Exemple #1
0
 public void buySpace(ListSpaces B, ListPlayer P)
 {
     if (B.getSpace(position) is Propriety)
     {
         Propriety prop = (Propriety)B.getSpace(position);
         if (prop.possessed)
         {
             Console.WriteLine("This propriety is already possessed by " + prop.pl.name + ", you can't buy it.");
         }
         else
         {
             Console.WriteLine("Do you want to buy this propriety ? ");
             Console.WriteLine("Press 1 for yes or 0 for no. ");
             int resp = Convert.ToInt32(Console.ReadLine());
             while (resp != 0 && resp != 1)
             {
                 Console.WriteLine("Please enter a correct awnser.");
                 Console.WriteLine("Press 1 for yes or 0 for no. ");
                 resp = Convert.ToInt32(Console.ReadLine());
             }
             if (resp == 1)
             {
                 int pri = prop.price;
                 if (account > prop.price)
                 {
                     prop.possessed = true;
                     prop.pl        = this;
                     account        = account - prop.price;
                     B.changeSpace(position, prop);
                     if (list_pr == null)
                     {
                         prop      = (Propriety)B.getSpace(position).Shallowcopy();
                         prop.next = null;
                         list_pr   = new ListSpaces(prop);
                     }
                     else
                     {
                         prop      = (Propriety)B.getSpace(position).Shallowcopy();
                         prop.next = null;
                         list_pr.AddTail(prop);
                     }
                     Console.WriteLine("You have acquired " + prop.name);
                 }
                 else
                 {
                     Console.WriteLine("You don't have enough money in your bank account to buy this propriety ! ");
                 }
             }
         }
     }
     else
     {
         Console.WriteLine("You can't buy this space, this is not a propriety.");
     }
 }
Exemple #2
0
 public void buyHotel(ListSpaces B)
 {
     if (list_pr == null)
     {
         Console.WriteLine("You don't owe any propriety, you can't buy a hotel !");
     }
     else
     {
         Console.WriteLine("Enter the name of the street where you want to buy a hotel :");
         string prop_name = Console.ReadLine();
         while (!(B.onList(prop_name, 40)))
         {
             Console.WriteLine("This propriety is not in the game board !");
             Console.WriteLine("Please write the space name correctly.");
             Console.WriteLine("If you want to leave, press 'z'");
             prop_name = Console.ReadLine();
             if (prop_name == "z")
             {
                 break;
             }
         }
         if ((B.onList(prop_name, 40)))
         {
             while (!(list_pr.onList(prop_name, list_pr.Size)))
             {
                 Console.WriteLine("You don't possess this propriety !");
                 Console.WriteLine("Your proprieties are " + list_pr);
                 Console.WriteLine("Please write the propriety name correctly.");
                 Console.WriteLine("If you want to leave, press 'z'");
                 prop_name = Console.ReadLine();
                 if (prop_name == "z")
                 {
                     break;
                 }
                 while (!(B.onList(prop_name, 40)))
                 {
                     Console.WriteLine("This propriety is not in the game board !");
                     Console.WriteLine("Please write the space name correctly.");
                     Console.WriteLine("If you want to leave, press 'z'");
                     prop_name = Console.ReadLine();
                     if (prop_name == "z")
                     {
                         break;
                     }
                 }
             }
             if ((B.onList(prop_name, 40)) && (list_pr.onList(prop_name, list_pr.Size)))
             {
                 Propriety test = (Propriety)B.getSpace(B.getSpacePosition(prop_name));
                 if (test is Street)
                 {
                     Street test1 = (Street)B.getSpace(B.getSpacePosition(prop_name));
                     if (test1.house != 4)
                     {
                         Console.WriteLine("This street already doesn't have 4 houses, you can't buy a hotel !");
                     }
                     else
                     {
                         if (test1.hotel == 1)
                         {
                             Console.WriteLine("This street already have 1 hotel, you can't buy another one !");
                         }
                         else
                         {
                             Console.WriteLine("Do you want to buy a hotel in this propriety : " + test1.name + " ?");
                             Console.WriteLine("The price of a hotel is " + test1.hprice());
                             Console.WriteLine("Press 1 for yes 0 for no");
                             int resp = Convert.ToInt32(Console.ReadLine());
                             while (resp != 0 && resp != 1)
                             {
                                 Console.WriteLine("Please enter a correct awnser.");
                                 Console.WriteLine("Press 1 for yes or 0 for no. ");
                                 resp = Convert.ToInt32(Console.ReadLine());
                             }
                             if (resp == 1)
                             {
                                 if (account >= test1.hprice())
                                 {
                                     account = account - test1.hprice();
                                     test1.hotel++;
                                     B.changeSpace(B.getSpacePosition(prop_name), test1);
                                 }
                                 else
                                 {
                                     Console.WriteLine("You don't have enough money to buy this hotel !");
                                 }
                             }
                         }
                     }
                 }
                 else
                 {
                     Console.WriteLine("You can't put a hotel in this propriety, this isn't a street !");
                 }
             }
         }
     }
 }
Exemple #3
0
        public void makeAction(ListSpaces B, ListPlayer P)
        {
            bool   fin     = false;
            bool   valid   = true;
            string lecture = "";

            do
            {
                Console.WriteLine("\nPlayer Action");
                Console.WriteLine("\n Turn of " + name);
                Console.WriteLine("-----------------\n\n");
                fin = false;
                Console.WriteLine();
                Console.WriteLine("1 : Buy this propiety");
                Console.WriteLine("2 : Buy a house or an hotel");
                Console.WriteLine("3 : Get informations");
                Console.WriteLine("4 : Pass your turn");

                do
                {
                    lecture = "";
                    valid   = true;

                    Console.Write("\n Choose an action : ");
                    lecture = Console.ReadLine();
                    Console.WriteLine(lecture);
                    if (lecture == "" || !"1234".Contains(lecture[0]))
                    {
                        Console.WriteLine("Your choice <" + lecture + "> is not valid = > Please choose a correct action. ");
                        valid = false;
                    }
                } while (!valid);


                switch (lecture[0])
                {
                case '1':
                    Console.Clear();
                    buySpace(B, P);
                    break;

                case '2':
                    Console.Clear();
                    buyH(B);
                    break;

                case '3':
                    Console.Clear();
                    getInformation(B, P);
                    break;

                case '4':
                    Console.Clear();
                    Console.WriteLine("You pass your turn");
                    if (B.getSpace(position) is Propriety)
                    {
                        Propriety prop = (Propriety)B.getSpace(position);
                        if (!(prop.possessed))
                        {
                            Console.WriteLine("This propriety will be auctionned");
                            Player pla = prop.auction(P);
                            prop.possessed = true;
                            prop.pl        = pla;
                            B.changeSpace(position, prop);
                            if (pla.list_pr == null)
                            {
                                prop        = (Propriety)B.getSpace(position).Shallowcopy();
                                prop.next   = null;
                                pla.list_pr = new ListSpaces(prop);
                            }
                            else
                            {
                                prop      = (Propriety)B.getSpace(position).Shallowcopy();
                                prop.next = null;
                                pla.list_pr.AddTail(prop);
                            }
                        }
                    }
                    Console.ReadKey();
                    fin = true;
                    break;

                default:
                    Console.WriteLine("\n Please choose a correct action.");
                    break;
                }
            } while (!fin);
        }
Exemple #4
0
 public void payRent(ListSpaces B, int dices)
 {
     if (B.getSpace(position) is Propriety)
     {
         Propriety prop = (Propriety)B.getSpace(position);
         if (prop.possessed)
         {
             if (prop.pl == this)
             {
                 Console.WriteLine("This is your propriety, you're at home.");
             }
             else
             {
                 Console.WriteLine("This propriety is owned by " + prop.pl.name + ". You have to pay a rent !");
                 int money = 0;
                 if (prop is Company)
                 {
                     Company comp      = (Company)prop;
                     int     n_of_comp = comp.pl.list_pr.number_of_companies();
                     if (n_of_comp == 1)
                     {
                         money = 4 * dices;
                     }
                     else
                     {
                         money = 10 * dices;
                     }
                 }
                 if (prop is Station)
                 {
                     Station stat      = (Station)prop;
                     int     n_of_stat = stat.pl.list_pr.number_of_stations();
                     if (n_of_stat == 1)
                     {
                         money = stat.rent;
                     }
                     if (n_of_stat == 2)
                     {
                         money = stat.rent2stations;
                     }
                     if (n_of_stat == 3)
                     {
                         money = stat.rent3stations;
                     }
                     if (n_of_stat == 4)
                     {
                         money = stat.rent4stations;
                     }
                 }
                 if (prop is Street)
                 {
                     Street st = (Street)prop;
                     if (st.pl.list_pr.allColors(st.color))
                     {
                         money = st.rent * 2;
                         if (st.house == 1)
                         {
                             money = st.rent1house;
                         }
                         if (st.house == 2)
                         {
                             money = st.rent2house;
                         }
                         if (st.house == 3)
                         {
                             money = st.rent3house;
                         }
                         if (st.house == 4)
                         {
                             money = st.rent4house;
                             if (st.hotel == 1)
                             {
                                 money = st.renthotel;
                             }
                         }
                     }
                     else
                     {
                         money = st.rent;
                     }
                 }
                 Console.WriteLine("You have to pay " + money + " euros to " + prop.pl.name);
                 account          = account - money;
                 prop.pl.account += money;
             }
         }
     }
 }