粉丝福利5(小游戏)(加油!!!破250,300粉!!!)

草原大战:

//感觉解释不全,很难玩
#include <bits/stdc++.h>   //WEWILLFINDYOUANDHANTYOU 
#include <windows.h>       //GETYOUANDKILLYOUEATYOU!
#include <conio.h>
using namespace std;
int t,g[15][15],h;
int xf=1,yf=1,hf=10,ff=1,gf=1;
int xs=12,ys=12,hs=10,fs=0,gs=1;
int xt,yt,xln,yln,fx[]= {-1,1,0,0},fy[]= {0,0,-1,1};
int dp[15][15][15][15],cd;
bool bt,bl,bn,bs;
string st="▓",f[4]= {"↑","↓","←","→"},s;
string gz=" <( 操作方法 )>\n1.A 用w a s d移动, 按x键攻击.\n2.B 用u h j k移动, 按n键攻击.\n";
void col(int c1,int c2,string c) {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c1*16+c2);
    cout<<c;
}
void HideCursor() {
    CONSOLE_CURSOR_INFO cursor_info = {1, 0};
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
int makeg(int k) {
    if(k<=600) return 0;//荒原
    if(k<=690) return 1;//草地
    if(k<=780) return 2;//沼泽
    if(k<=870) return 3;//冰川
    if(k<=980) return 4;//废墟
    if(k<=986) return 5;//小炮
    if(k<=988) return 6;//大炮
    if(k<=991) return 7;//穿透枪
    if(k<=992) return 8;// 弹炮
    if(k<=997) return 9;//火矢
    if(k<=999) return 10;//脉冲枪
    if(k<=1000) return 11;//手榴弹
}
void make() {
    int i=14,j;
    col(cd,7,"");
    while(i--) cout<<st;
    cout<<endl;
    for(i=1; i<=12; i++) {
        col(cd,7,st);
        for(j=1; j<=12; j++) {
            if(i==xf&&j==yf) col(10,2,f[ff]);
            else if(i==xs&&j==ys) col(12,4,f[fs]);
            else if(g[i][j]==4) col(cd,7,st);
            else if(g[i][j]==3) col(cd,11,st);
            else if(g[i][j]==2) col(cd,13,st);
            else if(g[i][j]==1) col(cd,10,st);
            else if(g[i][j]==11) col(cd,2,"⊕");
            else if(g[i][j]==10) col(cd,7,"◎");
            else if(g[i][j]==9) col(cd,13,"Δ");
            else if(g[i][j]==8) col(cd,12,"¤");
            else if(g[i][j]==7) col(cd,11,"≈");
            else if(g[i][j]==6) col(cd,14,"≡");
            else if(g[i][j]==5) col(cd,10,"=");
            else col(cd,7,"  ");
        }
        col(cd,7,st);
        cout<<endl;
    }
    i=14;
    col(cd,7,"");
    while(i--) cout<<st;
    cout<<endl<<endl;
    col(10,0,"");
    if(gf==1) cout<<"  ";
    if(gf==5) cout<<"=";
    if(gf==6) cout<<"≡";
    if(gf==7) cout<<"≈";
    if(gf==8) cout<<"¤";
    if(gf==9) cout<<"Δ";
    if(gf==10) cout<<"◎";
    if(gf==11) cout<<"⊕";
    col(cd,10," ph : ");
    printf("%-4d",hf);
    col(12,0,"");
    if(gs==1) cout<<"  ";
    if(gs==5) cout<<"=";
    if(gs==6) cout<<"≡";
    if(gs==7) cout<<"≈";
    if(gs==8) cout<<"¤";
    if(gs==9) cout<<"Δ";
    if(gs==10) cout<<"◎";
    if(gs==11) cout<<"⊕";
    col(cd,12," ph : ");
    printf("%-4d",hs);
}
bool dfs(int x,int y,int xl,int yl) {
    if(x==xl&&y==yl) return dp[x][y][xl][yl]=1;
    if(dp[x][y][xl][yl]!=-1) return dp[x][y][xl][yl];
    int te=g[x][y];
    bool btool=0;
    g[x][y]=-1;
    for(int i=0; i<4; i++) {
        xln=x+fx[i];
        yln=y+fy[i];
        if(xln>0&&xln<13&&yln>0&&yln<13&&(g[xln][yln]==0||g[xln][yln]>4)) {
            if(dfs(xln,yln,xl,yl)) btool=1;
        }
    }
    g[x][y]=te;
    return dp[x][y][xl][yl]=btool;
}
int main() {
    system("title skgame");
    srand((unsigned)time(0));
    HideCursor();
    cd=0;
    system("cls");
    for(int i=1; i<=12; i++)
        for(int j=1; j<=12; j++)
            for(int k=1; k<=12; k++)
                for(int l=1; l<=12; l++)
                    dp[i][j][k][l]=-1;
    for(int i=1; i<=12; i++)
        for(int j=1; j<=12; j++)
            g[i][j]=makeg(rand()%1000+1);
    g[1][1]=g[12][12]=0;
    col(cd,7,"");
    for(int i=0; i<gz.length(); i++) {
        cout<<gz[i];
        Sleep(30);
    }
    string que="3.武器:\n(1).小炮";
    for(int i=0; i<que.length(); i++) {
        cout<<que[i];
        Sleep(30);
    }
    col(cd,10,"=");
    col(cd,7,"");
    cout<<endl;
    Sleep(30);
    que="(2).大炮";
    for(int i=0; i<que.length(); i++) {
        cout<<que[i];
        Sleep(30);
    }
    col(cd,14,"≡");
    col(cd,7,"");
    cout<<endl;
    Sleep(30);
    que="(3).穿透枪";
    for(int i=0; i<que.length(); i++) {
        cout<<que[i];
        Sleep(30);
    }
    col(cd,11,"≈");
    Sleep(30);
    cout<<endl;
    col(cd,7,"");
    que="(4).弹炮";
    for(int i=0; i<que.length(); i++) {
        cout<<que[i];
        Sleep(30);
    }
    col(cd,12,"¤");
    col(cd,7,"");
    cout<<endl;
    Sleep(30);
    que="(5).火栓";
    for(int i=0; i<que.length(); i++) {
        cout<<que[i];
        Sleep(30);
    }
    col(cd,13,"Δ");
    col(cd,7,"");
    cout<<endl;
    Sleep(30);
    que="(6).脉冲枪";
    for(int i=0; i<que.length(); i++) {
        cout<<que[i];
        Sleep(30);
    }
    col(cd,7,"◎");
    col(cd,7,"");
    cout<<endl;
    Sleep(30);
    que="(7).手榴弹";
    for(int i=0; i<que.length(); i++) {
        cout<<que[i];
        Sleep(30);
    }
    col(cd,2,"⊕");
    col(cd,7,"");
    cout<<endl;
    Sleep(30);
    cout<<"4.周围:"<<endl;
    que="(1).墙";
    for(int i=0; i<que.length(); i++) {
        cout<<que[i];
        Sleep(30);
    }
    col(cd,7,"▓");
    col(cd,7,"");
    cout<<endl;
    Sleep(30);
    que="(2).草";
    for(int i=0; i<que.length(); i++) {
        cout<<que[i];
        Sleep(30);
    }
    col(cd,10,"▓");
    col(cd,7,"");
    cout<<endl;
    Sleep(30);
    que="(3).沼泽地";
    for(int i=0; i<que.length(); i++) {
        cout<<que[i];
        Sleep(30);
    }
    col(cd,13,"▓");
    col(cd,7,"");
    cout<<endl;
    Sleep(30);
    que="(4).湖";
    for(int i=0; i<que.length(); i++) {
        cout<<que[i];
        Sleep(30);
    }
    col(cd,11,"▓");
    col(cd,7,"");
    Sleep(30);
    cout<<endl;
    cout<<"按s键开始游戏\n按0键结束游戏"<<endl;
    t=getch();
    while(t!='s') t=getch();
    system("cls");
    make();
    col(cd,12,"\n  Game will start on 3 s\b\b");
    for(int i=3; i>=1; i--) {
        Sleep(1000);
        cout<<"\b"<<i;
    }
    cout<<"开始!"<<endl;
    system("cls");
    make();
    t=getch();
    while(t!='0') {
        bl=1;
        if(t=='w'&&xf>1&&(g[xf-1][yf]==0||g[xf-1][yf]==1)&&!((xf-1==xs)&&(yf==ys))) {
            xf--;
            ff=0;
        } else if(t=='w'&&xf>1&&g[xf-1][yf]==2&&!((xf-1==xs)&&(yf==ys))) {
            xf--;
            hf--;
            ff=0;
            if(hf<=0) break;
        } else if(t=='w'&&xf>1&&g[xf-1][yf]>4&&!((xf-1==xs)&&(yf==ys))) {
            xf--;
            ff=0;
            gf=g[xf][yf];
            g[xf][yf]=0;
        } else if(t=='s'&&xf<12&&(g[xf+1][yf]==0||g[xf+1][yf]==1)&&!((xf+1==xs)&&(yf==ys))) {
            xf++;
            ff=1;
        } else if(t=='s'&&xf<12&&g[xf+1][yf]==2&&!((xf+1==xs)&&(yf==ys))) {
            xf++;
            hf--;
            ff=1;
            if(hf<=0) break;
        } else if(t=='s'&&xf<12&&g[xf+1][yf]>4&&!((xf+1==xs)&&(yf==ys))) {
            xf++;
            ff=1;
            gf=g[xf][yf];
            g[xf][yf]=0;
        } else if(t=='a'&&yf>1&&(g[xf][yf-1]==0||g[xf][yf-1]==1)&&!((xf==xs)&&(yf-1==ys))) {
            yf--;
            ff=2;
        } else if(t=='a'&&yf>1&&g[xf][yf-1]==2&&!((xf==xs)&&(yf-1==ys))) {
            yf--;
            hf--;
            ff=2;
            if(hf<=0) break;
        } else if(t=='a'&&yf>1&&g[xf][yf-1]>4&&!((xf==xs)&&(yf-1==ys))) {
            yf--;
            ff=2;
            gf=g[xf][yf];
            g[xf][yf]=0;
        } else if(t=='d'&&yf<12&&(g[xf][yf+1]==0||g[xf][yf+1]==1)&&!((xf==xs)&&(yf+1==ys))) {
            yf++;
            ff=3;
        } else if(t=='d'&yf<12&&g[xf][yf+1]==2&&!((xf==xs)&&(yf+1==ys))) {
            yf++;
            hf--;
            ff=3;
            if(hf<=0) break;
        } else if(t=='d'&&yf<12&&g[xf][yf+1]>4&&!((xf==xs)&&(yf+1==ys))) {
            yf++;
            ff=3;
            gf=g[xf][yf];
            g[xf][yf]=0;
        } else if(t=='x') {
            xt=yt=bt=bn=bs=0;
            h=1;
            if(gf==8) {
                if(dfs(xf,yf,xs,ys)) bt=1;
            }
            if(gf==10) {
                if(sqrt(pow(xf-xs,2)+pow(yf-ys,2))<4) {
                    bt=1;
                    h=2;
                }
            }
            if(gf==11) {
                if(ff==0) xt=-1;
                if(ff==1) xt=1;
                if(ff==2) yt=-1;
                if(ff==3) yt=1;
                int xn,yn;
                for(xn=xf+xt,yn=yf+yt; xn<=12&&xn>=1&&yn<=12&&yn>=1; xn+=xt,yn+=yt) {
                    if(g[xn][yn]==0||g[xn][yn]>4) break;
                }
                if(xn<=12&&xn>=1&&yn<=12&&yn>=1) {
                    if(sqrt(pow(xn-xs,2)+pow(yn-ys,2))<3) {
                        bt=1;
                        h=2;
                    }
                }
            } else {
                if(gf==9) bs=1;
                if(gf==7) bn=1;
                if(gf==6) h=3;
                if(gf==5) h=2;
                if(ff==0) xt=-1;
                if(ff==1) xt=1;
                if(ff==2) yt=-1;
                if(ff==3) yt=1;
                for(int xn=xf,yn=yf; xn<=12&&xn>=1&&yn<=12&&yn>=1; xn+=xt,yn+=yt) {
                    if(xn==xs&&yn==ys) {
                        bt=1;
                        break;
                    }
                    if((g[xn][yn]==1||g[xn][yn]==4)&&bn==0) break;
                }
            }
            if(bt==1) {
                hs-=h;
                if(hf<10) hf+=bs;
            }
            if(hs<=0) break;
        } else if(t=='u'&&xs>1&&(g[xs-1][ys]==0||g[xs-1][ys]==1)&&!((xs-1==xf)&&(ys==yf))) {
            xs--;
            fs=0;
        } else if(t=='u'&&xs>1&&g[xs-1][ys]==2&&!((xs-1==xf)&&(ys==yf))) {
            xs--;
            hs--;
            fs=0;
            if(hs<=0) break;
        } else if(t=='u'&&xs>1&&g[xs-1][ys]>4&&!((xs-1==xf)&&(ys==yf))) {
            xs--;
            fs=0;
            gs=g[xs][ys];
            g[xs][ys]=0;
        } else if(t=='j'&&xs<12&&(g[xs+1][ys]==0||g[xs+1][ys]==1)&&!((xs+1==xf)&&(ys==yf))) {
            xs++;
            fs=1;
        } else if(t=='j'&&xs<12&&g[xs+1][ys]==2&&!((xs+1==xf)&&(ys==yf))) {
            xs++;
            hs--;
            fs=1;
            if(hs<=0) break;
        } else if(t=='j'&&xs<12&&g[xs+1][ys]>4&&!((xs+1==xf)&&(ys==yf))) {
            xs++;
            fs=1;
            gs=g[xs][ys];
            g[xs][ys]=0;
        } else if(t=='h'&&ys>1&&(g[xs][ys-1]==0||g[xs][ys-1]==1)&&!((xs==xf)&&(ys-1==yf))) {
            ys--;
            fs=2;
        } else if(t=='h'&&ys>1&&g[xs][ys-1]==2&&!((xs==xf)&&(ys-1==yf))) {
            ys--;
            hs--;
            fs=2;
            if(hs<=0) break;
        } else if(t=='h'&&ys>1&&g[xs][ys-1]>4&&!((xs==xf)&&(ys-1==yf))) {
            ys--;
            fs=2;
            gs=g[xs][ys];
            g[xs][ys]=0;
        } else if(t=='k'&&ys<12&&(g[xs][ys+1]==0||g[xs][ys+1]==1)&&!((xs==xf)&&(ys+1==yf))) {
            ys++;
            fs=3;
        } else if(t=='k'&ys<12&&g[xs][ys+1]==2&&!((xs==xf)&&(ys+1==yf))) {
            ys++;
            hs--;
            fs=3;
            if(hs<=0) break;
        } else if(t=='k'&&ys<12&&g[xs][ys+1]>4&&!((xs==xf)&&(ys+1==yf))) {
            ys++;
            fs=3;
            gs=g[xs][ys];
            g[xs][ys]=0;
        } else if(t=='n') {
            xt=yt=bt=bn=bs=0;
            h=1;
            if(gs==8) {
                if(dfs(xf,yf,xs,ys)) bt=1;
            }
            if(gs==10) {
                if(sqrt(pow(xf-xs,2)+pow(yf-ys,2))<4) {
                    bt=1;
                    h=2;
                }
            }
            if(gs==11) {
                if(fs==0) xt=-1;
                if(fs==1) xt=1;
                if(fs==2) yt=-1;
                if(fs==3) yt=1;
                int xn,yn;
                for(xn=xs+xt,yn=ys+yt; xn<=12&&xn>=1&&yn<=12&&yn>=1; xn+=xt,yn+=yt) {
                    if(g[xn][yn]==0||g[xn][yn]>4) break;
                }
                if(xn<=12&&xn>=1&&yn<=12&&yn>=1) {
                    if(sqrt(pow(xn-xf,2)+pow(yn-yf,2))<3) {
                        bt=1;
                        h=2;
                    }
                }
            } else {
                if(gs==9) bs=1;
                if(gs==7) bn=1;
                if(gs==6) h=3;
                if(gs==5) h=2;
                if(fs==0) xt=-1;
                if(fs==1) xt=1;
                if(fs==2) yt=-1;
                if(fs==3) yt=1;
                for(int xn=xs,yn=ys; xn<=12&&xn>=1&&yn<=12&&yn>=1; xn+=xt,yn+=yt) {
                    if(xn==xf&&yn==yf) {
                        bt=1;
                        break;
                    }
                    if((g[xn][yn]==1||g[xn][yn]==4)&&bn==0) break;
                }
            }
            if(bt==1) {
                hf-=h;
                if(hs<10) hs+=bs;
            }
            if(hf<=0) break;
        } else bl=0;
        if(bl==1) {
            system("cls");
            make();
        }
        t=getch();
    }
    system("cls");
    if(hf<=0) {
        col(cd,7,"\n  ");
        col(12,0,"  ");
        col(cd,12," wins!");
    } else if(hs<=0) {
        col(cd,7,"\n  ");
        col(10,0,"  ");
        col(cd,10," wins!");
    } else col(cd,7,"\n  end!\n\n");
    Sleep(1000);
    col(cd,7,"");
    return 0;
}

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值