C++枪战小游戏
2024-12-08 16:15:52
发布于:浙江
#include <bits/stdc++.h>
#include<conio.h>
#include<windows.h>
using namespace std;
int gj3 = 100, fy3 = 100, sm3 = 1000, gu = 1, sc = 0;
char* (s[]) = { "小刀","铁刀","铜刀","银刀","金刀","手枪","步枪","突击步枪","狙击枪","冲锋枪","藤甲","铁甲","铜甲","银甲","金甲" };
int sl[15] = { 0 }, ysl = 0, msx;
string name;
int sm1, sm2, gj1, gj2, fy1, fy2, rs = 999999, rw, gos, smc, rea, sr, srt, tes, sa, srf, srth; //smc是血量上限;
int gj[] = { 10,15,20,30,50,80,100,120,150,200,0,0,0,0,0 }, fy[] = { 0,5,10,15,20,0,0,0,0,0,20,30,50,80,100 }; //攻击、防御、数量、医疗箱数量
void bag()
{
int xz1, jx;
for (int i = 0; i < 15; i++)
{
cout << s << ": " << sl << "级" << endl;
}
cout << "医疗箱:" << ysl << "个" << endl << "0.退出 1.使用医疗箱" << endl;
cin >> xz1;
system("cls");
if (xz1 == 1) {
if (ysl == 0)
{
cout << "你没有医疗箱!" << endl;
Sleep(1000);
}
if (smc <= sm1)
{
cout << "你已满血!";
Sleep(1000);
}
else
{
jx = sm1 + 500;
if (jx > smc)
{
jx = smc;
}
sm1 = jx;
cout << "加血成功!";
Sleep(1000);
ysl--;
}
system("cls");
}
}
int into() {
srand(time(NULL));
sa = rand() % 16;
switch (sa)
{
case 15:
ysl++;
cout << "你捡到了医疗箱一级";
break;
default:
cout << "你捡到了" << s[sa] << "一级";
gj1 += gj[sa];
fy1 += fy[sa];
sl[sa]++;
break;
}
Sleep(1000);
system("cls");
return 0;
}
int unp()
{
int sm4, gj4, fy4;
cout << "第" << gu << "关" << endl;
cout << "你碰到了野兽" << endl;
Sleep(2000);
sm4 = sm3;
gj4 = gj3;
fy4 = fy3;
while (sm1 > 0 || sm4 > 0)
{
if (gj1 - fy4 <= 0)
{
cout << "他被打掉了0滴血,还剩" << sm4 << "滴血";
Sleep(1000);
system("cls");
sc++;
}
else
{
sm4 = sm4 - gj1 + fy4;
cout << "他被打掉了" << gj1 - fy4 << "滴血,还剩" << sm4 << "滴血";
Sleep(1000);
system("cls");
}
if (sm4 <= 0)
{
cout << "他死了!";
Sleep(1000);
system("cls");
into();
gu++;
return 0;
}
if (gj4 - fy1 <= 0)
{
cout << "你被打掉了0滴血,还剩" << sm1 << "滴血";
Sleep(1000);
system("cls");
sc++;
}
else
{
sm1 = sm1 - gj4 + fy1;
cout << "你被打掉了" << gj4 - fy1 << "滴血,还剩" << sm1 << "滴血";
Sleep(1000);
system("cls");
}
if (sc == 2)
{
cout << "你们打了个平手";
Sleep(1000);
system("cls");
into();
sc = 0;
return 0;
}
if (sm1 <= 0)
{
cout << "你死了!";
Sleep(1000);
system("cls");
return 0;
}
sc = 0;
}
gj3 += 50;
fy3 += 50;
sm3 += 100;
}
void puto()
{
srf = rand() % 15;
Sleep(199);
srth = rand() % 2;
if (srth == 1)
{
if (gj1 - srf < 0)
{
srf = gj1;
}
cout << "你丢失了" << srf << "点攻击力";
gj1 -= srf;
}
if (srth == 0)
{
if (fy1 - srf < 0)
{
srf = fy1;
}
cout << "你丢失了" << srf << "点防御力";
fy1 -= srf;
}
Sleep(1500);
system("cls");
}
int unf()
{
int gf, xzi, js = 0;
sm2 = rand() % 2200 + 800;
gj2 = rand() % 500 + 200;
fy2 = rand() % 300 + 10;
cout << "你碰到了一个人 1.战斗 2.逃跑" << endl;
cin >> tes;
gf = (gj2 - fy1) / 3;
if (tes == 2)
{
if (gf < 0)
{
gf = 0;
}
cout << "你还是被他打掉了" << gf << "滴血,然后逃脱成功!";
Sleep(1500);
system("cls");
sm1 -= gf;
}
if (tes == 1)
{
while (sm1 > 0 && sm2 > 0 && js != 1)
{
if (gj1 - fy2 <= 0)
{
cout << "他被打掉了0滴血,还剩" << sm2 << "滴血";
Sleep(1000);
system("cls");
sc++;
}
else
{
sm2 = sm2 - gj1 + fy2;
cout << "他被打掉了" << gj1 - fy2 << "滴血,还剩" << sm2 << "滴血";
Sleep(1000);
system("cls");
}
if (sm2 <= 0)
{
cout << "他死了!";
Sleep(1000);
system("cls");
rs--;
into();
return 0;
}
if (gj2 - fy1 <= 0)
{
cout << "你被打掉了0滴血,还剩" << sm1 << "滴血";
Sleep(1000);
system("cls");
sc++;
}
else
{
sm1 = sm1 - gj2 + fy1;
cout << "你被打掉了" << gj2 - fy1 << "滴血,还剩" << sm1 << "滴血";
Sleep(1000);
system("cls");
}
if (sc == 2)
{
cout << "你们打了个平手";
Sleep(1000);
system("cls");
into();
sc = 0;
}
sc = 0;
}
}
if (sm1 <= 0)
{
cout << "你死了!重新开始!";
Sleep(1000);
system("cls");
}
}
void sra()
{
sr = rand() % 9;
switch (sr)
{
case 0:
if (msx == 2)
{
unf();
}
else
{
unp();
}
break;
case 1:
into();
break;
case 2:
into();
break;
case 3:
puto();
break;
case 4:
puto();
break;
case 5:
puto();
break;
case 6:
puto();
break;
default:
cout << "你没有获得什么……";
Sleep(1000);
system("cls");
break;
}
}
int main()
{
srand(time(NULL));
cout << "你的名字:";
cin >> name;
system("cls");
aga:
cout << "0.退出游戏 1.开始游戏" << endl;
cin >> gos;
system("cls");
if (gos == 0) {
cout << "由似花还似飞花出品,欢迎再来!!";
Sleep(1500);
return 0;
}
retu:
while (1)
{
int sl[15] = { 0 }, ysl = 0;
if (msx == 2)
{
cout << "1.无限闯关模式 2.实战模式" << endl;
cin >> msx;
system("cls");
cout << name << ",生死枪战,现在开始!!";
Sleep(1500);
system("cls");
cout << "名字:" << name;
cout << endl << "(人越多越好玩)(包括你自己) " << "枪战人数:";
cin >> rs;
system("cls");
}
xz:
cout << "人物选择:" << endl;
cout << "1.步兵 生命:1000 攻击:50 防御:50" << endl;
cout << "2.丧尸 生命:1250 攻击:35 防御:40" << endl;
cout << "3.医生 生命:1500 攻击:20 防御:30" << endl;
cout << "4.铠甲人 生命:800 攻击:40 防御:80" << endl;
cin >> rw;
system("cls");
switch (rw)
{
case 1:
sm1 = 1000;
smc = 1000;
gj1 = 50;
fy1 = 50;
break;
case 2:
sm1 = 1250;
smc = 1250;
gj1 = 35;
fy1 = 40;
break;
case 3:
sm1 = 1500;
smc = 1500;
gj1 = 20;
fy1 = 30;
break;
case 4:
sm1 = 800;
smc = 800;
gj1 = 40;
fy1 = 80;
break;
default:
goto xz;
}
cout << "开局一抽奖" << endl;
Sleep(1500);
sr = rand() % 16;
switch (sr)
{
case 15:
ysl += 2;
cout << "你获得了医疗箱二级";
break;
default:
cout << "你获得了" << s[sr] << "二级";
gj1 += gj[sr] * 2;
fy1 += fy[sr] * 2;
sl[sr] += 2;
break;
}
Sleep(1000);
system("cls");
while (sm1 > 0 && rs > 1)
{
cout << "名字:" << name << endl;
cout << "生命:" << sm1 << endl;
cout << "攻击:" << gj1 << endl;
cout << "防御:" << fy1 << endl;
cout << "1.向前 2.向左 3.向右 4.向后 5.查看背包 6.退出" << endl;
cin >> rea;
system("cls");
if (rea == 6)
{
system("cls");
goto aga;
}
if (rea == 5)
{
bag();
}
if (rea >= 1 && rea <= 4)
{
sra();
}
}
if (sm1 > 0 && rs == 1)
{
cout << "你赢了!再来一局!" << endl;
Sleep(1000);
system("cls");
goto retu;
}
}
return 0;
}
全部评论 1
good
2024-12-09 来自 北京
0
有帮助,赞一个