废话不说看代码
#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♪(・ω・)ノ