//类型:开放世界/丧尸/生存
//地图大小:18*18
//实际大小(除去建筑):318
#include<algorithm>
#include<fstream>
#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<windows.h>
#include<conio.h>
#include <time.h>
#include <stdlib.h>
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include <windows.h>
#include <stdlib.h>
#include <time.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0) //必要的,要背下来
using namespace std;
//1: 竖的边界 2: 横的边界 3:墙
//was移动,空格攻击,f换弹,q吃东西(必须在安全屋),s饮水(必须在安全屋),v踢腿(和丧尸在一起时)
//视角:第一人称伪3D
int go=1;//移动判定
int cmoounity[20][20];
int first_food;
int first_water;
bool biu;//判断是否开枪
bool kick;//判断是否踢腿
int kill;
int zd;
int food;
int water;
int x,y;
int dx,dy;
int fx=1;
int x_what(int x) {//取随机数srand((unsigned)time(NULL));return( rand() % x);
}
int building_build() {for(int i=0; i<20; i++) {for(int j=0; j<20; j++) {if(j==0||j==19) {cmoounity[i][j]=1;}if(i==0||i==19) {cmoounity[i][j]=2;}}}for(int i=14; i<20; i++) {cmoounity[13][i]=3;}
}
int player_and_AI() {dx=x_what(11);dy=x_what(18);dx++;dy++;x=18;y=18;food=200;water=200;
}
int open() {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE);cout<<"_____________________"<<endl;cout<<"| |"<<endl;cout<<"| |"<<endl;cout<<"| by:用爱发电 |"<<endl;cout<<"| |"<<endl;cout<<"| |"<<endl;cout<<"|___________________|"<<endl;Sleep(2000);system("cls");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"_____________________"<<endl;cout<<"| |"<<endl;cout<<"| |"<<endl;cout<<"| by:黑客小C |"<<endl;cout<<"| |"<<endl;cout<<"| |"<<endl;cout<<"|___________________|"<<endl;Sleep(2000);system("cls");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"_____________________"<<endl;cout<<"| |"<<endl;cout<<"| 丧尸城市 |"<<endl;cout<<"|by:用爱发电&黑客小C|"<<endl;cout<<"| 任意键开始 |"<<endl;cout<<"| |"<<endl;cout<<"|___________________|"<<endl;while(!kbhit()) {}system("cls");fx=1;
}
int out_map() {if(kick==false&&biu==false) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"_____________________"<<endl;cout<<"| ************** |"<<endl;cout<<"| ************** |"<<endl;cout<<"| ************** |"<<endl;cout<<"| *************";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );cout<<"*** ";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"|"<<endl;cout<<"| ************** ";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );cout<<"*";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"|"<<endl;cout<<"|___________________|"<<endl;} else if(kick==true) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"_____________________"<<endl;cout<<"| ************** |"<<endl;cout<<"| ************** |"<<endl;cout<<"| ************** |"<<endl;cout<<"| ************** |"<<endl;cout<<"| ************** |"<<endl;cout<<"|___________________|"<<endl;} else if(biu==true) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"_____________________"<<endl;cout<<"| ************** |"<<endl;cout<<"| ************** |"<<endl;cout<<"| ************** |"<<endl;cout<<"| **************";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );cout<<"***";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"|"<<endl;cout<<"| ************** ";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );cout<<"*";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"|"<<endl;cout<<"|___________________|"<<endl;}
}
int out_AI() {if(kick==false&&biu==false) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"_____________________"<<endl;cout<<"| *** |"<<endl;cout<<"| *** |"<<endl;cout<<"| ***** |"<<endl;cout<<"| * ";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );cout<<"*** ";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"|"<<endl;cout<<"| * * ";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );cout<<"*";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"|"<<endl;cout<<"|___________________|"<<endl;} else if(kick==true) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"_____________________"<<endl;cout<<"| *** |"<<endl;cout<<"| *** |"<<endl;cout<<"| ***** |"<<endl;cout<<"| *** |"<<endl;cout<<"| * *** |"<<endl;cout<<"|___________________|"<<endl;} else if(biu==true) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"_____________________"<<endl;cout<<"| *** |"<<endl;cout<<"| *** |"<<endl;cout<<"| ***** |"<<endl;cout<<"| * *";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );cout<<"***";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"|"<<endl;cout<<"| * * ";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );cout<<"*";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"|"<<endl;cout<<"|___________________|"<<endl;}
}
int out_no() {if(kick==false&&biu==false) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"_____________________"<<endl;cout<<"| |"<<endl;cout<<"| |"<<endl;cout<<"| |"<<endl;cout<<"| ";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );cout<<"*** ";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"|"<<endl;cout<<"| ";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );cout<<"*";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"|"<<endl;cout<<"|___________________|"<<endl;}if(kick==true) {cout<<"_____________________"<<endl;cout<<"| |"<<endl;cout<<"| |"<<endl;cout<<"| ** |"<<endl;cout<<"| ** |"<<endl;cout<<"| ** |"<<endl;cout<<"|___________________|"<<endl;} else if(biu==true) {SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"_____________________"<<endl;cout<<"| |"<<endl;cout<<"| |"<<endl;cout<<"| |"<<endl;cout<<"| *";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );cout<<"***";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"|"<<endl;cout<<"| ";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );cout<<"*";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"|"<<endl;cout<<"|___________________|"<<endl;}
}
int sw() {//丧尸死亡dx=x_what(11);dy=x_what(18);dx++;dy++;kill++;
}
int play() {char cz;biu=false;kick=false;if(kbhit()) {cz=getch();if(cz=='a') {if(fx>1) {fx--;} else {fx=4;}}if(cz=='d') {if(fx<4) {fx++;} else {fx=1;}}if(cz=='w') {if(fx==1&&cmoounity[y][x-1]==0) {x--;}if(fx==2&&cmoounity[y-1][x]==0) {y--;}if(fx==3&&cmoounity[y][x+1]==0) {x++;}if(fx==4&&cmoounity[y+1][x]==0) {y++;}}if(cz==' '&&zd>0) {biu=true;zd--;if(fx==1&&y==dy&&x>dx) {sw();}if(fx==2&&y<dy&&x==dx) {sw();}if(fx==3&&y==dy&&x<dx) {sw();}if(fx==4&&y>dy&&x==dx) {sw();}}if(cz=='f') {zd=20;}if(x>14&&cz=='q'&&food<200&&first_food>=1000) {food+=31;first_food-=1000;}if(x>14&&cz=='s'&&water<200&&first_water>=500) {water+=11;first_water-=500;}if(cz=='v') {kick=true;if(x==dx&&y==dy) {sw();}food-=2;}}
}
int AI() {int dfx;if(go%8!=0) {return 0;}dfx=x_what(4);dfx++;if(dfx==1&&cmoounity[dy][dx-1]==0) {dx--;}if(dfx==2&&cmoounity[dy+1][dx]==0) {dy++;}if(dfx==3&&cmoounity[dy][dx+1]==0) {dx++;}if(dfx==4&&cmoounity[dy-1][dx]==0) {dy--;}
}
int before() {system("cls");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"购买食物(克):";cin>>first_food;cout<<"购买水(毫升):";cin>>first_water;system("cls");
}
int out() {int yn_no=0;system("cls");cout<<"击杀丧尸数量:"<<kill;cout<<"饥饿:"<<food<<"口渴"<<water<<endl;cout<<"子弹:"<<zd<<" ";if(fx==1) {cout<<"方向:西";}if(fx==2) {cout<<"方向:北";}if(fx==3) {cout<<"方向:东";}if(fx==4) {cout<<"方向:南";}cout<<endl;cout<<"玩家"<<x<<","<<y<<" ";cout<<"附近丧尸"<<dx<<","<<dy<<endl;for(int i=0; i<=3; i++) {if(fx==1&&cmoounity[y][x-i]!=0) {out_map();yn_no=1;break;} else if(fx==2&&cmoounity[y-i][x]!=0) {out_map();yn_no=1;break;} else if(fx==3&&cmoounity[y][x+i]!=0) {out_map();yn_no=1;break;} else if(fx==4&&cmoounity[y+i][x]!=0) {out_map();yn_no=1;break;} else if(fx==1&&y==dy&&x==dx+i) {out_AI();yn_no=1;break;} else if(fx==2&&x==dx&&y==dy-i) {out_AI();yn_no=1;break;} else if(fx==3&&y==dy&&x==dx-i) {out_AI();yn_no=1;break;} else if(fx==4&&x==dx&&y==dy+i) {out_AI();yn_no=1;break;}}if(yn_no==0) {out_no();}
}
int main() {open();building_build();player_and_AI();before();while(true) {out();play();AI();Sleep(10);go++;if(dx==x&&dy==y&&go%20==0) {system("cls");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"_____________________"<<endl;cout<<"| |"<<endl;cout<<"| game over |"<<endl;cout<<"| |"<<endl;cout<<"| ";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );cout<<"*** ";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"|"<<endl;cout<<"| ";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );cout<<"*";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"|"<<endl;cout<<"|___________________|"<<endl;Sleep(2000);return 0;}food--;water--;if(food<=0||water<=0) {system("cls");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"_____________________"<<endl;cout<<"| |"<<endl;cout<<"| game over |"<<endl;cout<<"| |"<<endl;cout<<"| ";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );cout<<"*** ";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"|"<<endl;cout<<"| ";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );cout<<"*";SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);cout<<"|"<<endl;cout<<"|___________________|"<<endl;Sleep(2000);return 0;}}
}