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&类型。

    评论

报告相同问题?

悬赏问题

  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B