/*
Name : Millionare
Original producer : A_Pikachu
Version : v0.1.2(beta)
Lastest update : 2022/5/25
*/
//at most 4 people
//to do: better display and interact, sell houses, trade, ...
#include <windows.h>
#include <bits/stdc++.h>
#include <conio.h>
#define gc _getch
#define gcc getchar
#define pc putchar
using namespace std;
const int P=15,N=35,D=10,CR=200;
namespace display{
void full_screen(){
HWND hwnd=GetForegroundWindow();
int cx=GetSystemMetrics(SM_CXSCREEN);
int cy=GetSystemMetrics(SM_CYSCREEN);
LONG l_WinStyle=GetWindowLong(hwnd,GWL_STYLE);
SetWindowLong(hwnd,GWL_STYLE,(l_WinStyle|WS_POPUP|WS_MAXIMIZE));
SetWindowPos(hwnd,HWND_TOP,0,0,cx,cy,0);
}
void gotoxy(int x,int y){
COORD pos;
pos.X=x;
pos.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
int getl(){
CONSOLE_SCREEN_BUFFER_INFO SBInfo;
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hOut,&SBInfo);
return SBInfo.dwCursorPosition.Y;
}
}
using namespace display;
void enter_pause(){
printf("Press Enter to continue.\n");
gc();
}
void preprint(){
printf("Name : Millionare\n");
printf("Original producer : A_Pikachu\n");
printf("Version : v0.1.2(beta)\n");
printf("Lastest update : 2022/5/25\n");
printf("Hope you can have fun! o.O\n\n");
printf("Update log (v0.1.1):\nfixed some bugs due to weird players input\nfixed some bugs in single player mode\n\n");
printf("Update log (v0.1.2):\nfixed some bugs due to weird interactions\n\n");
enter_pause();
}
void emp(){
printf(" \n");
}
void clscr(){
gotoxy(0,0);
for(int i=1; i<=50; i++) emp();
gotoxy(0,0);
}
void clrs(){
int l=getl();
for(int i=1; i<=10; i++) emp();
gotoxy(0,l);
}
bool askk(char x='y',char y='n'){
char ch=gc();
int l=getl();
while(1){
gotoxy(0,l);
emp();
gotoxy(0,l);
if(ch==x) return 1;
if(ch==y) return 0;
printf("Try again...(%c/%c):",x,y);
ch=gc();
}
}
template <typename T> void read(T &x){
x=0;
char ch=getchar();
while(ch<'0'||ch>'9') ch=gcc();
while('0'<=ch&&ch<='9'&&x<=10000000) x=x*10+ch-'0',ch=gcc();
while('0'<=ch&&ch<='9'&&x>10000000) ch=gcc();
}
int players,val[N]={
0,3200,2600,2700,2200,2400,2600,2500,1900,2000,2800,2700,2300,2900,3300,3500,2400,2100,2600,3000,2500,2700
};
char inp[N];
int mp[P][P]={{},{0,22,1,2,3,23,4,5,6,24},{0,7,0,29,0,10,0,30,0,13,0,28},{0,8,0,0,0,11,0,0,0,14},{0,9,0,31,0,12,0,32,0,15},{0,25,16,17,18,26,19,20,21,27}};
/*
22 1 2 3 23 4 5 6 24
7 29 10 30 13 0 28
8 11 14
9 31 12 32 15
25 16 17 18 26 19 20 21 27
*/
int player_display_x[D]={0,};
int player_display_y[D]={0,};
int getmoney(int id);
namespace basic{
int hrate[]={20,40,60,80,100}; // build house
int prate[]={10,30,60,100,150,200}; // pay
int mrate[]={30,36,48,66,90,120}; // mortgage
int srate[]={70,84,112,154,210,280}; // sell
#define r pc('\n')
#define s pc(' ')
#define l pc('|')
#define c(tmp) printf("%2d",id+tmp)
void pt0(){printf(" ");}
struct usual{ // unchecked
int price,owner,houses,passer,id;
bool mort,pos[5];
void pt1(){printf("*---------*");}
void pt2(){printf(" ");}
void pt3(){l; printf("%c",houses>=1?'^':' '); printf("%5d",price); s; c(0); l;}
void pt4(){l; printf("%c",houses>=2?'^':' '); s; s; pc(pos[1]?'1':' '); s; pc(pos[2]?'2':' '); s; s; s; l;}
void pt5(){l; printf("%c",houses>=3?'^':' '); s; s; s; pc(owner+'0'); s; s; s; s; l;}
void pt6(){l; printf("%c",houses>=4?'^':' '); s; s; pc(pos[3]?'3':' '); s; pc(pos[4]?'4':' '); s; s; s; l;}
void pt7(){l; printf("%c",houses>=5?'^':' '); s; printf("%5d",passer); s; s; l;}
// unchecked
void buy(int id){
mort=0;
owner=id;
passer=price*prate[0]/100;
}
int setup(){
passer=price*prate[++houses]/100;
return price*hrate[houses-1]/100;
}
int house_money(){
return price*hrate[houses]/100;
}
int sell_money(){
if(mort) return 0;
return price*srate[houses]/100;
}
int mortgage_money(){
return price*mrate[houses]/100;
}
void sell_a_house(){
--houses;
}
void sold(){
mort=0;
owner=0;
houses=0;
passer=0;
}
void mortgage(){
mort=1;
passer=houses=0;
}
}a[N];
struct specl{ // checked
int id,price,owner,passer;
bool pos[5];
void pt1(){printf("*---------*");}
void pt2(){printf(" ");}
void pt3(){
if(id==1){l; s; printf("Start"); s; c(21); l;}
if(id==2){l; s; printf("Build"); s; c(21); l;}
if(id==3){l; s; printf("Jail!"); s; c(21); l;}
if(id==4){l; s; s; printf("Free"); s; c(21); l;}
if(id==5){l; s; printf("%5d",price); s; c(21); l;}
if(id==6){l; s; s; printf("Free"); s; c(21); l;}
if(id==7){l; s; printf("Price"); s; printf("Id"); l;}
if(id>7){s; if(id-7<=players){printf("Player %d:",id-7);} else{s; s; s; s; s; s; s; s; s;} s;}
}
void pt4(){
if(id==1){l; s; s; s; pc(pos[1]?'1':' '); s; pc(pos[2]?'2':' '); s; s; s; l;}
if(id==2){l; s; s; s; pc(pos[1]?'1':' '); s; pc(pos[2]?'2':' '); s; s; s; l;}
if(id==3){l; s; s; s; pc(pos[1]?'1':' '); s; pc(pos[2]?'2':' '); s; s; s; l;}
if(id==4){l; s; s; s; pc(pos[1]?'1':' '); s; pc(pos[2]?'2':' '); s; s; s; l;}
if(id==5){l; s; s; s; pc(pos[1]?'1':' '); s; pc(pos[2]?'2':' '); s; s; s; l;}
if(id==6){l; s; s; s; pc(pos[1]?'1':' '); s; pc(pos[2]?'2':' '); s; s; s; l;}
if(id==7){l; s; printf("Players"); s; l;}
}
void pt5(){
if(id==1){l; s; s; s; s; s; s; s; s; s; l;}
if(id==2){l; s; s; s; s; s; s; s; s; s; l;}
if(id==3){l; s; s; s; s; s; s; s; s; s; l;}
if(id==4){l; s; s; s; s; printf("to"); s; s; s; l;}
if(id==5){l; s; s; s; s; pc(owner+'0'); s; s; s; s; l;}
if(id==6){l; s; s; s; s; s; s; s; s; s; l;}
if(id==7){l; s; s; printf("Owner"); s; s; l;}
}
void pt6(){
if(id==1){l; s; s; s; pc(pos[3]?'3':' '); s; pc(pos[4]?'4':' '); s; s; s; l;}
if(id==2){l; s; s; s; pc(pos[3]?'3':' '); s; pc(pos[4]?'4':' '); s; s; s; l;}
if(id==3){l; s; s; s; pc(pos[3]?'3':' '); s; pc(pos[4]?'4':' '); s; s; s; l;}
if(id==4){l; s; s; s; pc(pos[3]?'3':' '); s; pc(pos[4]?'4':' '); s; s; s; l;}
if(id==5){l; s; s; s; pc(pos[3]?'3':' '); s; pc(pos[4]?'4':' '); s; s; s; l;}
if(id==6){l; s; s; s; pc(pos[3]?'3':' '); s; pc(pos[4]?'4':' '); s; s; s; l;}
if(id==7){l; s; printf("Players"); s; l;}
}
void pt7(){
if(id==1){l; s; s; printf("+5000"); s; s; l;}
if(id==2){l; s; s; s; s; s; s; s; s; s; l;}
if(id==3){l; s; s; s; s; s; s; s; s; s; l;}
if(id==4){l; s; s; s; printf("Jail"); s; s; l;}
if(id==5){l; s; s; s; s; s; s; s; s; s; l;}
if(id==6){l; s; printf("Flight!"); s; l;}
if(id==7){l; s; s; s; printf("Toll"); s; s; l;}
if(id>7){s; s; if(id-7<=players){printf("$%5d",getmoney(id-7));} else{s; s; s; s; s; s;} s; s; s;}
}
}b[N];
void pt(const int *all){ // checked
for(int j=1; j<=11; j++){
if(all[j]>28) pt0();
else if(all[j]>21) b[all[j]-21].pt1();
else if(all[j]) a[all[j]].pt1();
else pt0();
} r;
for(int j=1; j<=11; j++){
if(all[j]>28) b[all[j]-21].pt3();
else if(all[j]>21) b[all[j]-21].pt3();
else if(all[j]) a[all[j]].pt3();
else pt0();
} r;
for(int j=1; j<=11; j++){
if(all[j]>28) pt0();
else if(all[j]>21) b[all[j]-21].pt4();
else if(all[j]) a[all[j]].pt4();
else pt0();
} r;
for(int j=1; j<=11; j++){
if(all[j]>28) pt0();
else if(all[j]>21) b[all[j]-21].pt5();
else if(all[j]) a[all[j]].pt5();
else pt0();
} r;
for(int j=1; j<=11; j++){
if(all[j]>28) pt0();
else if(all[j]>21) b[all[j]-21].pt6();
else if(all[j]) a[all[j]].pt6();
else pt0();
} r;
for(int j=1; j<=11; j++){
if(all[j]>28) b[all[j]-21].pt7();
else if(all[j]>21) b[all[j]-21].pt7();
else if(all[j]) a[all[j]].pt7();
else pt0();
} r;
for(int j=1; j<=11; j++){
if(all[j]>28) pt0();
else if(all[j]>21) b[all[j]-21].pt1();
else if(all[j]) a[all[j]].pt1();
else if(j==11&&all[9]==24) printf("Example:");
else pt0();
} r;
}
void ptmp(){for(int i=1; i<=5; i++) pt(mp[i]);}
void init1(){ // checked
b[5].price=100;
for(int i=1; i<N-21; i++) b[i].id=i;
clscr();
printf("Input the player numbers(at most 4):\n");
read(players);
while(players<1||players>4){
printf("Invalid input, try again:\n");
read(players);
}
for(int i=1; i<=players; i++) b[1].pos[i]=1;
printf("Do you need to change the price?(y/n):\n");
if(askk()){
printf("Sorry, we're unable to do this now.\n");
// printf("Input the prices for each land(21):\n");
// for(int i=1; i<=21; i++) scanf("%d",val+i);
}
for(int i=1; i<=21; i++) a[i].price=val[i];
}
#undef l
#undef r
#undef s
#undef c
void move(int from,int to,int id){ // checked
if(from>21) b[from-21].pos[id]=0;
else a[from].pos[id]=0;
if(to>21) b[to-21].pos[id]=1;
else a[to].pos[id]=1;
}
}
namespace game{
int to[N][D];
int dx[D]={0,0,1,-1,0};
int dy[D]={0,-1,0,0,1};
char dire[D][N]={"","left(a)","down(s)","up(w)","right(d)"};
// 1:left 2:down 3:up 4:right
int cg(char a){
return (a=='a'?1:(a=='s'?2:(a=='w'?3:(a=='d'?4:0))));
}
bool can[D];
void give_money(int from,int to,int money);
bool injail(int id);
struct info{
int id,money,jail,lands,back,pos,land[N];
bool alive=1,lst[2][D][D];
void init(int i){
id=i;
pos=22;
money=15000;
}
void dead(){
printf("Oops, you are out of money...\n");
printf("WASTED!\n");
printf("Player %d go bankrupt...\n",id);
for(int i=1; i<=lands; i++) basic::a[land[i]].sold();
--players;
alive=0;
}
void going_to_dead(){ // unfinished
while(money<0){
if(!lands){
dead();
break;
}
printf("You are going to go bankrupt now...\n");
printf("Now you have %d land(s).\n",lands);
int max_sell=0;
for(int i=1; i<=lands; i++) max_sell+=basic::a[land[i]].sell_money();
if(max_sell+money<0){
printf("Although you have such these lands, you still will go bankrupt!\n");
dead();
return;
}
printf("Your lands are:\n");
for(int i=1; i<=lands; i++){
printf("%3d ",land[i]);
}
printf("Choose one to sell or mortgage.\n");
int land_id=0;
read(land_id);
while(1){
clrs();
if(land_id<1||land_id>21){
printf("Invalid input, try again:\n");
read(land_id);
continue;
}
if(basic::a[land_id].owner!=id){
printf("This is not your land...\nWhat are you thinking about?\nTry again:\n");
read(land_id);
continue;
}
if(basic::a[land_id].mort){
printf("This land has been mortgaged...\nWhat are you thinking about?\nTry again:\n");
read(land_id);
continue;
}
break;
}
printf("Do you want to sell it or mortgage it?(s/m)\n");
bool want_to_sell=askk('s','m');
if(want_to_sell){
money+=basic::a[land_id].sell_money();
basic::a[land_id].sold();
for(int i=1; i<=lands; i++){
if(land[i]==land_id){
for(int j=i; j<lands; j++) land[j]=land[j+1];
break;
}
}
--lands;
}else{
money+=basic::a[land_id].mortgage_money();
basic::a[land_id].mortgage();
}
}
}
void stand(){ // writing
gotoxy(0,0);
basic::ptmp();
clrs();
printf("You are at %d. \n",pos);
if(pos<=21){ //finished
if(!basic::a[pos].owner){
printf("No one owns it.\n");
if(money<basic::a[pos].price){
printf("It seems like you don't have enough money to buy this land...\n");
}else{
printf("Would you like to buy it for $%d?(y/n)\n",basic::a[pos].price);
if(askk()){
printf("Congratulations! You're now the owner of this land!\n");
basic::a[pos].buy(id);
land[++lands]=pos;
sort(land+1,land+1+lands);
money-=basic::a[pos].price;
}else{
printf("That's alright.\n");
}
}
}else if(basic::a[pos].owner==id){
printf("It's your land!\n");
if(basic::a[pos].mort){
printf("You mortgaged it!\n");
if(money<basic::a[pos].price){
printf("And you can't buy it now...\n");
return;
}else{
printf("Would you like to buy it?(y/n)\n");
if(askk()){
printf("You redeem your land!\n");
money-=basic::a[pos].price;
basic::a[pos].buy(id);
}else{
printf("That's alright.\n");
}
}
}else if(money<basic::a[pos].house_money()){
printf("It seems like you don't have enough money to build a house...\n");
}else{
printf("Would you like to build a house for $%d?(y/n)\n",basic::a[pos].house_money());
if(askk()){
money-=basic::a[pos].house_money();
basic::a[pos].setup();
printf("Congratulations! You now have %d house(s) on this land!\n",basic::a[pos].houses);
}else{
printf("That's alright.\n");
}
}
}else{
printf("It's Player %d's land.\n",basic::a[pos].owner);
if(injail(basic::a[pos].owner)){
printf("But Player %d is in jail!\nSo you don't have to pay anything!\n",basic::a[pos].owner);
}else{
printf("You have to pay $%d.\n",basic::a[pos].passer);
give_money(id,basic::a[pos].owner,basic::a[pos].passer);
}
if(money<0){
going_to_dead();
}
}
}
if(pos==22){ // checked
back=0;
money+=6000;
printf("You get $5000 and extra $1000!\n");
return;
}
if(pos==23){ // checked
printf("You can build a house on one of your lands!\n");
if(!lands){
printf("But you don't have any lands...\n");
return;
}
printf("You have %d land(s)!\n",lands);
printf("Choose one and pay for the house!(or type 0 to quit)\n");
int aim=0,tmp=getl(),res=0;
while(1){
++res;
read(aim);
if(aim<0||aim>21){
printf("Invalid number!\n");
++res;
continue;
}
if(!aim){
++res;
printf("Are you sure?(y/n)\n");
if(askk()) break;
else{
int nowsl=getl()-1;
gotoxy(0,nowsl);
emp();
gotoxy(0,nowsl);
}
continue;
}
if(basic::a[aim].owner!=id){
++res;
printf("It's not yours...\n");
continue;
}
if(basic::a[aim].house_money()>money){
++res;
printf("You need $%d to build a house on this land...\n",basic::a[aim].house_money());
continue;
}
printf("You need $%d to build a house on this land...\nAre you sure?(y/n)\n",basic::a[aim].house_money());
++res; ++res;
if(askk()) break;
else{
int nowsl=getl()-2;
gotoxy(0,nowsl);
emp();
emp();
gotoxy(0,nowsl);
}
}
gotoxy(0,tmp);
for(int i=1; i<res; i++) emp();
gotoxy(0,tmp);
if(aim){
int cost=basic::a[aim].setup();
printf("You should pay $%d to build a house.\n",cost);
money-=cost;
}
return;
}
if(pos==24){ //finished
printf("You are in prison now!\n");
jail=2;
return;
}
if(pos==25){ //finished
printf("You are arrested!\n");
jail=2;
pos=24;
back=0;
basic::move(25,24,id);
return;
}
if(pos==26){ // finished
printf("You are at the checker!\n");
if(!basic::b[5].owner){
printf("No one owns it.\n");
if(money<basic::b[5].price){
printf("It seems like you don't have enough money to buy this land...\n");
}else{
printf("Would you like to buy it for $%d?(y/n)\n",basic::b[5].price);
if(askk()){
printf("Congratulations! You're now the owner of this land!\n");
basic::b[5].owner=id;
money-=basic::a[pos].price;
}else{
printf("That's alright.\n");
}
}
}
return;
}
if(pos==27){ // finished
printf("You can go to anywhere you want!\n");
printf("Choose one and fly to it!(or type 0 to quit)\n");
int aim=0,tmp=getl(),res=0;
while(1){
++res;
read(aim);
if(aim<0||aim>26){
++res;
printf("Invalid number!\n");
continue;
}
if(!aim){
++res;
printf("Are you sure?(y/n)\n");
if(askk()) break;
else{
int nowsl=getl()-1;
gotoxy(0,nowsl);
emp();
gotoxy(0,nowsl);
}
continue;
}
break;
}
gotoxy(0,tmp);
for(int i=1; i<res; i++) emp();
gotoxy(0,tmp);
basic::move(pos,aim,id);
pos=aim;
back=0;
stand();
}
}
void act(){ // checked
gotoxy(0,0);
basic::ptmp();
printf("Player %d's turn!\n",id);
if(jail){
printf("Player %d is in prison...\n%d day%s left.\n",id,jail,jail>1?"s":"");
jail--;
return;
}
int dice=rand()%6+1;
//
// dice=35;
//
printf("You rolled %d!\n",dice);
enter_pause();
while(dice){
gotoxy(0,0);
basic::ptmp();
clrs();
printf("You have %d step%s left.\n",dice,dice>1?"s":"");
printf("You are at %d. \n",pos);
printf("You can move to:\n");
can[1]=can[2]=can[3]=can[4]=0;
for(int t=1; t<=4; t++){
if(t==back||!to[pos][t]||(pos==23&&lst[0][back][t])||(pos==26&&lst[0][back][t])) continue;
printf("%s ",dire[t]);
can[t]=1;
}
gotoxy(120,0);
gotoxy(0,39);
int tt=0,tmp=getl(),res=0;
while(1){
++res;
tt=cg(gc());
if(!tt){
printf("Invalid direction!\n");
continue;
}
if(!can[tt]){
printf("You can't go that way...\n");
continue;
}
break;
}
gotoxy(0,tmp);
for(int i=1; i<res; i++) emp();
gotoxy(0,tmp);
if(pos==23){
for(int i=1; i<=4; i++) for(int j=1; j<=4; j++) lst[0][i][j]=0;
lst[0][back][tt]=1;
}
if(pos==26){
for(int i=1; i<=4; i++) for(int j=1; j<=4; j++) lst[1][i][j]=0;
lst[1][back][tt]=1;
}
back=5-tt;
basic::move(pos,to[pos][tt],id);
pos=to[pos][tt];
dice--;
if(pos==26){
int tmp=getl();
if(basic::b[5].owner==id){
printf("You passed the checker!\n");
basic::b[5].price+=CR;
}else if(basic::b[5].owner){
printf("You passed the checker! You paid %d and it's yours now!\n",basic::b[5].price);
money-=basic::b[5].price;
basic::b[5].owner=id;
basic::b[5].price+=CR;
}else{
printf("You passed the checker! But nothing happens.\n");
}
gc();
gotoxy(0,tmp);
emp();
}
if(!dice) break;
if(pos==22){
int tmp=getl();
printf("You passed the START!\n");
printf("You get $5000!\n");
money+=5000;
gc();
gotoxy(0,tmp);
emp();
}
}
stand();
}
}p[P];
void give_money(int from,int to,int money){
p[from].money-=money;
p[to].money+=money;
}
bool injail(int id){return game::p[id].jail;}
void init(){ // checked
for(int i=1; i<=players; i++) p[i].init(i);
for(int i=1; i<=21; i++) basic::a[i].id=i;
for(int i=1; i<=5; i++){
for(int j=1; j<=9; j++){
printf("%2d ",mp[i][j]);
int id=mp[i][j];
if(!id) continue;
for(int t=1; t<=4; t++){
int xx=i+dx[t],yy=j+dy[t];
if(!mp[xx][yy]||mp[xx][yy]>27) continue;
to[id][t]=mp[xx][yy];
}
}
printf("\n");
}
}
}
int getmoney(int id){return game::p[id].money;}
int main(){
full_screen();
srand(time(0));
preprint();
basic::init1();
game::init();
int now=1,lst=0;
while(1){
if((lst==now&&players!=1)||(players==1&&!game::p[1].alive)) break;
if(game::p[now].alive) game::p[now].act(),lst=now;
enter_pause();
++now;
if(now>players) now=1;
gotoxy(0,35); clrs();
}
if(players!=1) printf("Congratulations! Player %d wins!\n",now);
else printf("You lose! /cf\n");
// ptmp();
return 0;
}剪贴板
剪贴板 yk9nf9a2
剪贴板信息
剪贴板信息
- 收录
- 更新