一款双人对打游戏(c++)

这是一款使用C++编程语言开发的双人对打游戏,博主分享了其在空闲时间创作的成果,并表示代码仍有改进空间。游戏旨在提供娱乐体验,源代码已公开。
摘要由CSDN通过智能技术生成

我无聊打出来的,有待提高,请见谅。

#include<iomanip>
#include<iostream>
#include<conio.h>
#include<windows.h>
#include<cstdio>
#include<vector>
#include<cstring>
#include<string>

#define bottom 40
#define jumph 6
#define skills 6
#define skilled 2
#define Setcolor(NAME) if(NAME)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_GREEN | BACKGROUND_BLUE);else SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE | FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_GREEN | BACKGROUND_BLUE)
#define Backcolor(NAME) if(NAME)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE | FOREGROUND_INTENSITY | BACKGROUND_INTENSITY | BACKGROUND_GREEN | BACKGROUND_BLUE)
#define Choosecolor(NAME) if(NAME==2)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED| FOREGROUND_GREEN|FOREGROUND_BLUE | FOREGROUND_INTENSITY|BACKGROUND_BLUE );else if(!NAME)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE | FOREGROUND_RED| BACKGROUND_INTENSITY| BACKGROUND_GREEN|BACKGROUND_RED|BACKGROUND_BLUE );else if(NAME==1)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE | FOREGROUND_INTENSITY | BACKGROUND_INTENSITY| BACKGROUND_GREEN|BACKGROUND_RED)

using namespace std;

void HideCursor();
void go(int x, int y);
void movewindow();
void GetContain();
void start1();
void start2();
void _skillprint(int, int);
void skillprint(int,int);
void mapprint();
void Getmove();
void winprint(bool);
void BoomGet();
class bullet;
class player;

bool dj1, dj2, s11, s12, s21, s22;
int da1, da2,skill1[2] = { 4,3 }, skill2[2] = {2,4}, boom1, boom2, cost[10] = {0,3,3,5,15},place[11][2][2],explace[11][2];//[技能数字][属于][x,y坐标]
float cool[2][2];
char hit[2];
string name1, name2,contain[11],excontain[11];
vector<bullet>bu;
class player {
public:
int x, y, j, jh, life,loving,flying,gaying;
char a, b[2];
bool dir, fly, myself,fdir;
//dir:0为左,1为右
void clear() {
go(x, y);
printf(" ");
go(x, y + 1);
printf(" ");
}
void print() {
Setcolor(myself);
if (gaying)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE|FOREGROUND_RED | BACKGROUND_INTENSITY | BACKGROUND_GREEN | BACKGROUND_BLUE);
go(x, y);
if (loving) {
Setcolor(!myself);
cout << (char)3;
Setcolor(myself);
}
else if (gaying)cout << "♂";
else cout << a;
go(x, y + 1);
cout << b[dir];
Backcolor(myself);
}
void lifedown(int l) {
if (!myself) {
go(life - l+1, 2);
for (int i = 1; i <= l; ++i)
cout << " ";
}
else {
go(188 - life, 2);
for (int i = 1; i <= l; ++i)
cout << " ";
}
life -= l;
}
void jump() {
++j;
if (j <= jh) {
clear();
--y;
print();
}
else fly = 1;
}
void flown() {
++flying;
clear();
if (flying <= jumph-1)--y;
else if (flying <= 2 * jumph-2)++y;
else flying = 0;
if (!fdir)x-=2;
else x+=2;
if (x < 1)x = 1;
else if (x > 188)x = 188;
print();
}
void skill(int,bool);
void attack();
void move(int);
} p1, p2;
class bullet {
public:
int x, y, boom,length,soap;
bool own, dir, love;
inline void clear() {
go(x, y);
cout << " ";
}
void print() {
Setcolor(own);
go(x, y);
if (boom)cout << (char)15;
else if (love)cout << (char)3;
else if (soap) cout << "▅";
else cout << hit[own];
Backcolor(own);
}
void start(int p, int q, bool d, bool o) {
y = q;
dir = d;
own = o;
if (!d)x = p - 1;
else x = p + 1;
boom = 0;
love = 0;
length = 0;
soap = 0;
}
void boomstart(int p, int q, bool d, bool o,int l) {
y = q + 1;
dir = d;
own = o;
if (!d)x = p - 1;
else x = p + 1;
boom = 1;
length = l;
love = 0;
}
bool fly() {
if (boom >= 800) {
if (boom == 805) {
for (int i = -4; i <= 4; i += 2)
for (int j = -2; j <= 2; ++j) {
if (x + i < 1 || x + i>188 || y + j > bottom + 1)continue;
go(x + i, y + j);
cout << " ";
}
p1.print();
p2.print();
return 1;

}++boom;
return 0;
}
if(soap!=-1)clear();
if (!dir)--x;
else ++x;
if (boom) {
if (!dir)x-=length;
else x+=length;
}
if (boom) {
++boom;
char _sign = 4;
if (x < 1 || x>188) {
Setcolor(own);
for (int i = -4; i <= 4; i += 2)
for (int j = -2; j <= 2; ++j) {
if (x + i < 1 || x + i>188 || y + j > bottom + 1)continue;
go(x + i, y + j);
cout <<_sign ;
}
Backcolor(own);
if (!own)
{
if (x >= p2.x - 4 && x <= p2.x + 4 && y+2 >= p2.y&&y-2 <= p2.y + 1) {
p2.lifedown(10);
if (x > p2.x)p2.fdir = 0;
else p2.fdir = 1;
p2.flown();
}
}
else {
if (x >= p1.x - 4 && x <= p1.x + 4 && y + 2 >= p1.y&&y - 2 <= p1.y + 1) {
p1.lifedown(10);
if (x >= p1.x)p1.fdir = 0;
else p1.fdir = 1;
p1.flown();
}
}
boom = 800;
return 0;
}
if (boom <= 2 * jumph+length)--y;
else if (boom > 2 * jumph + 2+length) {
if (y <= bottom)++y;
else {
Setcolor(own);
for (int i = -4; i <= 4; i += 2)
for (int j = -2; j <= 2; ++j) {
if (x + i < 1 || x + i>188 || y + j > bottom + 1)continue;
go(x + i, y + j);
cout << _sign
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值