糖尿病康复,内容丰富有趣,生活中的好帮手!
糖尿病康复 > 5.1[潜心创作]逃跑吧少年·追击游戏

5.1[潜心创作]逃跑吧少年·追击游戏

时间:2020-05-12 22:08:46

相关推荐

5.1[潜心创作]逃跑吧少年·追击游戏

本人自创了一个游戏,不喜勿喷...

#include<bits/stdc++.h>

#include<winsock2.h>

#include<windows.h>

#include<conio.h>

#include<time.h>

#define Height 30

#define Width 120

#define Exit 6

#define Door 5

#define Box 4

#define Tree 3

#define Grass 2

#define Wall 1

#define Road 0

#define Up 1

#define Down 2

#define Left 3

#define Right 4

#define Up1 5

#define Down1 6

#define Left1 7

#define Right1 8

#define Flash 9

#define Chase 10

#define Medkit 11

#define Energy 12

#define Incantation 13

#define FearFrighten 14

using namespace std;

HWND hwnd=GetForegroundWindow();

char chart_compare[100][200]={

"************************************************************************************************************************",

"* ****************** ## ### ######### *",

"* T## T **###### ** ***** *",

"* ### ### --****#** B * T*",

"* ##### #*# B T * *-- T *",

"* T###**** -**####T # *",

"* ## ### ## ###* *-- ### # *",

"*#*** #*** * T#### *********### # *",

"* ###* ##*** ## *",

"* *-- T * T## ******** ****** *",

"* ** ### #**************** ### ***-- T ##* ***T ****************",

"* # #**** #*#* * ****************",

"******* * * * T**######*----* ## * ** *",

"* *----* ###****##** ## ** ** *",

"* ###**** --******+*",

"* --*****##**************** ** *",

"* *-- T##*********** ****** T ** *",

"******* * * ### *****************",

"* ## # ### ****************",

"* #* T ****###* *",

"* *** * #*### *",

"** **** *** #*** T #*** *** * *###*** ###*",

"** * * #** * ** *#*#T###* *",

"* T ** --* * #** *#- #*##*#* *",

"* # * #* #*#####**",

"* T# --* **-- T*",

"* **** * B * * * B ####### *",

"* **** ********* * * T****** *",

"************************************************************************************************************************",

};

int chart[100][200];

int si=15,sj=3;

int pi=15,pj=102;

int Slife=20,Plife=20;

int Money=100,Money1=100;

void gotoxy(int x,int y)

{

COORD coord;

coord.X=x;

coord.Y=y;

SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);

}

void hidden()

{

HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);

CONSOLE_CURSOR_INFO cci;

GetConsoleCursorInfo(hOut,&cci);

cci.bVisible=0;

SetConsoleCursorInfo(hOut,&cci);

}

void clear()

{

system("pause");

system("cls");

}

int get_key()

{

char c;

while(c=getch())//a97 b98 c99 d100 e101 f102 g103 h104 i105 j106 k107 l108 m109 n110 o111 p112 q113 r114 s115 t116 u117 v118 w119 x120 y121 z122

{

if(c!=-32)

{

if(c==119)

{

return Up;

}

if(c==115)

{

return Down;

}

if(c==97)

{

return Left;

}

if(c==100)

{

return Right;

}

if(c==105)

{

return Flash;

}

if(c==101)

{

return Chase;

}

if(c==111)

{

return Medkit;

}

if(c==114)

{

return Energy;

}

if(c==112)

{

return Incantation;

}

if(c==116)

{

return FearFrighten;

}

}

c=getch();

if(c==72)

{

return Up1;

}

if(c==80)

{

return Down1;

}

if(c==75)

{

return Left1;

}

if(c==77)

{

return Right1;

}

}

return 0;

}

void paint(int x,int y)

{

gotoxy(y-1,x-1);

switch(chart[x][y])

{

case Wall:

{

printf("*");

break;

}

case Road:

{

printf(" ");

break;

}

case Grass:

{

printf("#");

break;

}

case Tree:

{

printf("T");

break;

}

case Box:

{

printf("B");

break;

}

case Door:

{

printf("-");

break;

}

case Exit:

{

printf("+");

break;

}

}

}

int check_reward(int i,int j)

{

if(chart[i-1][j]==Box)

{

return 1;

}

if(chart[i+1][j]==Box)

{

return 2;

}

if(chart[i][j-1]==Box)

{

return 3;

}

if(chart[i][j+1]==Box)

{

return 4;

}

return 0;

}

void set_box()

{

srand(time(0));

int seti=rand()%(Height-3)+1,setj=rand()%(Width-3)+1;

while(chart[seti][setj]!=Road)

{

seti=rand()%(Height-3)+1;

setj=rand()%(Width-3)+1;

}

chart[seti][setj]=Box;

}

bool hurt()

{

if(si==pi&&sj==pj)

{

return true;

}

return false;

}

bool died()

{

if(Slife<=0)

{

return true;

}

return false;

}

bool reward(int i,int j)

{

if(chart[i+1][j]==Box||chart[i-1][j]==Box||chart[i][j+1]==Box||chart[i][j-1]==Box)

{

return true;

}

return false;

}

bool no_box()

{

for(int i=1;i<Height;i++)

{

for(int j=1;j<=Width;j++)

{

if(chart[i][j]==Box)

{

return false;

}

}

}

return true;

}

bool Pursuer_died()

{

if(Plife<=0)

{

return true;

}

return false;

}

bool distance()

{

if(abs(si-pi)+abs(sj-pj)<=10)

{

return true;

}

return false;

}

void play()

{

int c;

bool Fflag=false,Cflag=false;

time_t start,end;

time_t start1,end1;

time_t start2,end2;

bool vertigo=false,vertigo1=false,die=false;

while(1)

{

hidden();

gotoxy(sj-1,si-1);

if(chart[si][sj]!=Grass)

{

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);

printf("o");

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN);

}

gotoxy(pj-1,pi-1);

if(chart[pi][pj]!=Grass)

{

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE);

printf("@");

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN);

}

gotoxy(0,Height+1);

cout<<"Survivor's HP : ";

for(int i=1;i<=Slife;i++)

{

cout<<'*';

}

cout<<" ";

cout<<endl<<"Pursuer 's HP : ";

for(int i=1;i<=Plife;i++)

{

cout<<'+';

}

cout<<" "<<endl;

cout<<"Survivor's money : "<<Money<<""<<endl;

cout<<"Pursuer 's money : "<<Money1<<""<<endl;

cout<<"Survivor's shop : 1、Flash(150$)(i) 2、Medkit(188$)(o) 3、Incantation (200$)(p)"<<endl;

cout<<"Pursuer 's shop : 1、Chase(150$)(e) 2、Energy(188$)(r) 3、FearFrighten(200$)(t)"<<endl;

c=get_key();

switch(c)

{

case Up:

if(vertigo1==true)

{

end1=clock();

if((end1-start1)<500)

{

break;

}

}

if(chart[si-1][sj]==Road||chart[si-1][sj]==Grass)

{

paint(si,sj);

si--;

}

if(Fflag==true)

{

paint(si,sj);

si=max(2,si-5);

while(chart[si][sj]!=Road&&chart[si][sj]!=Grass)

{

si++;

}

Fflag=false;

}

break;

case Down:

if(vertigo1==true)

{

end1=clock();

if((end1-start1)<500)

{

break;

}

}

if(chart[si+1][sj]==Road||chart[si+1][sj]==Grass)

{

paint(si,sj);

si++;

}

if(Fflag==true)

{

paint(si,sj);

si=min(si+5,Height-1);

while(chart[si][sj]!=Road&&chart[si][sj]!=Grass)

{

si--;

}

Fflag=false;

}

break;

case Left:

if(vertigo1==true)

{

end1=clock();

if((end1-start1)<500)

{

break;

}

}

if(chart[si][sj-1]==Road||chart[si][sj-1]==Grass)

{

paint(si,sj);

sj--;

}

if(Fflag==true)

{

paint(si,sj);

sj=max(2,sj-9);

while(chart[si][sj]!=Road&&chart[si][sj]!=Grass)

{

sj++;

}

Fflag=false;

}

break;

case Right:

if(vertigo1==true)

{

end1=clock();

if((end1-start1)<500)

{

break;

}

}

if(chart[si][sj+1]==Road||chart[si][sj+1]==Grass)

{

paint(si,sj);

sj++;

}

if(Fflag==true)

{

paint(si,sj);

sj=min(sj+9,Width-1);

while(chart[si][sj]!=Road&&chart[si][sj]!=Grass)

{

sj--;

}

Fflag=false;

}

break;

case Up1:

if(vertigo==true)

{

end=clock();

if((end-start)<1000)

{

break;

}

}

if(die==true)

{

end2=clock();

if((end2-start2)<5000)

{

break;

}

}

if(chart[pi-1][pj]==Road||chart[pi-1][pj]==Grass)

{

paint(pi,pj);

pi--;

}

if(Cflag==true)

{

paint(pi,pj);

pi=max(2,pi-5);

while(chart[pi][pj]!=Road&&chart[pi][pj]!=Grass)

{

pi++;

}

Cflag=false;

}

break;

case Down1:

if(vertigo==true)

{

end=clock();

if((end-start)<1000)

{

break;

}

}

if(die==true)

{

end2=clock();

if((end2-start2)<5000)

{

break;

}

}

if(chart[pi+1][pj]==Road||chart[pi+1][pj]==Grass)

{

paint(pi,pj);

pi++;

}

if(Cflag==true)

{

paint(pi,pj);

pi=min(pi+5,Height-1);

while(chart[pi][pj]!=Road&&chart[pi][pj]!=Grass)

{

pi--;

}

Cflag=false;

}

break;

case Left1:

if(vertigo==true)

{

end=clock();

if((end-start)<1000)

{

break;

}

}

if(die==true)

{

end2=clock();

if((end2-start2)<5000)

{

break;

}

}

if(chart[pi][pj-1]==Road||chart[pi][pj-1]==Grass)

{

paint(pi,pj);

pj--;

}

if(Cflag==true)

{

paint(pi,pj);

pj=max(2,pj-9);

while(chart[pi][pj]!=Road&&chart[pi][pj]!=Grass)

{

pj++;

}

Cflag=false;

}

break;

case Right1:

if(vertigo==true)

{

end=clock();

if((end-start)<1000)

{

break;

}

}

if(die==true)

{

end2=clock();

if((end2-start2)<5000)

{

break;

}

}

if(chart[pi][pj+1]==Road||chart[pi][pj+1]==Grass)

{

paint(pi,pj);

pj++;

}

if(Cflag==true)

{

paint(pi,pj);

pj=min(pj+9,Width-1);

while(chart[pi][pj]!=Road&&chart[pi][pj]!=Grass)

{

pj--;

}

Cflag=false;

}

break;

case Flash:

if(Money>=150)

{

Money-=150;

Fflag=true;

}

break;

case Chase:

if(die==true)

{

end2=clock();

if((end2-start2)<5000)

{

break;

}

}

if(Money1>=150)

{

Money1-=150;

Cflag=true;

}

break;

case Medkit:

if(Money>=188)

{

Money-=188;

Slife=min(20,Slife+3);

}

break;

case Energy:

if(die==true)

{

end2=clock();

if((end2-start2)<5000)

{

break;

}

}

if(Money1>=188)

{

Money1-=188;

Plife=min(20,Plife+3);

}

break;

case Incantation:

if(Money>=200&&distance())

{

Money-=200;

Plife=max(0,Plife-3);

vertigo=true;

start=clock();

}

break;

case FearFrighten:

if(die==true)

{

end2=clock();

if((end2-start2)<5000)

{

break;

}

}

if(Money1>=200&&distance())

{

Money1-=200;

Slife=max(0,Slife-3);

vertigo1=true;

start1=clock();

}

break;

}

if(hurt())

{

Slife-=5;

Money1+=200;

}

if(died())

{

clear();

cout<<"Runner failed";

break;

}

int choose_money[15]={88,88,88,88,188,188,188,288,288,588},choose=rand()%10+1;

if(reward(si,sj))

{

int direction=check_reward(si,sj);

Money+=choose_money[choose];

if(direction==1)

{

chart[si-1][sj]=Road;

}

if(direction==2)

{

chart[si+1][sj]=Road;

}

if(direction==3)

{

chart[si][sj-1]=Road;

}

if(direction==4)

{

chart[si][sj+1]=Road;

}

}

if(reward(pi,pj))

{

int direction=check_reward(pi,pj);

Money1+=choose_money[choose];

if(direction==1)

{

chart[pi-1][pj]=Road;

}

if(direction==2)

{

chart[pi+1][pj]=Road;

}

if(direction==3)

{

chart[pi][pj-1]=Road;

}

if(direction==4)

{

chart[pi][pj+1]=Road;

}

}

if(no_box())

{

set_box();

for(int i=1;i<Height;i++)

{

for(int j=1;j<=Width;j++)

{

paint(i,j);

}

}

}

if(Pursuer_died())

{

Plife=20;

die=true;

start2=clock();

}

}

}

int main()

{

ShowWindow(hwnd,SW_MAXIMIZE);

cout<<"Get new game——Run teenager!"<<endl;

cout<<"注释·逃生者技能:1、Flash 闪现 2、Medkit 急救包 3、Incantation 咒术"<<endl;

cout<<" 追击者技能:1、Chase 追击 2、Energey 能量 3、FearFrighten 恐惧震慑"<<endl;

for(int i=0;i<Height;i++)

{

for(int j=0;j<Width;j++)

{

if(chart_compare[i][j]==' '||chart_compare[i][j]=='#')

{

if(chart_compare[i][j]==' ')

{

chart[i+1][j+1]=Road;

}

else

{

chart[i+1][j+1]=Grass;

}

}

else

{

if(chart_compare[i][j]=='*')

{

chart[i+1][j+1]=Wall;

}

if(chart_compare[i][j]=='T')

{

chart[i+1][j+1]=Tree;

}

if(chart_compare[i][j]=='B')

{

chart[i+1][j+1]=Box;

}

if(chart_compare[i][j]=='-')

{

chart[i+1][j+1]=Door;

}

if(chart_compare[i][j]=='+')

{

chart[i+1][j+1]=Exit;

}

}

}

}

clear();

for(int i=1;i<Height;i++)

{

for(int j=1;j<=Width;j++)

{

paint(i,j);

}

}

play();

return 0;

}

如果觉得《5.1[潜心创作]逃跑吧少年·追击游戏》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。