c++小游戏——职业战争2.0
背景简介
本文介绍了一个名为职业战争的小游戏qwq
是基于某大佬博客的二次创作~~
以下是本篇文章正文内容
一、职业有哪些?
目前游戏中加入的职业有杀手、医生、法师三个
二、具体代码实现
1.调试环境
环境为微软的Visual Studio 2015
2.代码实现
代码如下:
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<cstring>
#include<string>
#include<windows.h>
using namespace std;
int i, H[3], S[3], K[3], p = 1, Y, C;
string P[3];
bool game = 1;
void a(int i) {
for (; i; i--);
}
void help() {
cout << "杀手:\nHP:100\nSP:5\nkill:3\n";
cout << "医生:\nHP:75\nSP:7\nkill:2\n";
cout << "法师:\nHP:144\nSP:3\nkill:1\n";
cin >> i;
}
void killer() {
P[p] += "杀手";
H[p] = 100;
S[p] = 5;
K[p] = 3;
}
void doctor() {
P[p] += "医生";
H[p] = 75;
S[p] = 7;
K[p] = 2;
}
void engineer() {
P[p] += "法师";
H[p] = 144;
S[p] = 3;
K[p] = 1;
}
void e(int j) {
if (j == 2 && S[Y] >= 2) {
int w = rand() % 2;
if (Y == 1) cout << "你使用技能\n";
else cout << "电脑使用技能\n";
K[Y] += w;
cout << "攻击力(kill)+" << w << endl;
w = rand() % 5 - 1;
w = int(1.2*(K[Y] + w));
H[C] -= w;
if (H[C] <= 0) game = 0;
if (Y == 1) cout << "你杀了电脑 ";
else cout << "你被电脑杀了 ";
cout << w;
if (Y == 1) cout << endl;
S[Y] -= 2;
}
if (j == 3 && S[Y] >= 5) {
int w = rand() % 10;
if (Y == 1) cout << "你使用大杀特杀\n";
else cout << "电脑使用大杀特杀\n";
K[Y] += w;
cout << "攻击力(kill)+" << w << endl;
w = rand() % 5 - 1;
w = int(1.2*(K[Y] + w));
H[C] -= w;
if (H[C] <= 0) game = 0;
if (Y == 1) cout << "你杀了电脑 ";
else cout << "你被电脑杀了 ";
cout << w;
if (Y == 1) cout << endl;
S[Y] -= 5;
}
}
void k(int j) {
if (j == 2 && S[Y] >= 2) {
if (Y == 1) cout << "YOU 使用技能\n";
else cout << "The computer 使用技能\n";
int w = rand() % 4 + 1;
H[C] -= int(1.5*K[Y] + w);
if (H[C] <= 0) game = 0;
if (Y == 1) cout << "你杀了电脑 ";
else cout << "你被电脑杀了 ";
cout << int(1.5*K[Y] + w);
cout << endl;
S[Y] -= 2;
}
if (j == 3 && S[Y] >= 5) {
int w = rand() % 10;
if (Y == 1) cout << "你使用大杀特杀\n";
else cout << "电脑使用大杀特杀\n";
K[Y] += w;
cout << "攻击力(kill)+" << w << endl;
w = rand() % 5 - 1;
w = int(1.2*(K[Y] + w));
H[C] -= w;
if (H[C] <= 0) game = 0;
if (Y == 1) cout << "你杀了电脑 ";
else cout << "你被电脑杀了 ";
cout << w;
if (Y == 1) cout << endl;
S[Y] -= 5;
}
}
void d(int j) {
if (j == 2 && S[Y] >= 2) {
if (Y == 1) cout << "YOU 使用技能\n";
else cout << "The computer 使用技能\n";
int w = rand() % 5;
H[Y] += K[Y] + w;
if (Y == 1) cout << "YOU HP+";
else cout << "The computer HP+";
cout << K[Y] + w;
if (Y == 1) cout << endl;
S[Y] -= 2;
}
if (j == 3 && S[Y] >= 5) {
int w = rand() % 10;
if (Y == 1) cout << "你使用大杀特杀\n";
else cout << "电脑使用大杀特杀\n";
K[Y] += w;
cout << "攻击力(kill)+" << w << endl;
w = rand() % 5 - 1;
w = int(1.2*(K[Y] + w));
H[C] -= w;
if (H[C] <= 0) game = 0;
if (Y == 1) cout << "你杀了电脑 ";
else cout << "你被电脑杀了 ";
cout << w;
if (Y == 1) cout << endl;
S[Y] -= 5;
}
}
void play() {
system("cls");
cout << "Game start!!!!!!!!!!!!!!!!";
Sleep(500);
system("cls");
int r = 1, j;
// bool game=1;
while (game) {
Y = 1;
C = 2;
cout << "Round " << r << "\n";
Sleep(500);
cout << "The 电脑 HP:" << H[2] << " SP:" << S[2] << " kill:" << K[2] << "\t" << P[2];
cout << "\n\n\n\nYour HP:" << H[1] << " SP:" << S[1] << " kill:" << K[1] << "\t" << P[1];
Sleep(500);
cout << "\nYou choose:\n1.攻击(1SP)\n2.技能(2SP)\n3.大杀特杀(5SP)\n4.蓄力(+1~3SP)\n5.修炼(+0~2kill)\n6.挂机(0SP)\n";
cin >> j;
if (j == 1 && S[Y]>0) {
int w = rand() % 5 - 1;
S[Y]--;
H[C] -= K[Y] + w;
if (H[C] <= 0) game = 0;
cout << "You kill the computer" << K[Y] + w << endl;
}
else {
if (j == 4) {
int w = rand() % 3 + 1;
S[Y] += w;
cout << "YOU SP+" << w << endl;
}
else {
if (j == 5) {
int w = rand() % 3;
K[Y] += w;
cout << "YOU kill+" << w << endl;
}
else {
if (P[Y] == "杀手") k(j);
if (P[Y] == "医生") d(j);
if (P[Y] == "法师") e(j);
}
}
}
if (game) {
j = rand() % 6 + 1;
C = 1;
Y = 2;
while (j != 1 && j != 2 && j != 4 && j != 5) j = rand() % 6 + 1;
if (j == 1 && S[2]>1) {
int w = rand() % 5 - 1;
S[2]--;
H[1] -= K[2] + w;
if (H[1] <= 0) game = 0;
cout << "你被电脑杀了" << K[2] + w;
}
else {
if (j == 4) {
int w = rand() % 3 + 1;
S[2] += w;
cout << "The computer SP+" << w;
}
else {
if (j == 5) {
int w = rand() % 3;
K[2] += w;
cout << "The computer kill+" << w;
}
else {
if (P[Y] == "杀手") k(j);
if (P[Y] == "医生") d(j);
if (P[Y] == "法师") e(j);
}
}
}
if (game) Sleep(1000);
}
r++;
system("cls");
}
}
int main() {
srand((unsigned)time(NULL));
cout << "Welcome to my game!!!!!!!!!!!!\n";
Sleep(500);
system("cls");
cout << "Please choose:\n1.killer\n2.doctor\n3.engineer\n4.help\n";
cin >> i;
if (i == 4) help();
cout << "You choose ";
if (i == 1) killer();
if (i == 2) doctor();
if (i == 3) engineer();
cout << P[p] << endl;
i = rand() % 3 + 1;
p++;
cout << "The computer chooses ";
if (i == 1) killer();
if (i == 2) doctor();
if (i == 3) engineer();
cout << P[p] << endl;
system("pause");
play();
if (H[1] <= 0) cout << "YOU LOSE~~~~~~~~~~~~~~~~~";
else cout << "YOU WIN!!!!!!!!!!!!!!!!!!!";
getchar();
getchar();
return 0;
}
3.运行演示
开局
大招
普通攻击
获胜
小结
以上就是今天要讲的内容啦,看到这里不点个赞或者三连支持一下这个刚刚开始写博客的萌新博主嘛qwq
朋友们我们下期再见哦~~