Devc++战斗1.0
Posted binggan369
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Devc++战斗1.0相关的知识,希望对你有一定的参考价值。
大家好!
我最近花了四天的时间做了一个小游戏:
战斗1.0
由于是第一次写那么多代码,
可能会有很多BUG,请大佬见谅!
如有BUG,希望大佬能告诉我,谢谢!
话有点多话不多说上代码!
代码
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
const long long wqs=11;
string t;
bool f=1;
struct wj//玩家的结构体
{
string name,mm;
bool awq[wqs+1];
long long bwq[wqs+1];
long long dj,jyz,xie,max_xie;
long long gj,fy,wq,qian;
long long sbl,zbbh[4];
void csh()
{
max_xie=xie=100;
gj=25;
fy=5;
sbl=5;
qian=0;
dj=0;
jyz=0;
for(long long i=1;i<=3;i++)
{
zbbh[i]=0;
}
for(long long i=0;i<=wqs;i++)
{
awq[i]=0;
bwq[i]=0;
}
return ;
}
}wj;
struct cd//存档结构体
{
void out()
{
ofstream a("玩家属性.binggan");
a<<wj.name<<"\\n";
a<<wj.mm<<"\\n";
a<<wj.dj<<"\\n";
a<<wj.jyz<<"\\n";
a<<wj.max_xie<<"\\n";
a<<wj.xie<<"\\n";
a<<wj.gj<<"\\n";
a<<wj.fy<<"\\n";
a<<wj.sbl<<"\\n";
a<<wj.qian<<"\\n";
a.close();
ofstream b("装备.binggan");
b<<wj.zbbh[1]<<"\\n"<<wj.zbbh[2]<<"\\n"<<wj.zbbh[3]<<"\\n\\n";
for(long long i=0;i<=wqs;i++)
{
b<<wj.awq[i]<<"\\n";
}
b<<"\\n";
for(long long i=0;i<=wqs;i++)
{
b<<wj.bwq[i]<<"\\n";
}
b.close();
return ;
}
void in()
{
ifstream a("玩家属性.binggan");
a>>wj.name;
a>>wj.mm;
a>>wj.dj;
a>>wj.jyz;
a>>wj.max_xie;
a>>wj.xie;
a>>wj.gj;
a>>wj.fy;
a>>wj.sbl;
a>>wj.qian;
a.close();
ifstream b("装备.binggan");
b>>wj.zbbh[1]>>wj.zbbh[2]>>wj.zbbh[3];
for(long long i=0;i<=wqs;i++)
{
a>>wj.bwq[i];
}
for(long long i=0;i<=wqs;i++)
{
b>>wj.bwq[i];
}
b.close();
return ;
}
}cd;
struct wq//武器结构体
{
string name;
long long gj;
long long fy;
long long sbl;
long long qian;
}wq[wqs+1]={
{"无",0,0,0,0},
{"匕首",10,0,20,0},
{"铁剑",30,5,5,100},
{"盾",0,30,-5,20},
{"铁甲",-5,40,-10,200},
{"大砍刀",45,0,5,0},
{"锁甲",5,35,10,0},
{"矛",50,-3,-5,300},
{"斧子",50,0,-10,300},
{"流星锤",55,-15,-15,0},
{"刺伞",40,30,0,0},
{"刺扇",40,15,35,0}
};
struct gw//怪物结构体
{
string name;
long long xie;
long long gj,fy,sbl;
long long qian;
long long zbl,zbbh;
long long jy;
}gw,kl[6]={
{"\\0",0,0,0,0,0,0,0,0},
{"骷髅士兵",80,20,5,5,50,1,50,30},
{"骷髅骑士",100,30,5,5,80,2,45,50},
{"幽灵骷髅",90,25,0,30,150,wqs,30,60},
{"骷髅暴君",180,70,10,5,300,6,55,100},
{"骷髅巨人",300,100,20,0,1000,9,75,200}
};
void kshm();
void zjm();
void zd();
void dz(long long);
void sd();
void bb();
void qk();
void rqk();
void wqqk();
void zwq();
void xwq();
void mwq();
void mwq(long long);
void sj();
void out(string,long long);
long long sj(long long);
int main()
{
kshm();
while(1)
{
system("cls");
cout<<"1.存档 2.新建\\n";
char n;
n=getch();
system("cls");
if(n=='1')
{
cd.in();
cout<<"用户名:";
cin>>t;
if(t!=wj.name)
{
cout<<"用户名错误!";
Sleep(1000);
system("cls");
continue;
}
cout<<"密码:";
cin>>t;
if(t!=wj.mm)
{
cout<<"密码错误!";
Sleep(1000);
system("cls");
continue;
}
cd.in();
break;
}
else
if(n=='2')
{
cout<<"用户名:";
cin>>wj.name;
cout<<"密码:";
cin>>wj.mm;
wj.csh();
break;
}
else
{
cout<<"不要乱输入!!!";
}
system("cls");
}
system("cls");
while(f)
{
zjm();
}
cd.out();
return 0;
}
void kshm()
{
system("color f0");
cout<<"按任意键开始游戏";
getch();
system("cls");
for(long long i=1;i<=3;i++)
{
system("color 07");
system("color 10");
system("color 20");
system("color 30");
system("color 40");
system("color 50");
system("color 60");
system("color 70");
system("color 80");
system("color 90");
system("color a0");
system("color b0");
system("color c0");
system("color d0");
system("color e0");
system("color f0");
}
cout<<"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n ";
out("战斗",300);
cout<<"\\n";
cout<<" ";
out("出品:饼干",30);
Sleep(1500);
return ;
}
void out(string n,long long s)
{
for(long long i=0;i<n.size();i++)
{
cout<<n[i];
Sleep(s);
}
return ;
}
void zjm()
{
system("cls");
cout<<"1.战斗\\n2.商店\\n3.背包\\n4.退出";
char s;
s=getch();
switch(s)
{
case '1':
zd();
break;
case '2':
sd();
break;
case '3':
bb();
break;
case '4':
f=0;
break;
default:
system("cls");
cout<<"不要乱输入!!!";
Sleep(1000);
break;
}
return ;
}
void zd()
{
long long s=sj(100);
if(s<=40)dz(1);
else
if(s<=65)dz(2);
else
if(s<=75)dz(3);
else
if(s<=90)dz(4);
else
dz(5);
return ;
}
void dz(long long bh)
{
long long t=wj.sbl>80?80:wj.sbl;
bool f=0;
char s;
system("cls");
cout<<"你面对的是"<<kl[bh].name<<"\\n";
cout<<"血量:"<<kl[bh].xie<<"\\n";
cout<<"攻击:"<<kl[bh].gj<<"\\n";
cout<<"防御:"<<kl[bh].fy<<"\\n";
cout<<"闪避率:"<<kl[bh].sbl<<"%\\n";
cout<<"1.迎战 2.逃跑";
s=getch();
while(s!='1'&&s!='2')s=getch();
if(s=='2')
{
if(sj(100)<=50)
{
system("cls");
cout<<"逃跑成功!";
Sleep(1500);
return ;
}
else
{
system("cls");
cout<<"逃跑失败!";
Sleep(1500);
}
}
gw=kl[bh];
system("cls");
for(long long i=1;1;i++)
{
cout<<"第"<<i<<"回合\\n\\n\\n";
cout<<"你的血量:"<<wj.xie<<"\\n";
cout<<gw.name<<"的血量"<<gw.xie<<"\\n";
cout<<"1.攻击 2.治疗\\n";
s=getch();
while(s!='1'&&s!='2')s=getch();
if(s=='1')
{
if(gw.sbl>=sj(100))
{
cout<<gw.name<<"闪避了你的攻击\\n";
}
else
if(gw.fy>=wj.gj)
{
cout<<gw.name<<"防御下了你的攻击\\n";
}
else
{
cout<<gw.name<<"的血量-"<<wj.gj-gw.fy<<"\\n";
gw.xie-=wj.gj-gw.fy;
}
}
else
{
if(wj.xie+20>=wj.max_xie)
{
cout<<"已回满!\\n";
wj.xie=wj.max_xie;
}
else
{
cout<<"你的血量+20\\n";
wj.xie+=20;
}
}
if(gw.xie<=0)
{
system("cls");
cout<<"胜利!\\n";
cout<<"你获得了"<<gw.qian<<"金币\\n";
cout<<"你获得了"<<gw.jy<<"经验值\\n\\n";
wj.qian+=gw.qian;
wj.jyz+=gw.jy;
cout<<"按空格键继续";
while(getch()!=' ');
sj();
return ;
}
if(t>=sj(100))
{
cout<<"你闪避了"<<gw.name<<"的攻击\\n";
}
else
if(wj.fy>=gw.gj)
{
cout<<"你防御下了"<<gw.name<<"的攻击\\n";
}
else
{
cout<<"你的血量-"<<gw.gj-wj.fy<<"\\n";
wj.xie-=gw.gj-wj.fy;
}
if(wj.xie<=0)
{
system("cls");
cout<<"你战死了!\\n";
wj.xie=0;
Sleep(1000);
return ;
}
Sleep(1000);
system("cls");
}
return ;
}
void sj()
{
while(wj.jyz>=100&&wj.dj!=10)
{
system("cls");
wj.gj+=2;
wj.fy+=1;
wj.dj++;
wj.jyz-=100;
wj.max_xie+=10;
wj.xie=wj.max_xie;
wj.sbl+=1;
out("你升级了!\\n",30);
out("血量上限+10\\n",30);
out("伤害+2\\n",30);
out("防御+1\\n",30);
out("闪避率+1\\n\\n",30);
cout<<"按空格继续";
while(getch()!=' ');
}
return ;
}
void sd()
{
long long t;
while(1)
{
system("cls");
cout<<"欢迎来到本【饼干】商店!\\n\\n";
cout<<"你有"<<wj.qian<<"金币\\n";
cout<<"1.武器 2.药品(30元/个,每个补50血量) 3.退出";
char s;
s=getch();
while(s!='1'&&s!='2'&&s!='3')s=getch();
if(s=='1')
{
mwq();
}
else
if(s=='2')
{
system("cls");
cout<<"要不要帮你补满血量?(y/n)";
s=getch();
while(s!='y'&&s!='n')s=getch();
if(s=='y')
{
if((wj.max_xie-wj.xie)%50==0)
{
if((wj.max_xie-wj.xie)/50*30<=wj.qian)
{
system("cls");
cout<<"已回满!";
wj.qian-=(wj.max_xie-wj.xie)/50*30;
wj.xie=wj.max_xie;
Sleep(1000);
}
else
{
system("cls");
cout<<"钱不够!";
Sleep(1000);
system("cls");
}
}
else
{
if(((wj.max_xie-wj.xie)/50+1)*30<=wj.qian)
{
system("cls");
cout<<"已回满!";
wj.qian-=((wj.max_xie-wj.xie)/50+1)*30;
wj.xie=wj.max_xie;
Sleep(1000);
}
else
{
system("cls");
cout<<"钱不够!";
Sleep(1000);
system("cls");
}
}
}
else
{
system("cls");
cout<<"金币"<<wj.qian<<"\\n";
cout<<"血量:"<<wj.xie<<"/"<<wj.max_xie<<"\\n";
cout<<"你要买几个?\\n";
cin>>t;
if(t*30<=wj.qian)
{
system("cls");
wj.xie+=t*30;
if(wj.xie>wj.max_xie)wj.xie=wj.max_xie;
cout<<"够买成功!";
Sleep(1000);
system("cls");
}
else
{
system("cls");
cout<<"钱不够!";
Sleep(1000);
system("cls");
}
}
}
else
{
system("cls");
cout<<"欢迎下次光临!";
Sleep(1000);
system("cls");
return ;
}
}
return ;
}
void mwq()
{
system("cls");
cout<<"金币:"<<wj.qian<<"\\n\\n";
cout<<"0.退出\\n";
cout<<"1.盾(20金币)\\n";
cout<<"2.铁剑(100金币)\\n";
cout<<"3.矛(300金币)\\n";
cout<<"4.斧子(300金币)\\n";
cout<<"5.铁甲(200金币)\\n";
char s;
s=getch();
while(s!='1'&&s!='2'&&s!='3'&&s!='4'&&s!='5'&&s!='0')s=getch();
if(s=='0')
{
system("cls");
return ;
}
switch(s)
{
case '1':
mwq(3);
break;
case '2':
mwq(2);
break;
case '3':
mwq(7);
break;
case '4':
mwq(8);
break;
case '5':
mwq(4);
}
return ;
}
void mwq(long long n)
{
system("cls");
if(wj.qian>=wq[n].qian)
{
cout<<"购买成功!\\n";
wj.bwq[n]++;
wj.awq[n]=1;
wj.qian-=wq[n].qian;
Sleep(1000);
system("cls");
}
else
{
cout<<"钱不够!\\n";
Sleep(1000);
system("cls");
}
return ;
}
void bb()
{
while(1)
{
system("cls");
cout<<"1.查看情况\\n2.装上装备\\n3.卸下装备\\n4.退出";
char s;
s=getch();
while(s!='1'&&s!='2'&&s!='3'&&s!='4')s=getch();
switch(s)
{
case '1':
qk();
break;
case '2':
zwq();
break;
case '3':
xwq();
break;
case '4':
system("cls");
return ;
}
}
return ;
}
void qk()
{
while(1)
{
system("cls");
cout<<"1.玩家情况 2.武器情况 3.退出";
char s;
s=getch();
while(s!='1'&&s!='2'&&s!='3')s=getch();
switch(s)
{
case '1':
rqk();
break;
case '2':
wqqk();
break;
case '3':
system("cls");
return ;
}
}
return ;
}
void rqk()
{
system("cls");
cout<<"用户名:"<<wj.name<<"\\n";
cout<<"等级:"<<wj.dj;
if(wj.dj==10)cout<<"(max)";
cout<<"\\n";
if(wj.dj!=10)
cout<<"经验值:"<<wj.jyz<<"/100";
cout<<"\\n";
cout<<"血量:"<<wj.xie<<"/"<<wj.max_xie<<"\\n";
cout<<"攻击:"<<wj.gj<<"\\n";
cout<<"防御:"<<wj.fy<<"\\n";
cout<<"闪避率:";
if(wj.sbl>=80)cout<<"80";
else
if(wj.sbl<=0)cout<<"0";
else
cout<<wj.sbl;
cout<<"%\\n";
cout<<"金币:"<<wj.qian<<"\\n";
cout<<"装备:"<<"|"<<wq[wj.zbbh[1]].name<<"|"<<wq[wj.zbbh[2]].name<<"|"<<wq[wj.zbbh[3]].name<<"|"<<"\\n";
cout<<"其他装备:\\n";
bool f=1;
for(long long i=1;i<=wqs;i++)
{
if(wj.bwq[i]>=1)
{
f=0;
cout<<wq[i].name<<"*"<<wj.bwq[i]<<"\\n";
}
}
if(f)cout<<"无";
cout<<"\\n\\n按空格继续...\\n";
char s;
s=getch();
while(s!=' ')s=getch();
return ;
}
void wqqk()
{
while(1)
{
system("cls");
long long s;
do
{
system("cls");
cout<<"0.退出\\n";
for(long long i=1;i<=wqs;i++)
{
cout<<i<<"."<<wq[i].name<<"\\n";
}
cin>>s;
}
while(0>s||s>wqs);
if(s==0)return ;
system("cls");
cout<<"装备名:"<<wq[s].name<<"\\n";
cout<<"伤害:"<<wq[s].gj<<"\\n";
cout<<"防御:"<<wq[s].fy<<"\\n";
cout<<"闪避率:"<<wq[s].sbl<<"%\\n";
cout<<"\\n\\n按空格继续\\n";
char t;
t=getch();
while(t!=' ')t=getch();
}
return ;
}
void zwq()
{
long long s,n;
char t;
while(1)
{
system("cls");
cout<<"0.退出\\n";
for(long long i=1;i<=wqs;i++)
{
if(wj.bwq[i]>=1)
{
cout<<i<<"."<<wq[i].name<<"*"<<wj.bwq[i]<<"\\n";
}
}
cin>>s;
while(0>s||s>wqs)
{
system("cls");
cout<<"0.退出\\n";
for(long long i=1;i<=wqs;i++)
{
if(wj.bwq[i]>=1)
{
cout<<i<<"."<<wq[i].name<<"*"<<wj.bwq[i]<<"\\n";
}
}
cin>>s;
}
if(s==0)return ;
n=s;
if(wj.bwq[s]>=1)
{
system("cls");
cout<<"你要装在哪个格子里?\\n";
cout<<"|"<<wq[wj.zbbh[1]].name<<"|"<<wq[wj.zbbh[2]].name<<"|"<<wq[wj.zbbh[3]].name<<"|";
t=getch();
while(t!='1'&&t!='2'&&t!='3')t=getch();
s=t-'0';
if(wq[wj.zbbh[s]].name!="无")
{
system("cls");
cout<<"这个格子已经有武器了!\\n";
cout<<"是否替换?(y/n)";
t=getch();
while(t!='y'&&t!='n')t=getch();
if(t=='y')
{
wj.gj-=wq[wj.zbbh[s]].gj;
wj.fy-=wq[wj.zbbh[s]].fy;
wj.sbl-=wq[wj.zbbh[s]].sbl;
wj.bwq[wj.zbbh[s]]++;
wj.zbbh[s]=n;
wj.bwq[n]--;
wj.gj+=wq[n].gj;
wj.fy+=wq[n].fy;
wj.sbl+=wq[n].sbl;
system("cls");
out("成功替换!",30);
Sleep(1000);
}
else
{
system("cls");
continue;
}
}
else
{
wj.gj+=wq[n].gj;
wj.fy+=wq[n].fy;
wj.sbl+=wq[n].sbl;
wj.zbbh[s]=n;
wj.bwq[n]--;
system("cls");
out("成功装备!",30);
Sleep(1000);
}
}
else
{
system("cls");
cout<<"你没有这个装备!";
}
}
return ;
}
void xwq()
{
char s;
while(1)
{
system("cls");
cout<<"你要卸下哪个格子里的装备?\\n";
cout<<"|"<<wq[wj.zbbh[1]].name<<"|"<<wq[wj.zbbh[2]].name<<"|"<<wq[wj.zbbh[3]].name<<"|";
s=getch();
while(s!='1'&&s!='2'&&s!='3')s=getch();
if(wj.zbbh[s]==0)
{
system("cls");
cout<<"此格子内无装备!";
Sleep(1000);
continue;
}
wj.gj-=wq[wj.zbbh[s]].gj;
wj.fy-=wq[wj.zbbh[s]].fy;
wj.sbl-=wq[wj.zbbh[s]].sbl;
wj.bwq[wj.zbbh[s]]++;
wj.zbbh[s]=0;
system("cls");
out("成功卸下!",30);
}
return ;
}
long long sj(long long s)
{
srand(time(0));
return rand()%s+1;
}
第一次写那么多代码,手都酸死了!
大家如果觉得我写得好
请点赞、收藏、关注我哦!
声明:
以上是关于Devc++战斗1.0的主要内容,如果未能解决你的问题,请参考以下文章