新英格兰的旅行家

· · 个人记录

#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
int s[25][25],bo[10][10],ne[12][12],ph[11][11],blood=50,money=100,attack=5,medi;char n,df;
bool lo,li,bi,ar,ru;float shield=1.0;
struct pos{
    int x,y;
}pl,ib,iy,ip;
int war(int ea,float es,int med,int ebl){
    while(blood>0&&ebl>0){
        cout<<"what would you do?(1=attack,2=drink medicine,3=escape)\nyour blood:"<<blood<<"%\n"<<"medicine:"<<med<<"\n"<<"his blood:"<<ebl<<"\n";
        int yd;
        cin>>yd;
        if(yd==1){
            ebl-=es*attack;
        }else if(yd==2){
            if(med>0){
                blood+=45;
                blood=min(blood,100);
                med--;
                medi--;
            }
        }else if(yd==3){
            return 0;
        }
        blood-=ea*shield;
        if(blood<=0){
            cout<<"you died\ngame restarted before the task(or arena)\n";
            blood=0;
            return -1;
        }
        if(ebl<=0){
            cout<<"you win\n";
            return 1;
        }
    }
}
void arena(){
    system("cls");
    cout<<"Select a difficulty(1=easy,2=normal,3=hard)";
    int ff;
    cin>>ff;
    if(ff==1){
        if(war(15,0.8,medi,60)==1){
            cout<<"You got the reward of 20$\n";
            money+=20;
        }
    }else if(ff==2){
        if(war(35,0.6,medi,90)==1){
            cout<<"You got the reward of 40$\n";
            money+=40;
        }
    }else if(ff==3){
        if(war(55,0.4,medi,120)==1){
            cout<<"You got the reward of 60$\n";
            money+=60;
        }
    }
}
void TDK(){
    system("cls");
    cout<<"---The Black Slave---\n";
    cout<<"You met a black slave that escaped from an evil trader,and he asked you to protect him.(1=allow,2=refuse)";
    int qp;
    cin>>qp;
    if(qp==2){
        cout<<"Task Failed\n";
        return; 
    }
    cout<<"Then the trader came to you,with a knife(attack=20)";
    if(war(20,0.9,medi,65)==1){
        cout<<"You got the reward of 40$\n";
        money+=40;
        cout<<"Task Completed\n";
        bo[1][1]=14;
    }else if(war(20,0.9,medi,65)==0){
        cout<<"Task Failed\n";
        return; 
    }else{
        return;
    }
}
void shop(){
    system("cls");
    cout<<"Louis's Sword  Lincoin's Sword  Biden's Sword  Arther's Shield  Rubinson's Shield  medicine\n    40               80              130             50                 120            5\n";
    cout<<"choose the number";
    int nb;
    cin>>nb;
    if(nb==1){
        if(money>=40&&lo==0){
            money-=40;
            attack=15;
            cout<<"you did it\n";
            lo=1;
        }
    }else if(nb==2){
        if(money>=80&&li==0){
            money-=80;
            attack=30;
            cout<<"you did it\n";
            li=1;
        }
    }else if(nb==3){
        if(money>=130&&bi==0){
            money-=130;
            attack=50;
            cout<<"you did it\n";
            bi=1;
        }
    }else if(nb==4){
        if(money>=50&&ar==0){
            money-=50;
            shield=0.8;
            cout<<"you did it\n";
            ar=1;
        }
    }else if(nb==5){
        if(money>120&&ru==0){
            money-=120;
            shield=0.5;
            cout<<"you did it\n";
            ru=1;
        }
    }else if(nb==6&&money>=5){
        money-=5;
        medi++;
        cout<<"you did it\n"; 
    }
}
void dplay(){
    system("cls");
    for(int i=0;i<25;i++){
        cout<<"___";
    }
    cout<<"\n";
    for(int i=0;i<25;i++){
        for(int j=0;j<25;j++){
            if(s[i][j]==0){
                cout<<"   ";
            }else if(s[i][j]==5){
                cout<<" ^ ";
            }else if(s[i][j]==2){
                cout<<"$B$";
            }else if(s[i][j]==3){
                cout<<"$N$";
            }else if(s[i][j]==4){
                cout<<"$P$";
            }else if(s[i][j]==7||s[i][j]==8||s[i][j]==9){
                cout<<"$^$";
            }
        }
        cout<<"|\n";
    }
    for(int i=0;i<25;i++){
        cout<<"---";
    }
    cout<<"\nyour blood:"<<blood<<"%\nyour money:"<<money<<"\nmedicine:"<<medi<<"\n";
}
void dplay_bt(){
    system("cls");
    for(int i=0;i<10;i++){
        cout<<"___";
    }
    cout<<"\n";
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            if(bo[i][j]==0){
                cout<<"   ";
            }else if(bo[i][j]==5){
                cout<<" ^ ";
            }else if(bo[i][j]==2){
                cout<<"###";
            }else if(bo[i][j]==3){
                cout<<"<?>";
            }else if(bo[i][j]==8||bo[i][j]==14){
                cout<<"<^>";
            }else if(bo[i][j]==9){
                cout<<"<!>";
            }else if(bo[i][j]==10){
                cout<<"V S";
            }else if(bo[i][j]==15){
                cout<<"V^S";
            }
        }
        cout<<"|\n";
    }
    for(int i=0;i<10;i++){
        cout<<"---";
    }
    cout<<"\n";
    cout<<"\nyour blood:"<<blood<<"%\nyour money:"<<money<<"\nmedicine:"<<medi<<"\n";
}
void bt(){
    bo[6][4]=5;
    ib.x=6;ib.y=4;
    bo[0][0]=bo[0][1]=bo[0][2]=bo[0][4]=bo[0][7]=bo[0][8]=bo[0][9]=bo[0][6]=2;
    bo[1][0]=bo[1][2]=bo[1][4]=bo[1][6]=bo[1][7]=2;
    bo[2][0]=bo[2][4]=bo[2][7]=bo[2][9]=2;
    bo[3][0]=bo[3][1]=bo[3][4]=bo[3][9]=2;
    bo[4][1]=bo[4][2]=bo[4][4]=bo[4][6]=bo[4][8]=2;
    bo[5][4]=bo[5][5]=bo[5][6]=bo[5][8]=2;
    bo[6][1]=bo[6][2]=bo[6][0]=bo[6][5]=bo[6][8]=bo[6][9]=2;
    bo[7][0]=bo[7][1]=bo[7][9]=2;
    bo[8][3]=bo[8][4]=bo[8][5]=bo[8][8]=bo[8][9]=2;
    for(int i=0;i<=9;i++) bo[9][i]=2;
    while(1){
        dplay_bt();
        if(bo[ib.x][ib.y]==8&&ib.x==1&&ib.y==1){
            cout<<"Will you do this task(Y or N)";
            char ff;
            cin>>ff;
            if(ff=='Y'){
                TDK();
            }
        }
        if(bo[ib.x][ib.y]==15){
            cout<<"Will you go to the arena(Y or N)";
            char ff;
            cin>>ff;
            if(ff=='Y'){
                arena();
            }
        }
        cout<<"Your moving direction(m is to leave,n is to go to shop):";
        n=getch();
        bo[ib.x][ib.y]-=5;
        if(n=='w'||n=='W'){
            ib.x--;
        }else if(n=='s'||n=='S'){
            ib.x++;
        }else if(n=='a'||n=='A'){
            ib.y--;
        }else if(n=='d'||n=='D'){
            ib.y++;
        }else if(n=='m'||n=='M'){
            return;
        }else if(n=='n'||n=='N'){
            shop();
        }
        bo[ib.x][ib.y]+=5;
    }
}
void ny(){
    ne[6][6]=5;
    while(1){

    }
}
void pp(){
    ph[5][5]=5;
    while(1){

    }
}
int main(){
    pl.y=pl.x=13;
    s[13][13]=5;
    s[5][20]=2;
    s[15][12]=3;
    s[21][7]=4;
    bo[1][1]=bo[1][8]=bo[8][2]=bo[7][8]=3;
    bo[4][5]=10;
    while(1){
        dplay();
        if(pl.x==5&&pl.y==20){
            cout<<"Will you go to Boston?(Y or N)";
            cin>>df;
            if(df=='Y'){
                bt();
            }
        }
        if(pl.x==15&&pl.y==12){
            cout<<"Will you go to New York?(Y or N)";
            cin>>df;
            if(df=='Y'){
                ny();
            }
        }
        if(pl.x==21&&pl.y==7){
            cout<<"Will you go to Philadelphia?(Y or N)";
            cin>>df;
            if(df=='Y'){
                pp();
            }
        }
        cout<<"Your moving direction:(n is to go to the shop)";
        n=getch();
        s[pl.x][pl.y]-=5;
        if(n=='w'||n=='W'){
            pl.x--;
        }else if(n=='s'||n=='S'){
            pl.x++;
        }else if(n=='a'||n=='A'){
            pl.y--;
        }else if(n=='d'||n=='D'){
            pl.y++;
        }else if(n=='n'||n=='N'){
            shop();
        }
        s[pl.x][pl.y]+=5;
    }
}