最近做了一款C++的游戏,“神之领域”!!!
下次更新:
- 增加更多闯关。
- 增加副本模式。
- 更多boss等你来袭
代码:
#include<iostream>
#include<algorithm>
#include<windows.h>
#include<cmath>
#include<cstdio>
#include<string>
#include<time.h>
using namespace std;
/*=========== variable ===========*/
string name;
int aggressivity=50;
int blood=120;
string armor="not";
string weapon="not";
long long money=100;
string monster1[6]={" ","flame zombie","Fire Whip Tree Demon","Industry Fire Giant","Hell Fire Earth Corpse","Spitfire Gate Ghost"};
/*=========== class ===========*/
class display{
public:
void image();
void flash();
void clsxy();
void cls();
void mess_intro(){
MessageBox(NULL," Let's get started! It is not impossible for mortals to kill gods!!!","start game",MB_OK|MB_ICONASTERISK);
}
void pass_flash(){
printf(
"1.Flame Forest(3 Stars)\n"
"2.Dark Star River(5 Stars) Not yet completed\n"
);
}
void costoms_1();
};
class outcome{
public:
void state();
void shop();
void page();
void artifact1(){
outcome v;
system("cls");
system("color 6");
printf(
"1.Purple Dragon Dagger 100 money 140 power\n"
"2.Cloud Deep Sword 300 money 160 power\n"
"3.Dragon Calling Bracelet 700 money 945 power\n"
"4.key stand 1200 money 1050 power\n"
"5.The Ring of Creation 9900 money 9999 power\n"
);
int opt;
cin>>opt;
if(opt==1){
if(money<100){
cout<<"Not enough money!";
Sleep(800);v.page();
}else{
money-=100;
weapon="Purple Dragon Dagger";
aggressivity+=140;
cout<<"Purchase successful!";
Sleep(700);
v.page();
}
}else if(opt==2){
if(money<300){
cout<<"Not enough money!";
Sleep(800);
v.page();
}else{
money-=300;
weapon="Cloud Deep Sword";
aggressivity+=160;
cout<<"Purchase successful!";
Sleep(700);
v.page();
}
}else if(opt==3){
if(money<700){
cout<<"Not enough money!";
Sleep(800);
v.page();
}else{
money-=700;
weapon="Dragon Calling Bracelet";
aggressivity+=945;
cout<<"Purchase successful!";
Sleep(700);
v.page();
}
}else if(opt==4){
if(money<1050){
cout<<"Not enough money!";
Sleep(800);
v.page();
}else{
money-=1200;
weapon="key stand";
aggressivity+=1050;
cout<<"Purchase successful!";
Sleep(700);
v.page();
}
}else if(opt==5){
if(money<9900){
cout<<"Not enough money!";
Sleep(800);
v.page();
}else{
money-=9900;
weapon="The Ring of Creation";
aggressivity+=9999;
cout<<"Purchase successful!";
Sleep(700);
v.page();
}
}
}
void artifact2(){
outcome v;
system("cls");
system("color 5");
printf(
"1.Leather iron armor 50 money 90 dam\n"
"2.Refined Iron Armor 350 money 155 dam\n"
"3.Diamond Divine Apparel 650 money 900 dam\n"
"4.Obsidian Divine Apparel 1720 money 1200 dam\n"
"5.Supreme God Battle Armor 9090 money 9600 dam\n"
);
int opt;
cin>>opt;
if(opt==1){
if(money<50){
cout<<"Not enough money!";
Sleep(800);
v.page();
}else{
money-=50;
armor="Leather iron armor";
blood+=90;
cout<<"Purchase successful!";
Sleep(700);
v.page();
}
}else if(opt==2){
if(money<350){
cout<<"Not enough money!";
Sleep(800);
v.page();
}else{
money-=350;
armor="Refined Iron Armor";
blood+=155;
cout<<"Purchase successful!";
Sleep(700);
v.page();
}
}else if(opt==3){
if(money<650){
cout<<"Not enough money!";
Sleep(800);
v.page();
}else{
money-=650;
armor="Diamond Divine Apparel";
blood+=900;
cout<<"Purchase successful!";
Sleep(700);
v.page();
}
}else if(opt==4){
if(money<1720){
cout<<"Not enough money!";
Sleep(800);
v.page();
}else{
money-=1720;
armor="Obsidian Divine Apparel";
blood+=1200;
cout<<"Purchase successful!";
Sleep(700);
v.page();
}
}else if(opt==5){
if(money<9090){
cout<<"Not enough money!";
Sleep(800);
v.page();
}else{
money-=9090;
armor="Supreme God Battle Armor";
blood+=9600;
cout<<"Purchase successful!";
Sleep(700);
v.page();
}
}
}
void risk();
};
/*=========== function ===========*/
void gotoxy(SHORT x,SHORT y){
COORD pos={x,y};
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut,pos);
return;
}
void hideCursor(){
CONSOLE_CURSOR_INFO cursor;
cursor.bVisible = 0;
cursor.dwSize = 1;
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(hOut, &cursor);
}
void showCursor(){
HANDLE h_GAME =GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursor_info;
GetConsoleCursorInfo(h_GAME,&cursor_info);
cursor_info.bVisible=true;
SetConsoleCursorInfo(h_GAME,&cursor_info);
}
int rand(int a,int b){
int s=rand()%b+a;
return s;
}
void display::image(){
printf(
"\n"
"\n"
" /========================\\ \n"
" = = \n"
" = Divine Domain = \n"
" = = \n"
" \\========================/ \n"
);
}
void display::cls(){
system("cls");
}
void display::clsxy(){
gotoxy(0,0);
}
void display::flash(){
display vice1;
system("color 8"); vice1.image();
Sleep(800); vice1.clsxy();
system("color 7"); vice1.image();
Sleep(800); vice1.clsxy();
system("color F"); vice1.image();
Sleep(2500);
}
void outcome::page(){
display vice2;
vice2.cls();
outcome myclass;
system("color 1");
printf(
"1.To risk 2.shop 3.state 4.duplicate\n"
);
int opt=0;
cin>>opt;
if(opt==1){
myclass.risk();
}else if(opt==2){
myclass.shop();
}else if(opt==3){
myclass.state();
}else if(opt==4){
MessageBox(NULL," Author incomplete!","sorry",MB_OK|MB_ICONASTERISK);
myclass.page();
}
}
void outcome::state(){
outcome s;
system("cls");
hideCursor();
system("color 4");
for(int i=5;i>=1;i--){
cout<<"warrior name : "<<name<<endl;
cout<<"money : "<<money<<endl;
cout<<"aggressivity : "<<aggressivity<<endl;
cout<<"blood : "<<blood<<endl;
cout<<"armor : "<<armor<<endl;
cout<<"weapon : "<<weapon<<endl<<endl;
cout<<i<<" seconds left";
Sleep(1000);
gotoxy(0,0);
}
s.page();
}
void outcome::shop(){
outcome vice;
system("cls");
system("color F");
printf(
"1.weapon\n"
"2.armor\n"
);
int opt;
cin>>opt;
if(opt==1){
vice.artifact1();
}else if(opt==2){
vice.artifact2();
}
}
void outcome::risk(){
display s;outcome v;
s.cls();
s.pass_flash();
system("color 2");
int opt;
cin>>opt;
if(opt==2){
MessageBox(NULL," Not yet completed!","Sorry",MB_OK|MB_ICONASTERISK);
v.page();
}else if(opt==1){
s.costoms_1();
}
}
void game(){
outcome s;
showCursor();
cout<<"your name : ";
getline(cin,name);
s.page();
}
void display::costoms_1(){
display s;
outcome v;
s.cls();
system("color 4");
int cnt=0;
int strike;
int freak=rand(1,5);
cout<<freak<<endl;
string boss=monster1[freak];
cout<<boss<<" Launched an attack on you!\n";
printf(
"blood volume:%d\n"
"attack:%d\n"
"First level core!"
,freak*90,freak*67
);
int g=freak*60,f=freak*80;
Sleep(3000);
s.cls();
int flag;
while(f>0||blood>0){
s.cls();
if(blood<=g){
printf("The monster is attacking you with %d damage. Do you want to escape\n",g);
}
printf("1.attack 2.escape\n");
int opt;cin>>opt;
if(opt==2){
s.cls();
printf("You have escaped!");
Sleep(2000);
v.page();
}else{
if(blood<=g){
if(aggressivity>=f){
system("cls");
system("color E");
printf("You won!!!");
Sleep(3000);
printf("reward:%d money",freak*100-10);
money+=(freak*100-10);
Sleep(4000);
v.page();
}else{
if(opt==1){
cnt++;
}
system("cls");
system("color E");
printf("You lost\nLimited time Participation rewards:%d",cnt*10); Sleep(3000); v.page();
money+=cnt*10;
}
}
s.cls();
strike=rand(1,3);
f-=(aggressivity+(strike==1?40:0));
cnt++;
printf("You dealt %d damage to ",(aggressivity+(strike==1?40:0)));cout<<boss;
Sleep(2000);
if(blood<1){
flag=1;
break;
}
blood-=g;
if(f<1){
flag=2;
break;
}
}
}
s.cls();
system("color E");
if(flag==2){
printf("You won!!!");
Sleep(3000);
printf("reward:%d money",freak*100-10);
money+=(freak*100-10);
Sleep(4000);
v.page();
}else if(flag==1){
printf("You lost"); Sleep(3000); v.page();
}
}
/*=========== The game is about to begin ! ===========*/
int main(){
srand(time(nullptr));
hideCursor();
display reveal;
reveal.flash();
reveal.cls();
reveal.mess_intro();
game();
return 0;
}
我测试过一遍,可玩性较低,因此将初始数据增强了一些,勉强可以。