C++实现双人枪战游戏
//单机版枪战游戏,喜欢就拿走,把赞留下
//by floatiy #include<iostream>
#include<cstdio>
#include<windows.h>
#include<conio.h>
using namespace std;
int SIZ = ;
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord; HANDLE hCon;
enum Color { DARKBLUE = , DARKGREEN, DARKTEAL, DARKRED, DARKPINK, DARKYELLOW, GRAY, DARKGRAY, BLUE, GREEN, TEAL, RED, PINK, YELLOW, WHITE };
void SetColor(Color c) {
if(hCon == NULL)
hCon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hCon, c);
} SYSTEMTIME sys; //sys.wYear,sys.wMonth,sys.wDay,sys.wHour,sys.wMinute, sys.wSecond,sys.wMilliseconds,sys.wDayOfWeek
struct PLAYER {
int x,y;
int hp;
int gun;
int direct;
} p1,p2;
int map[][]; int abs(int x) {
if(x < ) return -x;
return x;
} void locate(int x,int y) {
coord.X=y - ;
coord.Y=x - ;
SetConsoleCursorPosition(hout,coord);
} void print_map() {
locate(,);
SetColor(GRAY);
for(int i = ; i <= SIZ; i++) cout<<"■";
locate(SIZ,);
for(int i = ; i <= SIZ; i++) cout<<"■";
for(int i = ; i < SIZ; i++) {
locate(i,);
cout<<"■";
locate(i,SIZ*-);
cout<<"■";
}
locate(SIZ+,);
SetColor(WHITE);
} void create_tree(int x,int y) {
map[x][y] = map[x+][y] = map[x-][y] = map[x][y+] = map[x][y-] = ;
} void use_map(int x) {
if(x == ) {
SIZ = ;
SetColor(DARKGREEN);
map[][]=map[][]=map[][]=map[][]=map[][]=map[][]=map[][]=map[][]=;
for(int i = ; i < SIZ; i++) {
for(int j = ; j < SIZ; j++) {
if(map[i][j] == ) {
locate(i,j*-);
cout<<"■";
}
}
}
SetColor(GRAY);
for(int i = ; i <= ; i++) {
map[i][i] = ;
locate(i,i*-);
cout<<"■";
}
SetColor(WHITE);
} else if(x == ) {
SIZ = ;
SetColor(GRAY);
for(int i = ; i <= ; i++) {
if(i == || i == ||i == ) continue;
map[i][] = map[][i] = map[][i] = map[i][] = ;
}
for(int i = ; i <= SIZ; i++) {
for(int j = ; j <= SIZ; j++) {
if(map[i][j] == ) {
locate(i,j*-);
cout<<"■";
}
}
}
SetColor(DARKGREEN);
for(int i = ; i<=; i++) {
if(i == || i == ) continue;
map[i][] = map[][i] = map[][i] = map[i][] = ;
}
create_tree(,);
create_tree(,);
for(int i = ; i <= SIZ; i++) {
for(int j = ; j <= SIZ; j++) {
if(map[i][j] == ) {
locate(i,j*-);
cout<<"■";
}
}
}
SetColor(WHITE);
}
}
void cleanbody(int x,int y);
void putbody(int x,int y,int z); void player_init() {
p1.hp = p2.hp = ;
p1.gun = p2.gun = ;
p1.direct = ;
p2.direct = ;
p1.x = ;
p1.y = ;
p2.x = SIZ - ;
p2.y = SIZ - ;
putbody(p1.x,p1.y,);
putbody(p2.x,p2.y,);
} void mapinit() {
for(int i = ; i <= SIZ; i++) {
map[i][] = map[][i] = map[SIZ][i] = map[i][SIZ] = ;
}
} void init() {
printf("Use Which Map?\n");
int x;
cin>>x;
system("cls");
use_map(x);
mapinit();
print_map();
player_init();
} void putbody(int x,int y,int z) {
if(z == ) SetColor(BLUE);
else if(z == ) SetColor(RED);
locate(x,y*-);
cout<<"■";
SetColor(WHITE);
}
void cleanbody(int x,int y) {
locate(x,y*-);
cout<<" ";
}
/*
LIST
direct:
w 1
a 2
s 3
d 4
gun:
usp 1
mimigun 2
awp 3
block:
void 0
stone 1
tree 2
player 3
clip 4
*/
bool judge(int x,int y) {
if(map[x][y] == ) return false;
if(map[x][y] == ) return false;
if(map[x][y] == ) return false;
return true;
} bool judge_gun(int x,int y) {
if(map[x][y] == ) return ;
if(map[x][y] == ) return ;
if(map[x][y] == ) {
if(p1.x == x && p1.y == y) p1.hp -= ;//此处暂时不管威力
else p2.hp -= ;
return ;
}
return ;
} int cnt;
struct Clip {
int x,y;
int derect;
int force;
int start;
bool flag;
} clip[];
void create_clip(int y,int x,int a,int b) {
int X,Y;
if(y == ) {
if(!judge_gun(a-,b)) return;
X = a-;
Y = b;
} else if(y == ) {
if(!judge_gun(a,b-)) return;
X = a;
Y = b-;
} else if(y == ) {
if(!judge_gun(a+,b)) return;
X = a+;
Y = b;
} else if(y == ) {
if(!judge_gun(a,b+)) return;
X = a;
Y = b+;
}
cnt++;
GetLocalTime( &sys );
clip[cnt].start = sys.wMilliseconds + sys.wSecond * + sys.wHour * ;
clip[cnt].x = X;
clip[cnt].y = Y;
if(x == ) {
clip[cnt].derect = p1.direct;
} else if(x == ) {
clip[cnt].derect = p2.direct;
}
} void shoot(int x) {
if(x == ) {
create_clip(p1.direct,,p1.x,p1.y);
} else if(x == ) {
create_clip(p2.direct,,p2.x,p2.y);
}
} void clean_clip(int x,int y) {
locate(x,y*-);
cout<<" ";
locate(,);
} void print_clip(int x,int y,int i) {
if(clip[i].flag) {
clean_clip(x,y);
return;
}
locate(x,y*-);
SetColor(YELLOW);
cout<<"''";
locate(,);
// system("pause");
} void clipmove() {
GetLocalTime( &sys );
int t = sys.wMilliseconds + sys.wSecond * + sys.wHour * ;
for(int i = ; i <= cnt; i++) {
if(clip[i].flag) continue;
if(abs(clip[i].start - t) > ) {
clip[i].start = t;
int x = clip[i].x;
int y = clip[i].y;
if(clip[i].derect==) {
if(!judge_gun(clip[i].x-,clip[i].y)) {
clip[i].flag = ;
clean_clip(x,y);
continue;
}
clean_clip(clip[i].x,clip[i].y);
clip[i].x--;
print_clip(clip[i].x,clip[i].y,i);
} else if(clip[i].derect==) {
if(!judge_gun(clip[i].x,clip[i].y-)) {
clip[i].flag = ;
clean_clip(x,y);
continue;
}
clean_clip(clip[i].x,clip[i].y);
clip[i].y--;
print_clip(clip[i].x,clip[i].y,i);
} else if(clip[i].derect==) {
if(!judge_gun(clip[i].x+,clip[i].y)) {
clip[i].flag = ;
clean_clip(x,y);
continue;
}
clean_clip(clip[i].x,clip[i].y);
clip[i].x++;
print_clip(clip[i].x,clip[i].y,i);
} else if(clip[i].derect==) {
if(!judge_gun(clip[i].x,clip[i].y+)) {
clip[i].flag = ;
clean_clip(x,y);
continue;
}
clean_clip(clip[i].x,clip[i].y);
clip[i].y++;
print_clip(clip[i].x,clip[i].y,i);
}
}
}
} void judge_hp() {
int x = p1.hp;
int y = p2.hp;
if(x< && y< && x > y) swap(x,y);
if(x <= ) {
locate(,);
system("cls");
printf("GAME OVER!\nTHE WINNER IS P2!");
Sleep();
printf("\n-MADE BY Floatiy-");
exit();
} else if(y <= ) {
locate(,);
system("cls");
printf("GAME OVER!\nTHE WINNER IS P1!");
Sleep();
printf("\n-MADE BY Floatiy-");
exit();
}
} void prog() {
char ch;
while(true) {
if(kbhit()) {
ch=getch();
if(ch == 'w' && judge(p1.x-,p1.y)) {
p1.direct = ;
cleanbody(p1.x,p1.y);
map[p1.x][p1.y] = ;
putbody(--p1.x,p1.y,);
map[p1.x][p1.y] = ;
} else if(ch == '' && judge(p2.x-,p2.y)) {
p2.direct = ;
cleanbody(p2.x,p2.y);
map[p2.x][p2.y] = ;
putbody(--p2.x,p2.y,);
map[p2.x][p2.y] = ;
} else if(ch == 'a' && judge(p1.x,p1.y-)) {
p1.direct = ;
cleanbody(p1.x,p1.y);
map[p1.x][p1.y] = ;
putbody(p1.x,--p1.y,);
map[p1.x][p1.y] = ;
} else if(ch == '' && judge(p2.x,p2.y-)) {
p2.direct = ;
cleanbody(p2.x,p2.y);
map[p2.x][p2.y] = ;
putbody(p2.x,--p2.y,);
map[p2.x][p2.y] = ;
} else if(ch == 's' && judge(p1.x+,p1.y)) {
p1.direct = ;
cleanbody(p1.x,p1.y);
map[p1.x][p1.y] = ;
putbody(++p1.x,p1.y,);
map[p1.x][p1.y] = ;
} else if(ch == '' && judge(p2.x+,p2.y)) {
p2.direct = ;
cleanbody(p2.x,p2.y);
map[p2.x][p2.y] = ;
putbody(++p2.x,p2.y,);
map[p2.x][p2.y] = ;
} else if(ch == 'd' && judge(p1.x,p1.y+)) {
p1.direct = ;
cleanbody(p1.x,p1.y);
map[p1.x][p1.y] = ;
putbody(p1.x,++p1.y,);
map[p1.x][p1.y] = ;
} else if(ch == '' && judge(p2.x,p2.y+)) {
p2.direct = ;
cleanbody(p2.x,p2.y);
map[p2.x][p2.y] = ;
putbody(p2.x,++p2.y,);
map[p2.x][p2.y] = ;
} else if(ch == '') {
shoot();
} else if(ch == ' ') {
shoot();
}
Sleep();
}
clipmove();
judge_hp();
}
} void welcome() {
printf("操作方法:\n玩家1 wasd控制移动,空格攻击\n玩家2 数字小键盘4568控制移动,0攻击\n");
Sleep();
} int main() {
welcome();
GetLocalTime( &sys );
init();
prog();
return ;
}
C++实现双人枪战游戏的更多相关文章
- C++游戏(大型PC端枪战游戏)服务器架构
实习期间深入参与到某大型pc端枪战游戏的后端开发中,此游戏由著名游戏工作室编写,代码可读性极高,自由时间对游戏后台代码进行了深入研究,在满足自身工作需要的同时对游戏后台的架构也有了理解,记录在此,以便 ...
- 少儿编程Scratch第三讲:宇宙大战.枪战游戏
小朋友这周的表现还算不错.周末多数时间都由我陪(bi)着(zhe)做课本上的数学题,后来还学了英语.任重道远啊,语数外都还得加强,还远不到自己就能取得好成绩的阶段. 上周说好这周要做一个发射炮弹的游戏 ...
- 【Unity3D】枪战游戏—弹孔设置
以子弹为原点,发射射线,如果射线检测到障碍物,则返回射线与障碍物的碰撞点 在该点处实例化出弹孔贴图 void Update () { transform.Translate (Vector3.forw ...
- 【Unity3D】枪战游戏—发射子弹、射线检测
一.子弹的碰撞检测: 因为子弹的移动速度非常的快,那么如果为子弹添加一个collider,就有可能检测不到了. 因为collider是每一帧在执行,第一帧子弹可能在100米处,那么下一帧就在900米处 ...
- Pascal小游戏 双人射击
一个双人的游戏 Pascal源码附上 只要俩人不脑残,一下午玩不完...又是控制台游戏中的一朵奇葩. Free Pascal 射击游戏 Program shooting_game; uses crt; ...
- Unity3D_(游戏)双人3D坦克_简易版
双人3D坦克实现 player1: WSAD控制上下左右 空格键发射炮弹 player2: IKJL可控制上下左右 B键发射炮弹 每个坦克只有100hp,子弹击中1次扣30hp,hp时时显示在坦克上 ...
- 对使命召唤OL游戏中队友能相互救治的动作设定的感慨
很偶然的在网吧看到有人在玩一个枪战游戏,场景特别真实特别吸引人,后来留意到是使命召唤OL.我使用QQ帐号(是腾讯代理)玩了一次,觉得游戏做的确实精致,子弹打击效果和人物被子弹击中的效果特别真实,大家可 ...
- Atitit. 常用街机系统and 模拟器总结 snk neo geo cps mame sfc smc
Atitit. 常用街机系统and 模拟器总结 snk neo geo cps mame sfc smc 1. #-------常用 游戏类型 1 2. 街机的历史 2 3. #=========== ...
- bzoj2940: [Poi2000]条纹
2940: [Poi2000]条纹 条纹游戏是一个双人的游戏.所需要的物品有一个棋盘以及三种颜色的长方形条纹,这三种颜色分别是红色.绿色和蓝色.所有的红色条纹的尺寸是c*1,所有的绿色条纹的尺寸是z* ...
随机推荐
- 20170620_javaweb_小结
01.session失效的方式 02. session和cookie的区别 03.jsp九大内置对象,意义 以及对应的java类 04.转发和重定向 05.jsp的执行过程 和 生命周期 06.实现s ...
- 【OI】向量&矩阵乘法
何为向量? 在初中课本中,我们知道: 向量是有大小和方向的量. 这样解释太笼统了,现在我们只讨论平面上的向量. 那么,我们约定:在平面上的向量,由一个二元组组成:如α(c1,c2). 在此平面上建立一 ...
- nginx搭建基于http协议的视频点播服务器
1,于由自己的服务器上已经安装好nginx(具体安装方法见我的另一篇文章,Linux中安装nginx),所以不再安装. 2,下载nginx_mod_h264_streaming-2.2.7.tar.g ...
- 51. ExtJs4之Ext.util.JSON编码和解码JSON对象
转自:https://blog.csdn.net/iteye_9439/article/details/82518158 1.decode() 该方法用于将符合JSON格式的String进行解码成为一 ...
- Is the Information Reliable?(差分约束系统)
http://poj.org/problem?id=2983 题意:给出M条信息,判断这些信息的正确性.(1)V A B :表示A,B之间的距离>=1; (2)P A B X :表示A B之间的 ...
- 9.12NOIP模拟题
NOIP 2017 全假模拟冲刺 hkd 题目名称 Spfa 走楼梯缩小版 滑稽 题目类型 传统 传统 传统 ...
- 高德,百度,Google地图定位偏移以及坐标系转换
一.在进行地图开发过程中,我们一般能接触到以下三种类型的地图坐标系: 1.WGS-84原始坐标系 一般用国际GPS纪录仪记录下来的经纬度,通过GPS定位拿到的原始经纬度,Google和高德地图定位的的 ...
- MySQL-ProxySQL中间件(一)| ProxySQL基本概念
目录 MySQL-ProxySQL中间件(一)| ProxySQL基本概念: https://www.cnblogs.com/SQLServer2012/p/10972593.html ...
- ASP.NET MVC5 之 Log4Net 的学习和使用
最近在学习 log4Net 插件,在博客园找到了好多资料,但是实现起来还是有点麻烦. 现在记录下学习的过程,期间可能加载着借鉴和转载的代码. 1.配置文件的设置: 新建config文件夹下 log4n ...
- flask中内置的session
Flask中的Session非常的奇怪,他会将你的SessionID存放在客户端的Cookie中,使用起来也非常的奇怪 1. Flask 中 session 是需要 secret_key 的 from ...