DEVC++伪3D小游戏丧尸城市

news/2024/11/30 9:51:29/
//类型:开放世界/丧尸/生存
//地图大小: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;}}
}


http://www.ppmy.cn/news/888624.html

相关文章

手柄映射软件_生化危机3该用哪款游戏手柄?北通宙斯给你四维游戏体验

4月3日&#xff0c;生化危机3&#xff1a;重制版重磅上线&#xff0c;不少玩家提出&#xff0c;此作十分适合手柄操作&#xff0c;通过一款好手柄&#xff0c;体验可以达到前所未有的高度。然而,目前手柄市场品种繁多,质量也参差不齐&#xff0c;稍一不慎便会花钱买教训。那么怎…

自创文字小游戏《人类末日·丧尸危机》

这个游戏有很多坑哦&#xff0c;其他就没什么要注意的啦。 你不要以为你以为的就是对的&#xff01; 有些关卡不能通关纯属运气&#xff01;&#xff01;&#xff01;最多10次就可以通关啦&#xff01;&#xff01;&#xff01; 代码在哪里&#xff1f; #include <bits/…

Android Vector(矢量图)介绍

Android Vector(矢量图)介绍 1、vector的宽高属性 <vector xmlns:android"http://schemas.android.com/apk/res/android"android:width"24dp"android:height"24dp"android:viewportWidth"24"android:viewportHeight"24"…

【InsCode Stable Diffusion 美图活动一期】生成着玩

此为内容创作模板&#xff0c;请按照格式补充内容&#xff0c;在发布之前请将不必要的内容删除 一、 Stable Diffusion 模型在线使用地址&#xff1a; https://inscode.csdn.net/inscode/Stable-Diffusion 二、模型相关版本和参数配置&#xff1a; 三、图片生成提示词与反向…

北京光纤宽带接入

公司资质和资源 我公司是北京市目前最具实力的ISP之一&#xff0c;具有丰富的INTERNET接入资源和优秀的施工及维护能力。可以在遍布北京市及全国的所有地区实施快速高质量的专线和光纤线路的开通工作。 我公司目前有10G(北网通-CHINANET)20G(南电信-CHINANET)200M(联通)200M&am…

宽带城域网

宽带城域网 广域网&#xff08;Wide Area Network&#xff0c;缩写为 WAN&#xff09; 又称广域网、外网、公网。是连接不同地区局域网或城域网计算机通信的远程网。通常跨接很大的物理范围&#xff0c;所覆盖的范围从几十公里到几千公里&#xff0c;它能连接多个地区、城市和…

Python练习 | 鬼画符门之大师兄恋爱

题目名称&#xff1a;鬼画符门之大师兄恋爱 时间限制&#xff1a;1000ms 内存限制&#xff1a;256M 题目描述&#xff1a; 鬼画符门&#xff0c;每年都会统计自己宗门鬼画符消耗的数量。 往年一直是大师兄管理。 但是大师兄谈恋爱了&#xff01;&#xff01;怎么能让这种事…

按关键词全网采集

简数采集器支持按关键词全网采集&#xff0c;只需输入对应关键词&#xff0c;即可在全网采集相关数据&#xff0c;类似搜索引擎&#xff0c;无需用户配置采集规则。 简数采集器按关键词泛采集可用于舆情监控、市场研究分析等。 使用方法如下&#xff1a; 目录 1. 创建关键词…