public string getInformationSnumber(ListSpaces B) { Console.WriteLine("Enter the number of the space whom you want to have information: "); int pos_sp = Convert.ToInt32(Console.ReadLine()); return("This is the space n°" + pos_sp + "\n" + B.getSpace(pos_sp).ToString()); }
public void buyH(ListSpaces B) { Console.WriteLine("\nBuy House/Hotel"); Console.WriteLine("-----------------\n\n"); bool end = false; bool valid = true; string lecture = ""; do { end = false; Console.WriteLine(); Console.WriteLine("1 : Buy a house"); Console.WriteLine("2 : Buy a hotel"); Console.WriteLine("3 : Leave the buy house/hotel option"); do { lecture = ""; valid = true; Console.Write("\n Choose an action : "); lecture = Console.ReadLine(); Console.WriteLine(lecture); if (lecture == "" || !"123".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(); buyHouse(B); break; case '2': Console.Clear(); buyHotel(B); break; case '3': Console.Clear(); Console.WriteLine("You leave this optionnality"); Console.ReadKey(); end = true; break; default: Console.WriteLine("\n Please choose a correct action."); break; } } while (!end); }
public void getInformationS(ListSpaces B) { Console.WriteLine("\nSpaces Informations"); Console.WriteLine("-----------------\n\n"); bool end = false; bool valid = true; string lecture = ""; do { end = false; Console.WriteLine(); Console.WriteLine("1 : Spaces informations by name"); Console.WriteLine("2 : Spaces informations by number"); Console.WriteLine("3 : Leave the spaces information option"); do { lecture = ""; valid = true; Console.Write("\n Choose an action : "); lecture = Console.ReadLine(); Console.WriteLine(lecture); if (lecture == "" || !"123".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(); Console.WriteLine(getInformationSname(B)); break; case '2': Console.Clear(); Console.WriteLine(getInformationSnumber(B)); break; case '3': Console.Clear(); Console.WriteLine("You leave this optionnality"); Console.ReadKey(); end = true; break; default: Console.WriteLine("\n Please choose a correct action."); break; } } while (!end); }
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."); } }
public Player(string nm) { name = nm; account = 1500; position = 0; ListSpaces list_pr = new ListSpaces(); in_prison = false; time_in_prison = 0; banker = false; next = null; }
public void playSpecialSpace(ListSpaces B, ListPlayer P, Queue <SpecialCards> Chance, Queue <SpecialCards> CommunityChest) { SpecialSpace sp = (SpecialSpace)B.getSpace(position); if (sp.go_to_prison) { Console.WriteLine("Go to prison !"); Console.WriteLine("You will not receive your 200 if you pas by the Start"); goToPrison(); } if (sp.tax) { Console.WriteLine("Pay a tax of 100 euros"); SpecialSpace park = (SpecialSpace)B.getSpace(20); park.money_in_parking += 100; account -= 100; Console.WriteLine("The money will go to the Public Parking (position 20)"); Console.WriteLine("The actual amount of money in the parking is : " + park.money_in_parking); } if (sp.luxe_tax) { Console.WriteLine("Pay a tax of 200 euros"); SpecialSpace park = (SpecialSpace)B.getSpace(20); park.money_in_parking += 200; account -= 200; Console.WriteLine("The money will go to the Public Parking (position 20)"); Console.WriteLine("The actual amount of money in the parking is : " + park.money_in_parking); } if (sp.chance) { Console.WriteLine("Press enter to pull a chance card"); Console.ReadLine(); SpecialCards cha = Chance.Dequeue(); Console.WriteLine(cha.SpecialCardAction(this, P, B)); Chance.Enqueue(cha); } if (sp.community_chest) { Console.WriteLine("Press enter to pull a community chest card"); Console.ReadLine(); SpecialCards cc = CommunityChest.Dequeue(); Console.WriteLine(cc.SpecialCardAction(this, P, B)); Chance.Enqueue(cc); } }
public string getInformationSname(ListSpaces B) { Console.WriteLine("Enter the name of the space whom you want to have information: "); string n = Console.ReadLine(); int pos = 0; while (!(B.onList(n, 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'"); n = Console.ReadLine(); if (n == "z") { return(null); } } pos = B.getSpacePosition(n); return("This is the space n°" + pos + "\n" + B.getSpace(pos).ToString()); }
static void Game(ListSpaces l_s, ListPlayer l_p, Player p, int size, Queue <SpecialCards> Chance, Queue <SpecialCards> CommunityChest) { while (p.next != p) { Console.Clear(); Console.WriteLine(p); Console.WriteLine("This is your turn to play !"); if (p.in_prison) { p.outOfPrison(l_s, l_p); } else { p.rollDice(l_s, l_p, Chance, CommunityChest); if (l_s.getSpace(p.position) is SpecialSpace) { p.playSpecialSpace(l_s, l_p, Chance, CommunityChest); } if (p.passByStart(p.position)) { Console.WriteLine("Collect your 200 euros for completing a tour "); p.account += 200; Console.WriteLine("Your account is now : " + p.account); } p.recalculatePosition(); p.makeAction(l_s, l_p); } if (p.bankruptcy()) { Console.WriteLine(p.name + ", you're in bankruptcy, you're out of the game!"); int pos_del = l_p.getPlayerPosition(p, size); l_p.deletePlayer(pos_del); size = size - 1; } p = p.next; } Console.WriteLine("This game is over !"); Console.WriteLine("Bravo " + p.name + " you won this game !"); }
public void outOfPrison(ListSpaces B, ListPlayer P) { Console.WriteLine("You're on prison !"); Console.WriteLine("Press enter to roll dices"); Console.ReadLine(); Random rd = new Random(); int first_dice = rd.Next(1, 7); int second_dice = rd.Next(1, 7); Console.WriteLine("The value of the first dice is : " + first_dice); Console.WriteLine("The value of the second dice is : " + second_dice); if (first_dice == second_dice) { Console.WriteLine("You're out of prison !"); position = position + 2 * first_dice; recalculatePosition(); Console.WriteLine("You are now in the space number : " + position); Console.WriteLine(B.getSpace(position)); Console.WriteLine(" You've turned the dices, make an action."); in_prison = false; time_in_prison = 0; makeAction(B, P); } else { time_in_prison++; if (time_in_prison >= 3) { Console.WriteLine("You're out of prison !"); in_prison = false; time_in_prison = 0; Console.WriteLine("You will play on your next turn."); } else { Console.WriteLine("Sorry, you will still in prison for " + (3 - time_in_prison) + "turns ..."); } } Console.ReadLine(); }
static void Main(string[] args) { // -------------------------Intialization------------------------------------------------------- ListSpaces Board = CreateBoard(); Console.WriteLine("How many players will play this game ? "); Console.WriteLine("Please enter a number : "); int number_players = Convert.ToInt32(Console.ReadLine()); while (number_players < 2) { Console.WriteLine("At least two players needed to start a game ! "); Console.WriteLine("How many players will play this game ? "); Console.WriteLine("Please enter a number : "); number_players = Convert.ToInt32(Console.ReadLine()); } ListPlayer List_of_players = CreatePlayers(number_players); Queue <SpecialCards> cc = CreateChanceQueue(); Queue <SpecialCards> ccc = CreateCommunityChestQueue(); // ---------------------------------------------------------------------------------------------- Game(Board, List_of_players, List_of_players.getPlayer(0), number_players, cc, ccc); Console.ReadLine(); }
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 !"); } } } } }
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); }
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; } } } }
public string rollDice(ListSpaces B, ListPlayer P, Queue <SpecialCards> Chance, Queue <SpecialCards> CommunityChest) { int count = 0; Console.WriteLine("Press enter to roll dices"); Console.ReadLine(); Random rd = new Random(); int first_dice = rd.Next(1, 7); int second_dice = rd.Next(1, 7); Console.WriteLine("The value of the first dice is : " + first_dice); Console.WriteLine("The value of the second dice is : " + second_dice); while (first_dice == second_dice) { count++; if (count == 3) { goToPrison(); return("You're probably cheating, go to prison !"); } position = position + 2 * first_dice; if (passByStart(position)) { Console.WriteLine("Collect your 200 euros for completing a tour "); account += 200; Console.WriteLine("Your account is now : " + account); } recalculatePosition(); Console.WriteLine("You are now in the space number : " + position); Console.WriteLine(B.getSpace(position).name); payRent(B, first_dice + second_dice); if (B.getSpace(position) is SpecialSpace) { playSpecialSpace(B, P, Chance, CommunityChest); } if (passByStart(position)) { Console.WriteLine("Collect your 200 euros for completing a tour "); account += 200; Console.WriteLine("Your account is now : " + account); } recalculatePosition(); makeAction(B, P); Console.WriteLine("You made a double, you can play again !"); Console.WriteLine("Press enter to roll dices again"); Console.ReadLine(); first_dice = rd.Next(1, 7); second_dice = rd.Next(1, 7); Console.WriteLine("The value of the first dice is : " + first_dice); Console.WriteLine("The value of the second dice is : " + second_dice); } int total = first_dice + second_dice; position = position + total; if (passByStart(position)) { Console.WriteLine("Collect your 200 euros for completing a tour "); account += 200; Console.WriteLine("Your account is now : " + account); } recalculatePosition(); payRent(B, total); Console.WriteLine("You are now in the space number : " + position); Console.WriteLine(B.getSpace(position).name); return(" You've turned the dices, make an action."); }
static ListSpaces CreateBoard() { // Creation of the game spaces --------------------------------- //Proprieties Spaces pr1 = new Street("Boulevard de Belleville", 60, "brown", 2, 10, 30, 90, 160, 250); Spaces pr2 = new Street("Rue Lecourbe", 80, "brown", 4, 20, 60, 180, 320, 450); Spaces pr3 = new Street("Rue de Vaugirard", 100, "sky_blue", 6, 30, 90, 270, 400, 550); Spaces pr4 = new Street("Rue de Courcelles", 100, "sky_blue", 6, 30, 90, 270, 400, 550); Spaces pr5 = new Street("Avenue de la Republique", 120, "sky_blue", 8, 40, 100, 300, 450, 600); Spaces pr6 = new Street("Boulevard de la Villette", 140, "pink", 10, 50, 150, 450, 625, 750); Spaces pr7 = new Street("Avenue de Neuilly", 140, "pink", 10, 50, 150, 450, 625, 750); Spaces pr8 = new Street("Rue de Paradis", 160, "pink", 12, 60, 180, 500, 700, 900); Spaces pr9 = new Street("Avenue Mozart", 180, "orange", 14, 70, 200, 550, 750, 950); Spaces pr10 = new Street("Boulevart Saint-Michel", 180, "orange", 14, 70, 200, 550, 750, 950); Spaces pr11 = new Street("Place Pigalle", 200, "orange", 16, 80, 220, 600, 800, 1000); Spaces pr12 = new Street("Avenue Matignon", 220, "red", 18, 90, 250, 700, 875, 1050); Spaces pr13 = new Street("Boulevard Malesherbes", 220, "red", 18, 90, 250, 700, 875, 1050); Spaces pr14 = new Street("Avenue Henri-Martin", 240, "red", 20, 100, 300, 750, 925, 1100); Spaces pr15 = new Street("Faubourg Saint-Honoré", 260, "yellow", 22, 110, 330, 800, 975, 1150); Spaces pr16 = new Street("Place de la Bourse", 260, "yellow", 22, 110, 330, 800, 975, 1150); Spaces pr17 = new Street("Rue de la Fayette", 280, "yellow", 24, 120, 360, 850, 1025, 1200); Spaces pr18 = new Street("Avenue De Breteuil", 300, "green", 26, 130, 390, 900, 1100, 1275); Spaces pr19 = new Street("Avenue de Foch", 300, "green", 26, 130, 390, 900, 1100, 1275); Spaces pr20 = new Street("Boulevard des Capucines", 320, "green", 28, 150, 450, 1000, 1200, 1400); Spaces pr21 = new Street("Avenue des Champs-Elysées", 350, "blue", 35, 175, 500, 1100, 1300, 1500); Spaces pr22 = new Street("Rue de la Paix", 400, "blue", 50, 200, 600, 1400, 1700, 2000); // Train Stations Spaces tr1 = new Station("Gare Montparnasse", 200, 25, 50, 100, 200); Spaces tr2 = new Station("Gare de Lyon", 200, 25, 50, 100, 200); Spaces tr3 = new Station("Gare du Nord", 200, 25, 50, 100, 200); Spaces tr4 = new Station("Gare Saint-Lazare", 200, 25, 50, 100, 200); // Public Service Companies Spaces pc1 = new Company("Electric Company", 150, 0); Spaces pc2 = new Company("Water Works", 150, 0); // Special Spaces Spaces ss1 = new SpecialSpace("Start"); Spaces ss2 = new SpecialSpace("Community"); Spaces ss3 = new SpecialSpace("Tax"); Spaces ss4 = new SpecialSpace("Chance"); Spaces ss5 = new SpecialSpace("PrisonVisit"); Spaces ss6 = new SpecialSpace("Community"); Spaces ss7 = new SpecialSpace("Parking"); Spaces ss8 = new SpecialSpace("Chance"); Spaces ss9 = new SpecialSpace("GtP"); Spaces ss10 = new SpecialSpace("Community"); Spaces ss11 = new SpecialSpace("Chance"); Spaces ss12 = new SpecialSpace("LuxeTax"); // Creation of game board -------------------------------------------- ListSpaces Board = new ListSpaces(ss1); Board.AddTail(pr1); Board.AddTail(ss2); Board.AddTail(pr2); Board.AddTail(ss3); Board.AddTail(tr1); Board.AddTail(pr3); Board.AddTail(ss4); Board.AddTail(pr4); Board.AddTail(pr5); Board.AddTail(ss5); Board.AddTail(pr6); Board.AddTail(pc1); Board.AddTail(pr7); Board.AddTail(pr8); Board.AddTail(tr2); Board.AddTail(pr9); Board.AddTail(ss6); Board.AddTail(pr10); Board.AddTail(pr11); Board.AddTail(ss7); Board.AddTail(pr12); Board.AddTail(ss8); Board.AddTail(pr13); Board.AddTail(pr14); Board.AddTail(tr3); Board.AddTail(pr15); Board.AddTail(pr16); Board.AddTail(pc2); Board.AddTail(pr17); Board.AddTail(ss9); Board.AddTail(pr18); Board.AddTail(pr19); Board.AddTail(ss10); Board.AddTail(pr20); Board.AddTail(tr4); Board.AddTail(ss11); Board.AddTail(pr21); Board.AddTail(ss12); Board.AddTail(pr22); pr22.next = ss1; return(Board); }
public ListSpacesIterator(ListSpaces l) { list = l; current_space_idx = -1; }