qq_43509688 2019-05-10 16:51 采纳率: 0%
浏览 278

我正在做一个控制台小游戏,遇到了一个问题,请各路大侠帮帮忙。

废话不说看代码

#include<iostream>
#include<thread>
#include<cstdio>             
#include<cstdlib> 
#include<windows.h>
#include<string.h>
#include<time.h>
#include<bits/stdc++.h>
#include<conio.h>
#include<fstream>
using namespace std;
struct project
{
    int blood;
    int x;
    int y;
    int lastx;
    int lasty;
    string name;
    int ATK;
    int DEF;
    int gongjif;
}m[15],player;
string names[10]={"Ted","Tom","Sans","Frisk","Lang","Tem","Bob","Dreamy","P***ru*s","错误代码:10011101"};
string mapp[20],f="●",q="○";
int gongji=0,gongji2=0;

ifstream fin("1.txt");
void gotoxy(int x, int y) //定位到第y行的第x列
{
    int xx=0x0b;
    HANDLE hOutput;
    COORD loc;
    loc.X = x;
    loc.Y=y;
    hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(hOutput, loc);
    return;
}
void AI(project a)
{
    srand(time(0));
    /*a.name=names[rand()%9];
    a.ATK=rand()%(100-50)+50;
    a.blood=rand()%(2000-1500)+1500;
    a.DEF=rand()%10;
    int y=rand()%100;
    if(y==1)
    {
        a.name=names[10];
        a.blood=10000;
        a.DEF=0;
        a.ATK=200;
    }*/
    a.y=3;
    a.x=rand()%58;
    while(1)
    {
        if(a.y<8)
        {
            a.y++;
        }
        if(a.x>=12&&a.y<12)
        {
            a.y++;
        }
        if(a.x==21)
        {
            a.y=9;
        }
        if(a.x==35)
        {
            a.y=9;
        }
        if(a.x>=50&&a.x<=58)
        {
            a.y=8;
        }
        if(a.x==28)
        {
            a.y=4;
        }
        if(a.x>=25&&a.y==3)
        {
            a.y=3;
        }

        if(a.y<player.y)
        {
            a.y-=2;
        }
        if(player.y<=a.y)
        {
            if(max(player.x-a.x,a.x-player.x)<2)
            {
                if(a.x-player.x>0)
                {
                    a.x--;
                }
                else
                {
                    a.x++;
                }   
            }
            else
            {
                a.gongjif=1;
                player.blood-=a.ATK;
                Sleep(100);
                a.gongjif=0;
            }
        }
    }
}
void AI2()
{
    AI(m[1]);
    AI(m[2]);
    AI(m[3]);
}
string c;
string l=" ";
void caozuo()
{
    while(1)
    {
        c=getch();
        if(c=="d")
        {
            if(player.x!=56)
            {
                if(player.x==20&&player.y>=10&&player.y<=12||(player.x==34&&player.y>=10&&player.y<=12)||(player.x==49&&player.y>=9&&player.y<=12))
                {
                }
                else
                {
                player.x++;
                }       
            }
        }
        if(c=="a")
        {
            if(player.x!=0)
            {
                if((player.x==7&&player.y>=9&&player.y<=12)||(player.x==22&&player.y>=10&&player.y<=12)||(player.x==36&&player.y>=10&&player.y<=12))
                {
                }
                else
                {
                player.x--;
                }
            }
        }
        if(c=="w")
        {
            if(player.y==12)
            {
                player.y-=3;
            }
        }
        if(c=="l")
        {
            gongji=1;
            Sleep(100);
            gongji=0; 
        }
        if(c=="j")
        {
            gongji=2;
            Sleep(100);
            gongji=0;
        }
    }
}
void zhongli()
{
    while(1)
    {
        if(player.y<8)
        {
            player.y++;
        }
        if(player.y<12)
        {
            player.y++;
        }
        if(player.x==21)
        {
            player.y=9;
        }
        if(player.x==35)
        {
            player.y=9;
        }
        if(player.x>=50&&player.x<=58)
        {
            player.y=8;
        }
        if(player.x==28)
        {
            player.y=2;
        }
        if(player.x>=25&&player.y==3)
        {
            player.y=3;
        }
        if(player.x<=12)
        {
            player.y=8;
        }
        Sleep(500);
    }
}
int main()
{

    system("color 70");
    thread t1(caozuo);
    thread t2(zhongli);
    thread t3(AI2);
    t1.detach(); 
    t2.detach();
    t3.detach();
    player.x=3;
    player.y=8;
     mapp[1]="                                                          ";
     mapp[2]="                                                          ";
     mapp[3]="                              |=|                            ";
     mapp[4]="                            |=|                            ";
     mapp[5]="                              |=|                            ";
     mapp[6]="                              |=|                          ";
     mapp[7]="                              |=|                            ";
     mapp[8]="       _____               |=|                            ";
     mapp[9]="■■■■ |=|                |=|                    ■■■■";
    mapp[10]="■    ■ |=|         ■    |=|     ■             ■    ■";
    mapp[11]="■    ■ |=|         ■    |=|     ■             ■    ■";
    mapp[12]="■    ■ |=|         ■    |=|     ■             ■    ■";
    mapp[13]="■■■■■■■■■■■■■■■■■■■■■■■■■■■■■";
    mapp[14]="                                                          ";
    mapp[15]="                                                          ";//58
    while(1)
    {
        gotoxy(0,0);
        for(int i=0;i<=15;i++)
        {
            cout<<mapp[i]<<endl;
        }
        gotoxy(player.x,player.y);
        cout<<f;
        gotoxy(m[1].x,m[1].y);
        cout<<q;
        gotoxy(m[2].x,m[2].y);
        cout<<q;
        gotoxy(m[3].x,m[3].y);
        cout<<q;
        if(gongji==1)
        {
            gotoxy(player.x+2,player.y);
            cout<<"-";
        }
        if(gongji==2)
        {
            gotoxy(player.x-1,player.y);
            cout<<"-";
        }
        if(m[1].gongjif==1)
        {
            gotoxy(m[1].x+2,m[1].y);
            cout<<"-";
            gotoxy(m[1].x-1,m[1].y);
            cout<<"-";
        }
        if(m[2].gongjif==2)
        {
            gotoxy(m[2].x-1,m[2].y);
            cout<<"-";
            gotoxy(m[2].x+2,m[2].y);
            cout<<"-";
        }
        if(m[3].gongjif==2)
        {
            gotoxy(m[3].x-1,m[3].y);
            cout<<"-";
            gotoxy(m[3].x+2,m[3].y);
            cout<<"-";
        }
    }
}

谁能告诉我为什么敌人的AI没有反应,也不能下落(下落代码在AI函数的前8个if中)
感谢Thanks♪(・ω・)ノ

  • 写回答

1条回答

  • 502203305 2019-05-10 17:09
    关注

    这里的函数定义有问题,如果是C++,可以使用引用类型,即project&类型。

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?