代码如下:
记得输入大写!!!
#include <iostream>
#include <bits/stdc++.h>
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <bitset>
#include <sstream>
#include <ctime>
#include <stdlib.h>
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
void hideCursor() {
CONSOLE_CURSOR_INFO cursor;
cursor.bVisible = 0;
cursor.dwSize = 1;
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(hOut, &cursor);
}
void exit(){
system("cls");
cout<<"__________________________________________________"<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" 退出中... "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
int n=40;
cout<<" ";
while(n--){
cout<<"\033[1m"<<"█"<<"\033[0m";
Sleep(150);
}
Sleep(1000);
}
int main(){
hideCursor();
system("color");
cout << "\033[1;36m" << "" << "\033[1;36m" << endl;
cout<<"__________________________________________________"<<endl;
cout<<" The Game.. "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout << "\033[0;36m" << " by.emmm... O_O" << "\033[0m" << endl;
Sleep(1000);
system("color");
cout << "\033[0m" << "" << "\033[0m" << endl;
system("cls");
//_____________________________________________________________________
cout << "\033[1m" << "" << "\033[1m" << endl;
cout<<"__________________________________________________"<<endl;
cout<<" 抵制不良游戏,拒绝盗版游戏。 "<<endl;
cout<<" 注意自我保护,谨防受骗上当。 "<<endl;
cout<<" 适度游戏益脑,沉迷游戏伤身。 "<<endl;
cout<<" 合理安排时间,享受健康生活。 "<<endl<<endl;
cout<<" 初始化资源中... "<<endl;
int n=40;
cout<<" ";
while(n--){
cout<<"\033[1m"<<"█"<<"\033[0m";
Sleep(100);
}
Sleep(1000);
system("cls");
//_______________________________________________________________________
cout << "\033[7;36m" << "" << "\033[7;36m" << endl;
cout<<"__________________________________________________"<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" 即将开始游戏... "<<endl;
cout<<" "<<endl;
cout<<" The game is about to start... "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
Sleep(1000);
cout << "\033[0m" << "" << "\033[0m" << endl;
system("cls");
//________________________________________________________________________
//______________________________定义____________________
int Attack=10;
int Healthmax=500;
int Health=500;
int Mora=100;
char code;
int temp_;
string wQ[5]={"<雷光之剑>","<制裁>","<白羽>","<鸢莺枪>","<鹤鸣之时>"};
string cD[2]={"阿布鲁人","史莱姆"};
string zD[4]={"阿布鲁射手","阿布鲁法师","阿布鲁萨满","西洋大盗"};
string gD[4]={"阿布鲁暴徒","阿布鲁王","巨龙蜥蜴","西洋武士"};
string jD[4]={"西洋大队","冰冻岩树","沉渊麒麟","落宫狻猊"};
//______________________________________________________
cout << "\033[36m" << "" << "\033[36m" << endl;
cout<<"__________________________________________________"<<endl;
cout<<" 攻击力:"<<Attack<<" 生命值:"<<Health<<" 摩拉:"<<Mora<<" "<<endl;
cout<<" ================== "<<endl;
cout<<" ‖ A.探索 ‖ "<<endl;
cout<<" ‖ B.商店 ‖ "<<endl;
cout<<" ‖ C.退出游戏 ‖ "<<endl;
cout<<" ================== "<<endl;
cout<<" "<<endl;
while(cin >> code){
//_____________________________________________________________
if(code == 'A'){
temp_ = 1 + rand() % 4;
if(temp_ == 1){
int getMo = 1 + rand() % 49;
Mora += getMo;
cout << "获得了" << getMo << "摩拉" << endl;
Sleep(1000);
}
if(temp_ == 2){
int getAt = 6 + rand() % 29;
Attack += getAt;
cout << "获得了"<< wQ[0 + rand() % 5] <<",攻击力+" << getAt << endl;
Sleep(1000);
}
if(temp_ == 3){
cout << "遭遇敌袭" << endl;
Sleep(1000);
system("cls");
int Datk;
int SFdef = 0;
int SFtt;
int Dhp;
char tcode;
string Dname;
int HDML;
//___________________________________________________________
if(Attack <= 50){
HDML = 31 + rand() % 29;
Dname = cD[0 + rand() % 2];
Dhp = 50;
Datk = 11 + rand() % 9;
}else if(Attack <= 100){
HDML = 46 + rand() % 29;
Dname = zD[0 + rand() % 4];
Dhp = 150;
Datk = 16 + rand() % 9;
}else if(Attack <= 200){
HDML = 51 + rand() % 29;
Dname = gD[0 + rand() % 4];
Dhp = 250;
Datk = 21 + rand() % 9;
}else if(Attack <= 350){
Dname = jD[0 + rand() % 4];
if(Dname == "西洋大队"){
Dhp = 300;
Datk = 25;
HDML = 70;
}
if(Dname == "冰冻岩树"){
Dhp = 325;
Datk = 30;
HDML = 80;
}
if(Dname == "沉渊麒麟"){
Dhp = 400;
Datk = 35;
HDML = 100;
}
if(Dname == "落宫狻猊"){
Dhp = 400;
Datk = 35;
HDML = 100;
}
} else{
Dname = "Icefire Twoheavens" ;
Dhp = 1000;
Datk = 50;
}
cout<<"__________________________________________________"<<endl;
cout<<" " << Dname << " : ATK: " << Datk << " HP: " << Dhp << endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" A.进攻 B.防御 C.撤退 "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" 你 : ATK: " << Attack << " HP: " << Health << endl;
while(cin >> tcode){
if(tcode == 'A'){
int Dhurt = Attack - 5 + rand() % 10;
Dhp -= Dhurt;
cout << Dname << "受到了" << Dhurt << "点伤害" << endl;
Sleep(1000);
}
if(tcode == 'B'){
SFdef = 1;
cout << "你决定防御" << endl;
Sleep(1000);
}
if(tcode == 'C'){
SFtt = 1 + rand() % 1;
if(SFtt == 0){
cout << "撤退失败" << endl;
Sleep(1000);
}else{
cout << "撤退成功,3s后退出" << endl;
Sleep(3000);
break;
}
}
int Yhurt = Datk - 5 + rand() % 10;
if(SFdef == 1){
cout << "你抵挡了" << Dname <<"部分伤害" << endl;
Yhurt /= 3;
}
cout << "你受到伤害" << Yhurt << endl;
Health -= Yhurt;
Sleep(1000);
if(Dname == "Icefire Twoheavens"&&Dhp <= 0 && Health > 0){
system("cls");
cout << "随着一声嚎叫,<Icefire Twoheavens>应声倒地" << endl;
Sleep(1000);
cout << "你扔去了手中的武器,转身离开" << endl;
Sleep(1000);
cout << "\033[31m" <<"事了拂衣去,深藏功与名" << "\033[31m" << endl << endl;
Sleep(1000);
cout << "\033[31m" <<"不见曾经壮士在,唯有长剑插石中" << "\033[37m" << endl << endl;
Sleep(1000);
cout << "未完待续...";
return 0;
}
if(Dhp <= 0 && Health > 0){
cout << "你击败了敌人" << "获得了摩拉" << HDML;
Mora += HDML;
Sleep(1000);
break;
}
if(Dhp <= 0 && Health <= 0){
cout << "两败俱伤,请重新开始";
Sleep(1000);
exit();
return 0;
}
if(Dhp > 0 && Health <= 0){
cout << "你死了,请重新开始";
Sleep(1000);
exit();
return 0;
}
system("cls");
cout<<"__________________________________________________"<<endl;
cout<<" " << Dname << " : ATK: " << Datk << " HP: " << Dhp << endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" A.进攻 B.防御 C.撤退 "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" 你 : ATK: " << Attack << " HP: " << Health << endl;
}
}
if(temp_ == 4){
cout<<"无事发生"<<endl;
Sleep(1000);
}
}
//_____________________________________________________________
if(code == 'B'){
system("cls");
char Bcode;
cout<<"__________________________________________________"<<endl;
cout<<" =^OwO^= <( 来点什么吧 ) 摩拉: "<<Mora<<endl;
cout<<" "<<endl;
cout<<" 1.千年老酒(Hp上限+100,Hp+100)[150摩拉] "<<endl;
cout<<" 2.龙吟剑(攻击+100)[200摩拉] "<<endl;
cout<<" 3.金疮药(Hp回满)[300摩拉] "<<endl;
cout<<" "<<endl;
cout<<" Q.退出 "<<endl;
cin >> Bcode;
if(Bcode == '1' && Mora < 150){
cout << "摩拉不够,你离开了商店";
Sleep(1000);
system("cls");
}
if(Bcode == '2' && Mora < 200){
cout << "摩拉不够,你离开了商店";
Sleep(1000);
system("cls");
}
if(Bcode == '3' && Mora < 300){
cout << "摩拉不够,你离开了商店";
Sleep(1000);
system("cls");
}
if(Bcode == '1' && Mora >= 150){
Mora -= 150;
Healthmax += 100;
Health += 100;
cout << "购买成功,欢迎下次光临";
Sleep(1000);
system("cls");
}
if(Bcode == '2' && Mora >= 200){
Mora -= 200;
Attack += 30;
cout << "购买成功,欢迎下次光临";
Sleep(1000);
system("cls");
}
if(Bcode == '3' && Mora >= 300){
Mora -= 300;
while(Health < Healthmax){
Health++;
}
cout << "购买成功,欢迎下次光临";
Sleep(1000);
system("cls");
}
if(Bcode == 'Q' ){
cout << "欢迎下次光临";
Sleep(1000);
system("cls");
}
}
//_____________________________________________________________
if(code == 'C'){
exit();
return 0;
}
//_______________________________________________
system("cls");
cout << "\033[36m" << "" << "\033[36m" << endl;
cout<<"__________________________________________________"<<endl;
cout<<" 攻击力:"<<Attack<<" 生命值:"<<Health<<" 摩拉:"<<Mora<<" "<<endl;
cout<<" ================== "<<endl;
cout<<" ‖ A.探索 ‖ "<<endl;
cout<<" ‖ B.商店 ‖ "<<endl;
cout<<" ‖ C.退出游戏 ‖ "<<endl;
cout<<" ================== "<<endl;
cout<<" "<<endl;
}
}
这里用的是c++11,其他不知到行不行,没试,可能不好看,请见谅