《绝地求生》
新版本!非常刺激!有空投!
以下是代码:
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cstdlib> #include <windows.h> #include <time.h> #include <conio.h> #include <cmath> using namespace std; int number_of_people; int safe_round; int number_of_handle; int player_hp; int target_hp; bool kt; int juli_kt; void init(); void procedure(); void menu(); void show(char[]); void end(); void target_active(); void target_init(); void target_meetPlayer(); int suiJi(); class Player { public: int hp; string name; string wu_qi; int number_of_bullet; string wu_pin[20]; int number_of_wu_pin; string bag; int max_number_of_wu_pin; int handle; int ju_li; void active() { move(); } void init() { hp = 100; wu_qi = "拳头"; number_of_wu_pin = 0; bag = "无"; max_number_of_wu_pin = 5; ju_li = 7000; player_hp = hp; } private: bool run_away; void attack() { int s = suiJi()%10+1; cout << name; if (wu_qi == "拳头") { show("出拳!\n\n"); cout << " O__ \\O" << endl; cout << " <| /\\" << endl; cout << " / \\ <\\" << endl; cout << endl; target_hp -= 5; target_meetPlayer(); show("敌人的hp减少了5!\n\n"); } else { if (number_of_bullet > 0) { show("开火!\n\n"); number_of_bullet --; if (s <= 6) { show("命中目标!\n\n"); cout << " O__ _@\\O" << endl; cout << " VV /\\" << endl; cout << " / \\ <\\" << endl; cout << endl; if (wu_qi == "M1911") { target_hp -= 10; show("敌人的hp减少了10!\n\n"); } else if (wu_qi == "MP5") { target_hp -= 20; show("敌人的hp减少了20!\n\n"); } else if (wu_qi == "AK47") { target_hp -= 30; show("敌人的hp减少了30!\n\n"); } else if (wu_qi == "S12K") { target_hp -= 40; show("敌人的hp减少了40!\n\n"); } else if (wu_qi == "AWM") { target_hp -= 50; show("敌人的hp减少了50!\n\n"); } else if (wu_qi == "M82A1") { target_hp -= 80; show("敌人的hp减少了80!\n\n"); } target_meetPlayer(); } else { show("没打中!QДQ\n\n"); } } else { show("没子弹了!QДQ\n\n"); } } } void move() { if (ju_li > 0) ju_li -= 200; show("距离绝对安全区还有"); printf("%d",ju_li); show("米!\n\n"); printf("输入1查看状态。\n\n"); int a; cin >> a; if (a == 1) { look(); } if (kt == true and juli_kt == 0) { show("你已找到空投。\n\n"); int s = suiJi()%10; if (s <= 5) { show("空投物资有:\n"); cout << "1.药 2.M82A1" << endl; int ch; cin >> ch; if (ch == 1) { if (number_of_wu_pin < max_number_of_wu_pin) { wu_pin[number_of_wu_pin] = "药"; number_of_wu_pin++; } } else if (ch == 2) { wu_qi = "M82A1"; number_of_bullet = 10; show("你装备了M82A1。\n\n"); } } else { show("可是空投物资被别人抢了。。。QДQ"); } kt = false; } else { int s; s = suiJi()%50; if (s >= 1 and s <= 10) { meetTarget(); } else if (s >= 10 and s <= 50) { getSomething(); } } } void runAway() { int s = suiJi()%10+1; if (s <= 4) { run_away = true; show("逃跑成功!(^o^)\n\n"); } else { run_away = false; show("逃跑失败!敌人追上来了!QДQ\n\n"); } } void daYao() { if (hp < 100) { bool find = false; for (int i=0; i<number_of_wu_pin; i++) { if (wu_pin[i] == "药") { find = true; show("正在打药......\n\n"); hp += 30; if (hp > 100) { hp = 100; } player_hp = hp; show("你的hp增加了30。\n\n"); for (int j=i; j<number_of_wu_pin-1; j++) { wu_pin[j] = wu_pin[j+1]; } number_of_wu_pin--; break; } } if (find == false) { show("你没有药!\n\n"); } } else { show("hp满,不用打药。\n\n"); } } void getSomething() { int s = suiJi()%100+1; show("发现"); char ch; if (s >= 1 and s <= 10) { show("三级包!\n\n"); show("是否拾取?Y/N\n\n"); cin >> ch; if (ch == 'Y') { show("背上了三级包。\n\n"); max_number_of_wu_pin = 20; bag = "三级包"; } } else if (s >= 11 and s <= 20) { show("二级包!\n\n"); show("是否拾取?Y/N\n\n"); cin >> ch; if (ch == 'Y') { show("背上了二级包。\n\n"); max_number_of_wu_pin = 15; bag = "二级包"; } } else if (s >= 21 and s <= 30) { show("一级包!\n\n"); show("是否拾取?Y/N\n\n"); cin >> ch; if (ch == 'Y') { show("背上了一级包。\n\n"); max_number_of_wu_pin = 10; bag = "一级包"; } } else if (s >= 31 and s <= 40) { show("AWM!\n\n"); show("是否拾取?Y/N\n\n"); cin >> ch; if (ch == 'Y') { show("装备了AWM。\n\n"); wu_qi = "AWM"; number_of_bullet = 5; } } else if (s >= 41 and s <= 50) { show("S12K!\n\n"); show("是否拾取?Y/N\n\n"); cin >> ch; if (ch == 'Y') { show("装备了S12K。\n\n"); wu_qi = "S12K"; number_of_bullet = 5; } } else if (s >= 51 and s <= 60) { show("AK47!\n\n"); show("是否拾取?Y/N\n\n"); cin >> ch; if (ch == 'Y') { show("装备了AK47。\n\n"); wu_qi = "AK47"; number_of_bullet = 30; } } else if (s >= 61 and s <= 70) { show("MP5!\n\n"); show("是否拾取?Y/N\n\n"); cin >> ch; if (ch == 'Y') { show("装备了MP5。\n\n"); wu_qi = "MP5"; number_of_bullet = 25; } } else if (s >= 71 and s <= 80) { show("M1911!\n\n"); show("是否拾取?Y/N\n\n"); cin >> ch; if (ch == 'Y') { show("装备了M1911。\n\n"); wu_qi = "M1911"; number_of_bullet = 7; } } else if (s >= 81 and s <= 100) { show("药!\n\n"); if (number_of_wu_pin < max_number_of_wu_pin) { show("是否拾取?Y/N\n\n"); cin >> ch; if (ch == 'Y') { wu_pin[number_of_wu_pin] = "药"; number_of_wu_pin++; show("捡起了药。\n\n"); } } else { show("可惜,背包满了。\n\n"); show("是否丢掉某样东西?Y/N\n\n"); cin >> ch; if (ch == 'Y') { int cho; show("请选择你要丢掉的东西:\n"); for (int i=0; i<number_of_wu_pin; i++) { cout << i+1 << '.' << wu_pin[i] << endl; } cin >> cho; if (cho >= 1 and cho <= number_of_wu_pin) { for (int i=cho-1; i<number_of_wu_pin-1; i++) { wu_pin[i] = wu_pin[i+1]; } number_of_wu_pin--; } else { while (not(cho >= 1 and cho <= number_of_wu_pin)) { show("输入错误!\n\n"); show("重新输入:"); cin >> cho; } for (int i=cho-1; i<number_of_wu_pin-1; i++) { wu_pin[i] = wu_pin[i+1]; } number_of_wu_pin--; } } } } } void look() { cout << name << endl; cout << "生命值:" << hp << endl; cout << "武器:" << wu_qi << ' ' << "子弹:" << number_of_bullet << endl;; cout << "背包:" << bag << endl; cout << "物品:" << endl; if (number_of_wu_pin > 0) { for (int i=0; i<number_of_wu_pin; i++) { cout << wu_pin[i] << endl; } } else { cout << "无" << endl; } cout << endl; system("pause"); cout << endl; } void meetTarget() { show("发现敌人!(o_o)!\n\n"); target_init(); while (target_hp > 0) { show("该怎么办?\n\n"); show("1.攻击 2.打药 3.逃跑\n\n"); cin >> handle; if (handle == 1) { attack(); if (target_hp == 0) { cout << " @@" << endl; cout << " @@" << endl; cout << " @" << endl; cout << " O---" << endl; cout << " /> \\\\" << endl; show("你淘汰了一个玩家!\n\n"); number_of_people--; break; } } else if (handle == 2) { daYao(); } else if (handle == 3) { runAway(); if (run_away == true) { break; } } target_active(); hp = player_hp; } } }; class Enemy { public: int hp; string wu_qi; void acitve() { attack(); } void init() { hp = suiJi()%100+1; target_hp = hp; int s = suiJi()%5+1; if (s == 1) { wu_qi = "M1911"; } else if (s == 2) { wu_qi = "MP5"; } else if (s == 3) { wu_qi = "AK47"; } else if (s == 4) { wu_qi = "S12K"; } else if (s == 5) { wu_qi = "AWM"; } } private: void attack() { show("敌人向你开火!\n\n"); int s = suiJi()%10+1; if (s <= 6) { show("你被击中了!(x_x)\n\n"); cout << "O/@" << endl; cout << " /\\" << endl; cout << " /\\" << endl; if (wu_qi == "M1911") { player_hp -= 10; show("敌人使用M1911,你的hp减少了10!\n\n"); } else if (wu_qi == "MP5") { player_hp -= 20; show("敌人使用MP5,你的hp减少了20!\n\n"); } else if (wu_qi == "AK47") { player_hp -= 30; show("敌人使用AK47,你的hp减少了30!\n\n"); } else if (wu_qi == "S12K") { player_hp -= 40; show("敌人使用S12K,你的hp减少了40!\n\n"); } else if (wu_qi == "AWM") { player_hp -= 50; show("敌人使用AWM,你的hp减少了50!\n\n"); } if (player_hp <= 0) { end(); } } else { show("但是没有击中你。(^o^)\n\n"); } } }; Player player; Enemy target; int main() { procedure(); return 0; } void init() { number_of_handle = 0; safe_round = 8000; kt = false; player.init(); } void procedure() { show("欢迎来到绝地求生!\n\n"); show("请输入玩家人数(最多100人,最少10人):"); cin >> number_of_people; if ((number_of_people < 10)or(number_of_people > 100)) { show("\n输入错误,系统自动为您更正,玩家人数为100人。\n\n"); number_of_people = 100; } show("\n请输入你的名字(不含空格):"); cin >> player.name; show("\n正在匹配......\n\n"); show("匹配成功!开始游戏!\n\n"); init(); system("pause"); system("cls"); menu(); } void menu() { show("你已落地。\n\n"); system("pause"); while (number_of_people > 1) { number_of_handle++; system("cls"); show("你正在跑毒......\n\n"); if (number_of_handle%5 == 0) { safe_round -= 1000; show("毒圈直径减小1000米!\n\n"); } if (number_of_handle == 5) { kt = true; show("空投已投下!\n\n"); juli_kt = 1000; } if (kt == true) { show("距离空投还有"); cout << juli_kt; show("米!\n\n"); if (juli_kt > 0) { juli_kt -= 200; } } if (number_of_people > 2) { int s = suiJi()%5+1; number_of_people -= s; if (number_of_people < 2) { number_of_people = 2; } } player.active(); printf("还剩%d人。\n", number_of_people); if (number_of_people > 1) system("pause"); cout << endl; } show("大吉大利,今晚吃鸡!\n\n"); system("pause"); } void show(char text[]) { int len = strlen(text); for (int i=0; i<=len; i++) { cout << text[i]; Sleep(80); } } int suiJi() { srand((unsigned)time(0)); return rand()%100+1; } void end() { cout << player.name; show("阵亡!\n\n"); show("再接再厉,下次吃鸡!\n\n"); system("pause"); exit(0); } void target_active() { target.acitve(); } void target_init() { target.init(); } void target_meetPlayer() { target.hp = target_hp; if (target.hp < 0) { target.hp = 0; target_hp = 0; } }