《绝地求生2》
最新版本,最强大版本,同时也是最刺激版本的控制台《绝地求生》!
操作说明就不写了,自己领悟。
Here is the code of the second version:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string.h>
#include <stdio.h>
#include <cstdlib>
#include <stdlib.h>
#include <windows.h>
#include <time.h>
#include <conio.h>
using namespace std;
const int number_of_kinds_of_normal_weapon = 7;
const int number_of_kinds_of_kt_weapon = 3;
struct Weapon {
string name;
int attack;
int number_of_bullet;
int find;
int kind;
};
Weapon normal_weapons[number_of_kinds_of_normal_weapon] =
{
{"M1911", 10, 7, 1, 1},
{"MP5", 20, 25, 2, 1},
{"AK47", 30, 30, 3, 1},
{"S12K", 40, 5, 4, 1},
{"AWM", 50, 5, 5, 1},
{"匕首", 8, 0, 6, 0},
{"平底锅", 20, 0, 7, 0}
};
Weapon kt_weapons[number_of_kinds_of_kt_weapon] =
{
{"大刀", 30, 0, 1, 0},
{"HK416", 35, 20, 2, 1},
{"M82A1", 80, 10, 3, 1}
};
struct Player {
string name;
int hp;
Weapon weapon[4];
int weapon_now;
int number_of_weapon;
string clothes;
string hat;
string bag;
string things[20];
int number_of_things;
int max_number_of_things;
int juli_safe;
int juli_kt;
int kill;
};
Player self;
struct Enemy {
int hp;
Weapon weapon_now;
string clothes;
string hat;
};
Enemy enemy;
int number_of_player;
int number_of_handle;
int safe_round;
bool kt;
bool self_run_away;
void procedure();
void init();
void mainMenu();
void activityMenu();
void over();
void showSlowly(char[]);
int suiJi();
void self_init();
void self_die();
void self_run();
void self_getThings();
void self_daYao();
void self_look();
void self_meet_kt();
void self_meet_enemy();
void self_attack();
void self_runAway();
void self_changeWeapon();
void enemy_init();
void enemy_attack();
int main()
{
procedure();
return 0;
}
void procedure()
{
showSlowly("欢迎来到绝地求生!\n\n");
showSlowly("请输入你的名字(不含空格):");
cin >> self.name;
cout << endl;
showSlowly("按任意键开始游戏......");
getch();
mainMenu();
}
void init()
{
showSlowly("请输入玩家人数(最多100人,最少10人):");
cin >> number_of_player;
if (number_of_player < 10 or number_of_player > 100) {
showSlowly("输入错误,系统自动为您更正,玩家人数为100人。\n");
number_of_player = 100;
}
cout << endl;
showSlowly("正在匹配......匹配成功......即将开始! ");
kt = false;
number_of_handle = 0;
safe_round = 5000;
self_init();
activityMenu();
}
void mainMenu()
{
system("cls");
cout << " 主菜单" << endl;
cout << "####################" << endl;
cout << " 1.匹配一把 2.退出" << endl;
cout << "####################" << endl;
char ch = getch();
if (ch == '1') init();
else if (ch == '2') over();
else mainMenu();
}
void activityMenu()
{
while (number_of_player > 1) {
number_of_handle++;
system("cls");
showSlowly("距离绝对安全区还有");
cout << self.juli_safe;
showSlowly("米!\n\n");
showSlowly("毒圈半径");
cout << safe_round;
showSlowly("米!\n\n");
if (kt == true) {
showSlowly("距离空投还有");
cout << self.juli_kt;
showSlowly("米!\n\n");
if (self.juli_kt == 0) {
showSlowly("你已找到空投! ^o^\n\n");
kt = false;
int s = suiJi()%10+1;
if (s <= 4) {
showSlowly("可是空投物资被别人抢了。QwQ\n\n");
}else{
self_meet_kt();
}
}
}
showSlowly("要做什么?\n\n1.跑毒 2.捡东西 3.打药 4.查看状态\n\n");
char ch;
do {
ch = getch();
}while(not(ch >= '1' and ch <= '4'));
if (ch == '4') {
do {
self_look();
showSlowly("要做什么?\n\n1.跑毒 2.捡东西 3.打药 4.查看状态\n\n");
ch = getch();
}while(ch == '4');
}
if (ch == '1') {
self_run();
}else if (ch == '2') {
self_getThings();
}else if (ch == '3') {
self_daYao();
}
if (number_of_handle%4 == 0 and safe_round > 500) {
safe_round -= 500;
showSlowly("毒圈半径减小500米!\n\n");
}
if (self.juli_safe > safe_round) {
self.hp -= 8;
showSlowly("你在毒圈外,hp减少8!\n\n");
if (self.hp <= 0) {
self_die();
}
}
if (number_of_handle == 5) {
kt = true;
self.juli_kt = 1000;
showSlowly("空投已投下!\n\n");
}
if (number_of_player > 2) {
int s = suiJi()%5+1;
number_of_player -= s;
if (number_of_player < 2) {
number_of_player = 2;
}
}
showSlowly("剩余");
cout << number_of_player;
showSlowly("人。\n\n");
system("pause");
}
showSlowly("大吉大利,今晚吃鸡!\n\n按任意键返回主菜单......");
getch();
mainMenu();
}
void over()
{
showSlowly("正在退出......");
exit(0);
}
void showSlowly(char text[])
{
int len = strlen(text);
for (int i=0; i<len; i++) {
cout << text[i];
Sleep(100);
}
}
int suiJi()
{
srand((unsigned)time(0));
return rand();
}
void self_init()
{
self.bag = "无";
self.clothes = "无";
self.hat = "无";
self.hp = 100;
self.juli_kt = 0;
self.juli_safe = 4000;
self.max_number_of_things = 5;
self.number_of_things = 0;
self.number_of_weapon = 0;
for (int i=0; i<20; i++) {
self.things[i] = "无";
}
for (int i=0; i<4; i++) {
self.weapon[i].name = "无";
self.weapon[i].attack = 0;
self.weapon[i].find = 0;
self.weapon[i].number_of_bullet = 0;
}
self.weapon_now = 0;
self.kill = 0;
}
void self_die()
{
cout << self.name;
showSlowly("阵亡!\n\n排名:");
cout << number_of_player+1;
showSlowly("\n\n");
showSlowly("再接再厉,下次吃鸡!\n\n按任意键返回主菜单......");
getch();
mainMenu();
}
void self_run()
{
showSlowly("正在跑毒......\n\n");
if (self.juli_safe > 0) {
self.juli_safe -= 200;
}
if (self.juli_kt > 0 and kt == true) {
self.juli_kt -= 200;
}
int s = suiJi()%10+1;
if (s <= 4) {
self_meet_enemy();
}
}
void self_getThings()
{
showSlowly("正在寻找物资......\n\n");
int s;
s = suiJi()%10+1;
if (s <= 2) {
showSlowly("这里没有任何物资!\n\n");
}else{
char ch;
showSlowly("发现");
s = suiJi()%17+1;
for (int i=0; i<number_of_kinds_of_normal_weapon; i++) {
if (normal_weapons[i].find == s) {
cout << normal_weapons[i].name;
showSlowly("!\n\n是否拾取?y/n\n\n");
do {
ch = getch();
}while(ch != 'y' and ch != 'n');
if (ch == 'y') {
if (normal_weapons[i].kind == 0) {
self.weapon[3] = normal_weapons[i];
}else{
bool none = false;
for (int j=0; j<3; j++) {
if (self.weapon[j].name == "无") {
none = true;
self.weapon[j] = normal_weapons[i];
self.number_of_weapon++;
break;
}
}
if (none == false) {
showSlowly("你的武器装备已满,请选择你要丢掉的武器:\n\n");
for (int j=0; j<3; j++) {
cout << j+1 << "." << self.weapon[j].name << ' ' << "子弹:" << self.weapon[j].number_of_bullet << endl;
}
cout << "4.算了吧\n\n";
do {
ch = getch();
}while(not(ch >= '1' and ch <= '4'));
if (ch == '1') {
self.weapon[0] = normal_weapons[i];
}else if (ch == '2') {
self.weapon[1] = normal_weapons[i];
}else if (ch == '3') {
self.weapon[2] = normal_weapons[i];
}
}
}
showSlowly("装备成功!\n\n");
}else{
showSlowly("你没有拾取。\n\n");
}
break;
}
}
if (s == 8) {
showSlowly("药!\n\n是否拾取?y/n\n\n");
do {
ch = getch();
}while(ch != 'y' and ch != 'n');
if (ch == 'y') {
if (self.number_of_things == self.max_number_of_things) {
showSlowly("背包已满!\n\n是否丢掉某样东西?\n\n");
int i;
for (i=0; i<self.number_of_things; i++) {
cout << i+1 << '.' << self.things[i] << endl;
}
cout << i+1 << ".算了吧\n\n";
int cho;
do {
cin >> cho;
}while(not(cho >= 1 and cho <= i+1));
cout << endl;
if (cho <= i) {
self.things[cho-1] = "药";
showSlowly("拾取成功!\n\n");
}
}else{
self.things[self.number_of_things] = "药";
self.number_of_things++;
showSlowly("拾取成功!\n\n");
}
}else{
showSlowly("你没有拾取。\n\n");
}
}else if (s == 9) {
showSlowly("一级头盔!\n\n是否拾取?y/n\n\n");
do {
ch = getch();
}while(ch != 'y' and ch != 'n');
if (ch == 'y') {
self.hat = "一级";
showSlowly("你戴起了一级头盔。\n\n");
}
}else if (s == 10) {
showSlowly("二级头盔!\n\n是否拾取?y/n\n\n");
do {
ch = getch();
}while(ch != 'y' and ch != 'n');
if (ch == 'y') {
self.hat = "二级";
showSlowly("你戴起了二级头盔。\n\n");
}
}else if (s == 11) {
showSlowly("三级头盔!\n\n是否拾取?y/n\n\n");
do {
ch = getch();
}while(ch != 'y' and ch != 'n');
if (ch == 'y') {
self.hat = "三级";
showSlowly("你戴起了三级头盔。\n\n");
}
}else if (s == 12) {
showSlowly("一级背包!\n\n是否拾取?y/n\n\n");
do {
ch = getch();
}while(ch != 'y' and ch != 'n');
if (ch == 'y') {
self.bag = "一级";
self.max_number_of_things = 10;
showSlowly("你背起了一级背包。\n\n");
}
}else if (s == 13) {
showSlowly("二级背包!\n\n是否拾取?y/n\n\n");
do {
ch = getch();
}while(ch != 'y' and ch != 'n');
if (ch == 'y') {
self.bag = "二级";
self.max_number_of_things = 15;
showSlowly("你背起了二级背包。\n\n");
}
}else if (s == 14) {
showSlowly("三级背包!\n\n是否拾取?y/n\n\n");
do {
ch = getch();
}while(ch != 'y' and ch != 'n');
if (ch == 'y') {
self.bag = "三级";
self.max_number_of_things = 20;
showSlowly("你背起了三级背包。\n\n");
}
}else if (s == 15) {
showSlowly("一级防弹衣!\n\n是否拾取?y/n\n\n");
do {
ch = getch();
}while(ch != 'y' and ch != 'n');
if (ch == 'y') {
self.clothes = "一级";
showSlowly("你穿上了一级防弹衣。\n\n");
}
}else if (s == 16) {
showSlowly("二级防弹衣!\n\n是否拾取?y/n\n\n");
do {
ch = getch();
}while(ch != 'y' and ch != 'n');
if (ch == 'y') {
self.clothes = "二级";
showSlowly("你穿上了二级防弹衣。\n\n");
}
}else if (s == 17) {
showSlowly("三级防弹衣!\n\n是否拾取?y/n\n\n");
do {
ch = getch();
}while(ch != 'y' and ch != 'n');
if (ch == 'y') {
self.clothes = "三级";
showSlowly("你穿上了三级防弹衣。\n\n");
}
}
}
}
void self_daYao()
{
if (self.hp < 100) {
bool find = false;
for (int i=0; i<self.number_of_things; i++) {
if (self.things[i] == "药") {
find = true;
showSlowly("正在打药......\n\n你的hp增加了30。\n\n");
self.hp += 30;
if (self.hp > 100) {
self.hp = 100;
}
for (int j=i; j<self.number_of_things-1; j++) {
self.things[j] = self.things[j+1];
}
self.things[self.number_of_things-1] = "无";
self.number_of_things--;
break;
}
}
if (find == false) {
showSlowly("你没有药!\n\n");
}
}else{
showSlowly("hp满不用打药。\n\n");
}
}
void self_look()
{
cout << self.name << endl;
cout << "生命值:" << self.hp << endl;
cout << "武器:"<< endl;
if (self.number_of_weapon > 0 or self.weapon[3].name != "无") {
for (int i=0; i<self.number_of_weapon; i++) {
cout << self.weapon[i].name << ' ' << "子弹:" << self.weapon[i].number_of_bullet << endl;
}
if (self.weapon[3].name != "无") {
cout << self.weapon[3].name << endl;
}
}else{
cout << "无" << endl;
}
cout << "防具:" << self.hat << "头盔 " << self.clothes << "防弹衣" << endl;
cout << "背包:" << self.bag << "背包" << endl;
cout << "物品:" << endl;
if (self.number_of_things > 0) {
for (int i=0; i<self.number_of_things; i++) {
cout << self.things[i] << ' ';
if (i%2 == 1) {
cout << endl;
}
}
}else{
cout << "无" << endl;
}
cout << endl;
cout << endl;
system("pause");
}
void self_meet_kt()
{
showSlowly("空投物资有:\n\n");
int s = suiJi()%3;
cout << kt_weapons[s].name << endl;
showSlowly("是否拾取?y/n\n\n");
char ch;
do {
ch = getch();
}while(ch != 'y' and ch != 'n');
if (ch == 'y') {
if (kt_weapons[s].kind == 0) {
self.weapon[3] = kt_weapons[s];
showSlowly("装备成功!\n\n");
}else{
if (self.number_of_weapon == 3) {
showSlowly("你的武器装备满了,请选择你要丢掉的武器:\n\n");
for (int i=0; i<3; i++) {
cout << i+1 << '.' << self.weapon[i].name << " 子弹:" << self.weapon[i].number_of_bullet << endl;
}
cout << "4.算了吧" << endl;
do {
ch = getch();
}while(not(ch >= '1' and ch <= '4'));
if (ch == '4') {
showSlowly("你错过了仅有的一个空投哦~\n\n");
}else{
for (int i=0; i<3; i++) {
if (ch == i+49) {
self.weapon[i] = kt_weapons[s];
break;
}
}
showSlowly("装备成功!\n\n");
}
}else{
self.number_of_weapon++;
self.weapon[self.number_of_weapon-1] = kt_weapons[s];
showSlowly("装备成功!\n\n");
}
}
}else{
showSlowly("你错过了仅有的一个空投哦~\n\n");
}
}
void self_meet_enemy()
{
showSlowly("发现敌人!\n\n");
self_run_away = false;
enemy_init();
while (enemy.hp > 0) {
showSlowly("该怎么办?\n\n1.攻击 2.打药 3.逃跑 4.查看状态 5.切换武器\n\n");
char ch;
do {
ch = getch();
if (ch == '1') {
self_attack();
}else if (ch == '2') {
self_daYao();
}else if (ch == '3') {
self_runAway();
}else if (ch == '4') {
self_look();
showSlowly("该怎么办?\n\n1.攻击 2.打药 3.逃跑 4.查看状态 5.切换武器\n\n");
}else if (ch == '5') {
self_changeWeapon();
showSlowly("该怎么办?\n\n1.攻击 2.打药 3.逃跑 4.查看状态 5.切换武器\n\n");
}
}while(not(ch >= '1' and ch <= '3'));
if (self_run_away == true) {
break;
}
if (enemy.hp <= 0) {
self.kill++;
number_of_player--;
showSlowly("你淘汰了一个玩家!\n\n");
cout << self.kill;
showSlowly("淘汰\n\n");
break;
}else{
enemy_attack();
}
if (self.hp <= 0) {
break;
}
}
if (self.hp <= 0) {
self_die();
}
}
void self_attack()
{
if (self.number_of_weapon == 0 and self.weapon[3].name == "无") {
showSlowly("你没有武器!\n\n");
}else{
if (self.weapon[self.weapon_now].number_of_bullet == 0 and self.weapon[self.weapon_now].kind == 1) {
showSlowly("没子弹了!\n\n");
}else{
cout << self.name;
if (self.weapon[self.weapon_now].kind == 1) {
showSlowly("开火!\n\n");
int s = suiJi()%10+1;
self.weapon[self.weapon_now].number_of_bullet--;
if (s <= 6) {
showSlowly("命中目标!\n\n");
int temp = enemy.hp;
enemy.hp -= self.weapon[self.weapon_now].attack;
if (enemy.hat == "一级") {
enemy.hp += 5;
}else if (enemy.hat == "二级") {
enemy.hp += 10;
}else if (enemy.hat == "三级") {
enemy.hp += 15;
}
if (enemy.clothes == "一级") {
enemy.hp += 2;
}else if (enemy.clothes == "二级") {
enemy.hp += 5;
}else if (enemy.clothes == "三级") {
enemy.hp += 7;
}
if (enemy.hp < 0) {
enemy.hp == 0;
}else if (enemy.hp > temp) {
enemy.hp = temp;
}
showSlowly("敌人的hp减少了");
cout << temp-enemy.hp;
showSlowly("!\n\n");
}else{
showSlowly("没打中!\n\n");
}
}else{
showSlowly(":我砍死你!\n\n");
int temp = enemy.hp;
enemy.hp -= self.weapon[self.weapon_now].attack;
if (enemy.hat == "一级") {
enemy.hp += 5;
}else if (enemy.hat == "二级") {
enemy.hp += 10;
}else if (enemy.hat == "三级") {
enemy.hp += 15;
}
if (enemy.clothes == "一级") {
enemy.hp += 2;
}else if (enemy.clothes == "二级") {
enemy.hp += 5;
}else if (enemy.clothes == "三级") {
enemy.hp += 7;
}
if (enemy.hp < 0) {
enemy.hp == 0;
}else if (enemy.hp > temp) {
enemy.hp = temp;
}
showSlowly("敌人的hp减少了");
cout << temp-enemy.hp;
showSlowly("!\n\n");
}
}
}
}
void self_runAway()
{
int s = suiJi()%10+1;
if (s <= 4) {
showSlowly("逃跑成功!\n\n");
self_run_away = true;
}else{
showSlowly("逃跑失败,敌人追上来了!\n\n");
}
}
void self_changeWeapon()
{
if (self.number_of_weapon == 0 and self.weapon[3].name == "无") {
showSlowly("你没有武器!\n\n");
}else{
showSlowly("请选择武器:\n\n");
int s = 0;
for (int i=0; i<4; i++) {
if (self.weapon[i].name != "无") {
s++;
cout << s << "." << self.weapon[i].name << " 子弹:" << self.weapon[i].number_of_bullet << endl;
}
}
cout << "\n\n";
int ch;
do {
cin >> ch;
}while(not(ch >= 1 and ch <= s));
s = 0;
for (int i=0; i<4; i++) {
if (self.weapon[i].name != "无") {
s++;
if (s == ch) {
self.weapon_now = i;
showSlowly("切换成功!\n\n");
break;
}
}
}
}
}
void enemy_init()
{
int s;
s = suiJi()%100+1;
enemy.hp = s;
s = suiJi()%3+1;
if (s == 1) {
enemy.hat = "三级";
}else if (s == 2) {
enemy.hat = "二级";
}else{
enemy.hat = "一级";
}
s = suiJi()%3+1;
if (s == 1) {
enemy.clothes = "三级";
}else if (s == 2) {
enemy.clothes = "二级";
}else{
enemy.clothes = "一级";
}
s = suiJi()%7;
enemy.weapon_now = normal_weapons[s];
s = suiJi()%100+1;
enemy.hp = s;
cout << "敌人头戴" << enemy.hat << "头盔,身穿" << enemy.clothes << "防弹衣,手持" << enemy.weapon_now.name << "!\n\n";
}
void enemy_attack()
{
if (enemy.weapon_now.name == "匕首") {
showSlowly("敌人砍你一刀!\n\n");
}else if (enemy.weapon_now.name == "平底锅") {
showSlowly("敌人给你一平底锅!\n\n");
}else{
if (enemy.weapon_now.number_of_bullet > 0) {
showSlowly("敌人向你开火!\n\n");
}else{
showSlowly("哈哈,敌人没子弹了!\n\n");
}
}
if (enemy.weapon_now.kind == 1 and enemy.weapon_now.number_of_bullet > 0) {
enemy.weapon_now.number_of_bullet--;
int s = suiJi()%10+1;
if (s <= 6) {
showSlowly("你被击中了!\n\n");
int temp = self.hp;
self.hp -= enemy.weapon_now.attack;
if (self.hat == "一级") {
self.hp += 5;
}else if (self.hat == "二级") {
self.hp += 10;
}else if (self.hat == "三级") {
self.hp += 15;
}
if (self.clothes == "一级") {
self.hp += 2;
}else if (self.clothes == "二级") {
self.hp += 5;
}else if (self.clothes == "三级") {
self.hp += 7;
}
if (self.hp < 0) {
self.hp == 0;
}else if (self.hp > temp) {
self.hp = temp;
}
showSlowly("你的hp减少了");
cout << temp-self.hp;
showSlowly("!\n\n");
if (self.hp == 0) {
self_die();
}
}else{
showSlowly("但是没有击中你。\n\n");
}
}else if (enemy.weapon_now.kind == 0){
int temp = self.hp;
self.hp -= enemy.weapon_now.attack;
if (self.hat == "一级") {
self.hp += 5;
}else if (self.hat == "二级") {
self.hp += 10;
}else if (self.hat == "三级") {
self.hp += 15;
}
if (self.clothes == "一级") {
self.hp += 2;
}else if (self.clothes == "二级") {
self.hp += 5;
}else if (self.clothes == "三级") {
self.hp += 7;
}
if (self.hp < 0) {
self.hp == 0;
}else if (self.hp > temp) {
self.hp = temp;
}
showSlowly("你的hp减少了");
cout << temp-self.hp;
showSlowly("!\n\n");
if (self.hp == 0) {
self_die();
}
}
}