Untitled5

作者:    qwerty 管理员

标签: C++

创建日期:2024年11月11日 18:21

浏览量:2

#include<bits/stdc++.h>
#include<windows.h>
#include<stdio.h>
#include<conio.h>
#include<time.h>
#ifndef color
#define color(a) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a)
//0黑 1蓝 2绿 3青 4红 5紫 6黄 7白 8灰 9亮蓝 10亮绿 11亮青 12亮红 13亮紫 14亮黄 15亮白 
#endif
using namespace std;
const int stdtime=0;
int Px=1,Py=1,Pd=3,Ph=2000;
int Ex=20,Ey=20,Ed=1,Eh=2000;
bool vis[21][21]={
{0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0}};
inline void initcolor(){
    color(0*16+15);
    return;
}
inline void pu(string s){
    for(int i=0;i<s.size();++i){
        char x=s[i];
        if(x=='\n') Sleep(200*stdtime);
        else if(x=='\t') Sleep(20*stdtime);
        else if(x==' ') Sleep(10*stdtime);
        else if(x=='?'||x=='!'||x==';') Sleep(23*stdtime);
        else if(x=='/'||x=='*'||x=='-'||x=='+'||x=='.') Sleep(4*stdtime);
        else Sleep(3*stdtime);
        putchar(x);
    }
    return;
}
inline void randmap(){
    srand(time(0));
    vis[1][1]=vis[20][20]=0;
    for(int i=2;i<=20;i++) vis[i][1]=!bool(abs(rand())%5);
    for(int i=1;i<=20;i++){
        for(int j=1;j<=20;j++) vis[j][i]=!bool(abs(rand())%5);
    }
    for(int i=1;i<=19;i++) vis[i][20]=!bool(abs(rand())%5);
    return;
}
inline void outputplot(){
    pu("剧情概述:\n");
    pu("A.D.4514年\n");
    pu("FaXiSi主义NaCui党重新组织起来\n");
    pu("进行了一次大规模的起义\n");
    pu("想要建立一个新的国度\n");
    pu("但\n");
    pu("这引起了一些人的注意\n");
    pu("于是乎\n");
    pu("各个大国联合起来剿杀FaXiSi主义NaCui党成员\n");
    pu("经历了无数场战争\n");
    pu("只剩下一位FaXiSi主义NaCui党成员\n");
    pu("那就是你\n");
    pu("希望身为FaXiSi主义NaCui党成员的你\n");
    pu("能够恢复我们曾经的辉煌!\n");
    system("pause");
    return;
}
inline void outputgameinfor(){
    pu("一个蒟蒻创作的游戏\n");
    pu("按WS移动,AD转向,空格开枪(按K相当于\\kill)\n");
    system("pause");
    system("cls");
    outputplot();
    return;
}
inline void outputmap(){
    for(int i=1;i<=20;i++){
        for(int j=1;j<=20;j++){
            if(Px==j&&Py==i) cout<<"卐";
            else if(Ex==j&&Ey==i) cout<<"卍";
            else if(vis[i][j]) cout<<"■";
            else cout<<"□";
        }
        puts("");
    }
    return;
}
inline int inputaction(){
    char x=_getch();
    if(x=='w') return 1;
    if(x=='a') return 2;
    if(x=='s') return 3;
    if(x=='d') return 4;
    if(x==' ') return 5;
    if(x=='k') return 6;
    return 0;
}
inline void dead(){
    color(4*16+13);
    system("cls");
    pu("\t\t\t\tYou died!!!\n");
    exit(0);
    return;
}
inline void win(){
    color(7*16+14);
    system("cls");
    pu("\t\t\t\tYou won!!!\n");
    exit(0);
    return;
}
inline void Pjudgedead(){
    if(Ph<=0) dead();
    else if(Ph>2000) Ph=2000;
    return;
}
inline void Ejudgedead(){
    if(Eh<=0) win();
    else if(Eh>2000) Ph=2000;
    return;
}
inline void refresh(){
    system("cls");
    Pjudgedead();
    color(0*16+4);
    pu("你的血量:");cout<<Ph<<"\t\t\t";
    color(0*16+9);
    pu("敌方血量:");cout<<Eh<<"\n";
    color(0*16+10);
    pu("当前坐标: x=");cout<<Px;pu(" y=");cout<<Py<<"\t\t";
    color(0*16+14);
    pu("敌方坐标: x=");cout<<Ex;pu(" y=");cout<<Ey<<"\n";
    color(0*16+11);
    pu("当前方向:");
    switch(Pd){
        case 1:pu("北");break;
        case 2:pu("西");break;
        case 3:pu("南");break;
        case 4:pu("东");break;
    }
    puts("");
    color(0*16+3);
    pu("敌方方向:");
    switch(Ed){
        case 1:pu("北");break;
        case 2:pu("西");break;
        case 3:pu("南");break;
        case 4:pu("东");break;
    }
    puts("");
    initcolor();
    outputmap();
    return;
}
inline void moving(int a){
    puts("");
    switch(a){
        case 1:
            if(Pd==1&&Py>1&&!vis[Py-1][Px]) Py--;
            else if(Pd==2&&Px>1&&!vis[Py][Px-1]) Px--;
            else if(Pd==3&&Py<20&&!vis[Py+1][Px]) Py++;
            else if(Pd==4&&Px<20&&!vis[Py][Px+1]) Px++;
            break;
        case 2:Pd=Pd%4+1;break;
        case 3:
            if(Pd==3&&Py>1&&!vis[Py-1][Px]) Py--;
            else if(Pd==4&&Px>1&&!vis[Py][Px-1]) Px--;
            else if(Pd==1&&Py<20&&!vis[Py+1][Px]) Py++;
            else if(Pd==2&&Px<20&&!vis[Py][Px+1]) Px++;
            break;
        case 4:Pd=Pd%4+1;Pd=Pd%4+1;Pd=Pd%4+1;break;
        case 5:
            if(Pd==1&&Ex==Px){
                if(Ey<=Py){
                    pu("击中了!造成500点伤害!!!\n");
                    Eh-=500;
                    Ejudgedead();
                }
            }else if(Pd==2&&Ey==Py){
                if(Ex<=Px){
                    pu("击中了!造成500点伤害!!!\n");
                    Eh-=500;
                    Ejudgedead();
                }
            }else if(Pd==3&&Ex==Px){
                if(Ey>=Py){
                    pu("击中了!造成500点伤害!!!\n");
                    Eh-=500;
                    Ejudgedead();
                }
            }else if(Pd==4&&Ey==Py){
                if(Ex>=Px){
                    pu("击中了!造成500点伤害!!!\n");
                    Eh-=500;
                    Ejudgedead();
                }
            }
            break;
    }
}
inline void Emoving(int a){
    switch(a){
        case 1:
            if(Ed==1&&Ey>1&&!vis[Ey-1][Ex]) Ey--;
            else if(Ed==2&&Ex>1&&!vis[Ey][Ex-1]) Ex--;
            else if(Ed==3&&Ey<20&&!vis[Ey+1][Ex]) Ey++;
            else if(Ed==4&&Ex<20&&!vis[Ey][Ex+1]) Ex++;
            break;
        case 2:Ed=Ed%4+1;break;
        case 3:
            if(Ed==3&&Ey>1&&!vis[Ey-1][Ex]) Ey--;
            else if(Ed==4&&Ex>1&&!vis[Ey][Ex-1]) Ex--;
            else if(Ed==1&&Ey<20&&!vis[Ey+1][Ex]) Ey++;
            else if(Ed==2&&Ex<20&&!vis[Ey][Ex+1]) Ex++;
            break;
        case 4:Ed=Ed%4+1;Ed=Ed%4+1;Ed=Ed%4+1;break;
        case 5:
            if(Ed==1&&Px==Ex){
                if(Py<=Ey){
                    pu("被击中了!受到500点伤害!!!\n");
                    Ph-=500;
                    Pjudgedead();
                }
            }else if(Ed==2&&Py==Ey){
                if(Px<=Ex){
                    pu("被击中了!受到500点伤害!!!\n");
                    Ph-=500;
                    Pjudgedead();
                }
            }else if(Ed==3&&Px==Ex){
                if(Py>=Ey){
                    pu("被击中了!受到500点伤害!!!\n");
                    Ph-=500;
                    Pjudgedead();
                }
            }else if(Ed==4&&Py==Ey){
                if(Px>=Ex){
                    pu("被击中了!受到500点伤害!!!\n");
                    Ph-=500;
                    Pjudgedead();
                }
            }
            break;
    }
}
int main(){
    initcolor();
//    outputgameinfor();
    system("cls");
    pu("请选择地图模式:");puts("");
    pu("1.空白地图");puts("");
    pu("2.随机地图");puts("");
    pu("3.默认地图(当前未开放)");puts("");
    char ch=_getch();
    puts("");
    switch(ch){
        case '1':memset(vis,0,sizeof vis);break;
        case '2':randmap();break;
        default:color(0*16+12);pu("输入不规范,NaCui两行泪!!!\n");dead();break;
    }
    while(1){
        srand(time(0));
        refresh();
        pu(":");
        int x=inputaction();
        if(x==6) dead();
        if(!x){
            puts("无效输入!!!");
            continue;
        }
        moving(x);
        if(x==2||x==4){
            pu(":");
            x=0;
            do{
                x=inputaction();
                if(!x){
                    puts("无效输入!!!");
                    continue;
                }
            }while(!x);
            moving(x);
        }
        Sleep(400*stdtime);
        refresh();
        int DeltaX=Ex-Px,DeltaY=Ey-Py;
        if(abs(DeltaX)<abs(DeltaY)){  //左右 
            if(DeltaX==0){
                if(DeltaY>0&&Ed!=3){
                    Ed=1;
                    Emoving(5);
                    continue;
                }else if(DeltaY<0&&Ed!=1){
                    Ed=3;
                    Emoving(5);
                    continue;
                }
            }
            if(Ed==1){  //朝北 
                if(DeltaX>0){  //向左
                    Emoving(2);
                }else{  //向右
                    Emoving(4);
                }
                refresh();
            }else if(Ed==3){  //朝南 
                if(DeltaX>0){  //向左
                    Emoving(4);
                }else{  //向右
                    Emoving(2);
                }
                refresh();
            }
            if(DeltaX>0){  //向左 
                if(vis[Ey][Ex-1]){
                    Emoving(2*(rand()%2+1));
                    Emoving(1);
                }else Emoving(1);
            }else{  //向右 
                if(vis[Ey][Ex+1]){
                    Emoving(2*(rand()%2+1));
                    Emoving(1);
                }else Emoving(1);
            }
        }else if(abs(DeltaX)>abs(DeltaY)){ //上下 
            if(DeltaY==0){
                if(DeltaX>0&&Ed!=4){
                    Ed=1;
                    Emoving(5);
                    continue;
                }else if(DeltaX<0&&Ed!=2){
                    Ed=3;
                    Emoving(5);
                    continue;
                }
            }
            if(Ed==2){  //朝左 
                if(DeltaY>0){  //向上
                    Emoving(4);
                }else{  //向下 
                    Emoving(2);
                }
                refresh();
            }else if(Ed==4){  //朝右 
                if(DeltaY>0){  //向上
                    Emoving(2);
                }else{  //向下
                    Emoving(4);
                }
                refresh();
            }
//          --------------------------------------以下的没改 ---------------------------------------
            if(DeltaX>0){  //向左 
                if(vis[Ey][Ex-1]){
                    Emoving(2*(rand()%2+1));
                    Emoving(1);
                }else Emoving(1);
            }else{  //向右 
                if(vis[Ey][Ex+1]){
                    Emoving(2*(rand()%2+1));
                    Emoving(1);
                }else Emoving(1);
            }
        }else{
            Emoving(5);
        }
    }
    return 0;
}

评论区

竟然没有人发布评论!