/* Monopoly program May 8, 2003 */ #include #include #include #include #include #include #include struct player { String name; char symb; int money; int n; //position char j; //jail status }; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ struct character { String name; char first; char t; //taken? }; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void initialize(matrix &propname, matrix &propval, ector &piece, vector &p, int num, int cnum, matrix &prop, matrix &house) { //initialize board // Up left column propname[0][7]="Go"; propval[0][7]=0; propname[0][6]="Cockbill Street"; propval[0][6]=60; propname[0][5]="The Shades"; propval[0][5]=60; propname[0][4]="Rogers the Bulls"; propval[0][4]=0; propname[0][3]="The Bucket"; propval[0][3]=100; propname[0][2]="Biers"; propval[0][2]=100; propname[0][1]="Mended Drum"; propval[0][1]=100; // Across top column propname[0][0]="The Ankh"; propval[0][0]=0; propname[1][0]="Gatehouse"; propval[1][0]=150; propname[2][0]="Cable Street"; propval[2][0]=150; propname[3][0]="Random Watch House"; propval[3][0]=150; propname[4][0]="Granny's Broom"; propval[4][0]=0; propname[5][0]="Baker Street"; propval[5][0]=200; propname[6][0]="Pseudopolis Yard"; propval[6][0]=200; // Down right column propname[7][0]="City Square"; propval[7][0]=0; propname[7][1]="Beggars' Guild"; propval[7][1]=250; propname[7][2]="Fools' Guild"; propval[7][2]=250; propname[7][3]="The Magpyr Carriage"; propval[7][3]=0; propname[7][4]="Alchemists' Guild"; propval[7][4]=300; propname[7][5]="Thieves' Guild"; propval[7][5]=300; propname[7][6]="Assassins' Guild"; propval[7][6]=300; // Across top column propname[7][7]="Fell in the Ankh!"; propval[7][7]=0; propname[6][7]="Heraldry place"; propval[6][7]=350; propname[5][7]="Unseen University"; propval[5][7]=350; propname[4][7]="Sunshine Sanctuary"; propval[4][7]=350; propname[3][7]="Binkie"; propval[3][7]=0; propname[2][7]="Vetinari's Palace"; propval[2][7]=400; propname[1][7]="Cori Celesti"; propval[1][7]=400; // Set owners for (int x=0; x<8; x++) for (int y=0; y<8; y++) prop[x][y]=-1; // Set houses for (int x=0; x<8; x++) for (int y=0; y<8; y++) house[x][y]=0; //initialize characters piece[0].name="Rincewind"; piece[0].first='R'; piece[0].t='n'; piece[1].name="The Librarian"; piece[1].first='L'; piece[1].t='n'; piece[2].name="Vimes"; piece[2].first='V'; piece[2].t='n'; piece[3].name="Death"; piece[3].first='D'; piece[3].t='n'; piece[4].name="Quoth"; piece[4].first='Q'; piece[4].t='n'; piece[5].name="Angua"; piece[5].first='A'; piece[5].t='n'; //initialize players int j=0; for (int i=0; i> cnum; if ((cnum>0)&&(cnum<7)&&(piece[cnum-1].t=='n')) { p[i].name=piece[cnum-1].name; p[i].symb=piece[cnum-1].first; p[i].j='n'; piece[cnum-1].t='y'; } else if (piece[cnum-1].t='y') cout << "This character is taken." <> num; clrscr(); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void display(int i, vector p) { int x, y; cout << " _______________________________________\n"; cout << " | | | | | | | | |\n"; cout << " |___7|__8_|__9_|_10_|_11_|_12_|_13_|14__|\n"; cout << " | 6| |15 |\n"; cout << " |____| |____|\n"; cout << " | 5| |16 |\n"; cout << " |____| |____|\n"; cout << " | 4| |17 |\n"; cout << " |____| ANKH- |____|\n"; cout << " | 3| MORPORK |18 |\n"; cout << " |____| |____|\n"; cout << " | 2| |19 |\n"; cout << " |____| |____|\n"; cout << " | 1| |20 |\n"; cout << " |____|_____________________________|____|\n"; cout << " | 0| 27 | 26 | 25 | 24 | 23 | 22 |21 |\n"; cout << " |____|____|____|____|____|____|____|____|\n"; convert(p[i].n, x, y); if ((p[i].n>-1)&&(p[i].n<7)) gotoxy(6, 2*y+2); else if ((p[i].n>6)&&(p[i].n<15)) gotoxy(5*x+6, 2); else if ((p[i].n>14, p[i].n<22)) gotoxy(42, 2*y+3); else gotoxy(5*x+6, 17); cout << p[i].symb; gotoxy(0, 20); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void move(int i, int d, vector &x) { if (x[i].n+d<28) x[i].n+=d; else { x[i].money+=200; x[i].n=d-28+x[i].n; } } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bool checkhouse(int x, int y, int i, matrix prop) { if (x==0) { if ((y==6)||(y==5)) { if ((prop[0][6]==i)&&(prop[0][5]==i)) { return(true); } else return(false); } else if ((y==3)||(y==2)||(y==1)) { if ((prop[0][3]==i)&&(prop[0][2]==i)&&(prop[0][1]==i)) { return(true); } else return(false); } } else if (x==7) { if ((y==1)||(y==2)) { if ((prop[7][1]==i)&&(prop[7][2]==i)) { return(true); } else return(false); } else if ((y==4)||(y==5)||(y==6)) { if ((prop[7][4]==i)&&(prop[7][5]==i)&&(prop[7][6]==i)) { return(true); } else return(false); } } else if (y==0) { if ((x==5)||(x==6)) { if ((prop[5][0]==i)&&(prop[6][0]==i)) { return(true); } else return(false); } else if ((x==3)||(x==2)||(x==1)) { if ((prop[3][0]==i)&&(prop[2][0]==i)&&(prop[1][0]==i)) { return(true); } else return(false); } } else if (y==7) { if ((x==1)||(x==2)) { if ((prop[1][7]==i)&&(prop[2][7]==i)) { return(true); } else return(false); } else if ((x==6)||(x==4)||(x==5)) { if ((prop[6][7]==i)&&(prop[4][7]==i)&&(prop[5][7]==i)) { return(true); } else return(false); } } else { return(false); } } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bool propcheck(matrix prop, int i) { for (int x=0; x<8; x++) for (int y=0; y<8; y++) if (prop[x][y]==i) return false; return true; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void options(vector &p, int i, char &act, matrix &house, matrix &prop, matrix propname, matrix propval, int num) { int x, y, B=0, d1, d2; convert(p[i].n, x, y); //Fell in the Ankh if (p[i].n==21) { cout << propname[x][y] <> act; if (act=='S') { int sell; cout << "Which property would you like to sell?\n"; cin >> sell; convert(sell, x, y); if (prop[x][y]!=i) cout << "You do not own this property.\n"; else { String sellp; cout << "Who would you like to sell this property to?\n"; cout << "(turn caps lock off and type full name)\n"; cin >> sellp; cout << endl <> act; if (act=='Y') { prop[x][y]==j; p[j].money-=propval[x][y]; p[i].money+=propval[x][y]; } } } } else if (act=='T') { String tradep; cout << "Who would you like to trade with?\n"; cout << "(turn caps lock off and type full name)\n"; cin >> tradep; clrsrc(); display(i, p); cout << p[i].name << ", you own the following properties: "; for (int x=0; x<8; x++) { for (int y=0; y<8; y++) { if (prop[x][y]==i) { cout << rconvert(x,y) << " - " << propname[x][y] << " ($" << propval[x][y] << ")" << endl; } } } int j; for (int a=0; a<6; a++) if (p[j].name==tradep) j=a; cout << tradep << " owns the following properties: "; for (int x=0; x<8; x++) { for (int y=0; y<8; y++) { if (prop[x][y]==j) { cout << rconvert(x,y) << " - " << propname[x][y] << " ($" << propval[x][y] << ")" << endl; } } } int traden; cout << endl << "How many of your properties would you like to trade?\n"; cin >> traden; vector trade1(traden); for (int b=0; b> trade1[b]; } clrsrc(); display(i, p); cout << p[i].name << ", you own the following properties: "; for (int x=0; x<8; x++) { for (int y=0; y<8; y++) { if (prop[x][y]==i) { cout << rconvert(x,y) << " - " << propname[x][y] << " ($" << propval[x][y] << ")" << endl; } } } cout << tradep << " owns the following properties: "; for (int x=0; x<8; x++) { for (int y=0; y<8; y++) { if (prop[x][y]==j) { cout << rconvert(x,y) << " - " << propname[x][y] << " ($" << propval[x][y] << ")" << endl; } } } int traden2; cout << endl << "How many properties would you like to receive in the trade?\n"; cin >> traden2; vector trade2(traden); for (int b=0; b> trade2[b]; } clrsrc(); display(i, p); cout << p[j].name << ", you own the following properties: "; for (int x=0; x<8; x++) { for (int y=0; y<8; y++) { if (prop[x][y]==j) { cout << rconvert(x,y) << " - " << propname[x][y] << " ($" << propval[x][y] << ")" << endl; } } } cout << p[i].name << " owns the following properties: "; for (int x=0; x<8; x++) { for (int y=0; y<8; y++) { if (prop[x][y]==i) { cout << rconvert(x,y) << " - " << propname[x][y] << " ($" << propval[x][y] << ")" << endl; } } } cout << p[i].n << " would like to trade the following properties: \n"; for (int b=0; b> trade2[b]; cout << "\nDo you agree to this trade (Y/N/P to propose new trade)? "; cin >> act; if (act=='Y') { int x1, y1; for(int b=0; b> traden; vector trade3(traden); for (int b=0; b> trade3[b]; } clrsrc(); display(i, p); cout << p[j].name << ", you own the following properties: "; for (int x=0; x<8; x++) { for (int y=0; y<8; y++) { if (prop[x][y]==j) { cout << rconvert(x,y) << " - " << propname[x][y] << " ($" << propval[x][y] << ")" << endl; } } } cout << p[i].name << " owns the following properties: "; for (int x=0; x<8; x++) { for (int y=0; y<8; y++) { if (prop[x][y]==i) { cout << rconvert(x,y) << " - " << propname[x][y] << " ($" << propval[x][y] << ")" << endl; } } } cout << endl << p[j].name << ", how many properties would you like to receive in the trade?\n"; cin >> traden2; vector trade4(traden); for (int b=0; b> trade4[b]; } clrsrc(); display(i, p); cout << p[i].name << ", you own the following properties: "; for (int x=0; x<8; x++) { for (int y=0; y<8; y++) { if (prop[x][y]==i) { cout << rconvert(x,y) << " - " << propname[x][y] << " ($" << propval[x][y] << ")" << endl; } } } cout << p[j].name << " owns the following properties: "; for (int x=0; x<8; x++) { for (int y=0; y<8; y++) { if (prop[x][y]==j) { cout << rconvert(x,y) << " - " << propname[x][y] << " ($" << propval[x][y] << ")" << endl; } } } cout << p[j].n << " would like to trade the following properties: \n"; for (int b=0; b> trade4[b]; cout << "\nDo you agree to this trade? "; cin >> act; if (act=='Y') { int x1, x2; for(int b=0; b> act; if (act=='Y') { house[x][y]++; p[i].money-=propval[x][y]/2; } } else if ((checkhouse(x,y,i,prop))&&(house[x][y]==4)) { cout << "A hotel costs " << propval[x][y]*2.5 <> act; if (act=='Y') { house[x][y]++; p[i].money-=propval[x][y]*2.5; } } } //Unowned property else { cout << propname[x][y] << " $" << propval[x][y] <=propval[x][y]) { cout << "Would you like to:\n"; cout << "A. Purchase this property\n"; cout << "B. Not purchase this property\n"; cout << "Q. Quit\n"; cin >> act; cout << endl; if (act=='A') { p[i].money-=propval[x][y]; prop[x][y]=i; } } else { cout << "You do not have enough money to purchase this property.\n"; getch(); } } } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void optionsp(vector &p, char &act, matrix &house, matrix &prop, matrix propname, matrix propval, int num) { int x, y, B=0, d1, d2; convert(p[0].n, x, y); //Fell in the Ankh if (p[0].n==21) { cout << propname[x][y] <> act; if (act=='S') { int sell; cout << "Which property would you like to sell?\n"; cin >> sell; convert(sell, x, y); if (prop[x][y]!=0) cout << "You do not own this property.\n"; else { if (p[1].money>propval[x][y]) { cout << "Hex agrees to purchase the porperty\n"; prop[x][y]==1; p[1].money-=propval[x][y]; p[0].money+=propval[x][y]; } else cout << "Hex does not wish to purchase the property\n"; } } else if (act=='T') { clrsrc(); display(0, p); cout << p[i].name << ", you own the following properties: "; for (int x=0; x<8; x++) { for (int y=0; y<8; y++) { if (prop[x][y]==0) { cout << rconvert(x,y) << " - " << propname[x][y] << " ($" << propval[x][y] << ")" << endl; } } } cout << "Hex owns the following properties: "; for (int x=0; x<8; x++) { for (int y=0; y<8; y++) { if (prop[x][y]==1) { cout << rconvert(x,y) << " - " << propname[x][y] << " ($" << propval[x][y] << ")" << endl; } } } int traden; cout << endl << "How many of your properties would you like to trade?\n"; cin >> traden; vector trade1(traden); for (int b=0; b> trade1[b]; } clrsrc(); display(0, p); cout << p[0].name << ", you own the following properties: "; for (int x=0; x<8; x++) { for (int y=0; y<8; y++) { if (prop[x][y]==0) { cout << rconvert(x,y) << " - " << propname[x][y] << " ($" << propval[x][y] << ")" << endl; } } } cout << "Hex owns the following properties: "; for (int x=0; x<8; x++) { for (int y=0; y<8; y++) { if (prop[x][y]==1) { cout << rconvert(x,y) << " - " << propname[x][y] << " ($" << propval[x][y] << ")" << endl; } } } int traden2; cout << endl << "How many properties would you like to receive in the trade?\n"; cin >> traden2; vector trade2(traden); for (int b=0; b> trade2[b]; } clrsrc(); display(0, p); int x1, y1, t1=0, t2=0; for(int b=0; b> act; if (act=='Y') { house[x][y]++; p[0].money-=propval[x][y]/2; } } else if ((checkhouse(x,y,0,prop))&&(house[x][y]==4)) { cout << "A hotel costs " << propval[x][y]*2.5 <> act; if (act=='Y') { house[x][y]++; p[0].money-=propval[x][y]*2.5; } } } //Unowned property else { cout << propname[x][y] << " $" << propval[x][y] <=propval[x][y]) { cout << "Would you like to:\n"; cout << "A. Purchase this property\n"; cout << "B. Not purchase this property\n"; cout << "Q. Quit\n"; cin >> act; cout << endl; if (act=='A') { p[0].money-=propval[x][y]; prop[x][y]=0; } } else { cout << "You do not have enough money to purchase this property.\n"; getch(); } } } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void options(vector &p, char &act, matrix &house, matrix &prop, matrix propname, matrix propval, int num) { int x, y, B=0, d1, d2; convert(p[1].n, x, y); //Fell in the Ankh if (p[1].n==21) { cout << propname[x][y] <=propval[x][y]/2) { cout << "Hex is purchasing a house at " << propname[x][y]; getch(); house[x][y]++; p[1].money-=propval[x][y]/2; } } //Hotel else if ((checkhouse(x,y,0,prop))&&(house[x][y]==4)) { if (p[1].money>=propval[x][y]*2.5) { cout << "Hex is purchasing a hotel at " << propname[x][y]; getch(); hotel[x][y]++; p[1].money-=propval[x][y]*2.5; } } } //Unowned property else { cout << propname[x][y] << " $" << propval[x][y] <=propval[x][y]) { cout << "Hex is purchasing this property\n"; getch(); p[1].money-=propval[x][y]; prop[x][y]=1; } else { cout << "Hex does not have enough money to purchase this property.\n"; getch(); } } } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void one(matrix propname, matrix propval, vector &p, int num, int bnum, matrix &prop, matrix house) { int d1, d2, doub=0; char act='A'; while ((bnum0) cout << " - " << house[x][y] << " houses\n"; } } } cout << endl; optionsp(p, act, house, prop, propname, propval, num); if ((p[0].money<=0)&&(propcheck(prop, 0)) bnum++; } else { cout << "Still in the Ankh!" <0) cout << " - " << house[x][y] << " houses\n"; } } } cout << endl; optionsc(p, act, house, prop, propname, propval, num); if ((p[1].money<=0)&&(propcheck(prop, 1))) bnum++; } else { cout << "Still in the Ankh!" < propname, matrix propval, vector &p, int num, int bnum, matrix &prop, matrix house) { int d1, d2, doub=0; char act='A'; while ((bnum0) cout << " - " << house[x][y] << " houses\n"; } } } cout << endl; options(p, i, act, house, prop, propname, propval, num); if ((p[i].money<=0)&&(propcheck(prop, i))) bnum++; } else { cout << "Still in the Ankh!" < piece(6); vector p(6); matrix house(8,8); matrix propname(8,8); matrix propval(8,8); matrix prop(8,8); int num, cnum, bnum=0; open(num); initialize(propname, propval, piece, p, num, cnum, prop, house); mult(propname, propval, p, num, bnum, prop, house); for (int i=0; i<6; i++) if ((p[i].money>0)||(!propcheck(prop, i))) cout << p[i].name << " wins!\n"; return(0); }