#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
using namespace std;
long long random(long long a,long long b){
return double(rand())/(RAND_MAX+1)*(max(a,b)-min(a,b)+1)+min(a,b);
}
int main(){
int blood=0,blood1=5,zombieblood=2,spirit=1,spirit1=1,zombiespirit=1,zz=1,zombiespirit1=0,hurt=3,zombiehurt=2,m,n,b;
int g[10],f=0,exp=0,plusexp=0,zombieexp,maxexp=5,grade=1,kk=0,xp=0;
string ju1=" ",ju2=" ",ju3=" ",ju4=" ",ju5=" ";
char c;
long long cnt=0;
int random_number;
while(1){
blood1=5;
blood=blood1+kk;
for(int i=0;i<grade;i++){
zombieblood=2;
zombiespirit=1;
zombiehurt=2;
Sleep(5);
random_number=random(0,5);
if(random_number%6==5){
zz++;
}
for(int j=1;j<zz;j++){
Sleep(5);
random_number=random(0,19);
if(random_number%4==1){
zombiehurt++;
Sleep(5);
}else if(random_number%5==2){
zombiespirit++;
Sleep(5);
}
else{
zombieblood+=2;
Sleep(5);
}
}
m=zombieblood;
b=zombiehurt;
n=zombiespirit;
maxexp=2*grade+3;
while(m>0){
blood1=5;
while(1){
cout<<"你碰到了怪物,它的血"<<m<<",伤"<<b-1<<",防御"<<zombiespirit-1<<","<<zz<<"级"<<endl;
cout<<"你的血"<<blood<<",伤"<<hurt-1<<",防御"<<spirit-1<<"。攻击按q,道具按1到5"<<endl;
cout<<"1."<<ju1<<endl;
cout<<"2."<<ju2<<endl;
cout<<"3."<<ju3<<endl;
cout<<"4."<<ju4<<endl;
cout<<"5."<<ju5<<endl;
cout<<"**已击败"<<cnt<<"只怪物**"<<endl<<endl<<"当前"<<exp<<"点经验"<<","<<"还差"<<maxexp-exp<<"点经验升级"<<endl<<"****"<<grade<<"级****"<<endl<<endl<<endl;
c=getch();
if(c=='q'){
Sleep(5);
Sleep(5);
random_number=random(0,zombiespirit-1);
n=random_number;
random_number=random(0,hurt-1);
if(n-random_number%hurt>=0){
m-=0;
cout<<"你造成了"<<0<<"点伤害"<<endl;
Sleep(500);
}else{
m+=floor(n-random_number%hurt);
cout<<"你造成了"<<abs(floor(n-random_number%hurt))<<"点伤害"<<endl;
Sleep(500);
}
random_number=random(0,3*4*spirit-1);
break;
}
if(c=='1'&&ju1=="小补丹"){
blood+=3;
ju1=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='1'&&ju1=="大补丹"){
blood+=7;
ju1=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='1'&&ju1=="火球术"){
m-=3;
ju1=" ";
}
if(c=='1'&&ju1=="大火球术"){
m-=6;
ju1=" ";
}
if(c=='1'&&ju1=="破防术"){
zombiespirit=1;
ju1=" ";
}
if(c=='2'&&ju2=="小补丹"){
blood+=3;
ju2=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='2'&&ju2=="大补丹"){
blood+=7;
ju2=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='2'&&ju2=="火球术"){
m-=3;
ju2=" ";
}
if(c=='2'&&ju2=="大火球术"){
m-=6;
ju2=" ";
}
if(c=='2'&&ju2=="破防术"){
zombiespirit=1;
ju2=" ";
}
if(c=='3'&&ju3=="小补丹"){
blood+=3;
ju3=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='3'&&ju3=="大补丹"){
blood+=7;
ju3=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='3'&&ju3=="火球术"){
m-=3;
ju3=" ";
}
if(c=='3'&&ju3=="大火球术"){
m-=6;
ju3=" ";
}
if(c=='3'&&ju3=="破防术"){
zombiespirit=1;
ju3=" ";
}
if(c=='4'&&ju4=="小补丹"){
blood+=3;
ju4=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='4'&&ju4=="大补丹"){
blood+=7;
ju4=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='4'&&ju4=="火球术"){
m-=3;
ju4=" ";
}
if(c=='4'&&ju4=="大火球术"){
m-=6;
ju4=" ";
}
if(c=='4'&&ju4=="破防术"){
zombiespirit=1;
ju4=" ";
}
if(c=='5'&&ju5=="小补丹"){
blood+=3;
ju5=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='5'&&ju5=="大补丹"){
blood+=7;
ju5=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='5'&&ju5=="火球术"){
m-=3;
ju5=" ";
}
if(c=='5'&&ju5=="大火球术"){
m-=6;
ju5=" ";
}
if(c=='5'&&ju5=="破防术"){
zombiespirit=1;
ju5=" ";
}
system("cls");
}
if(m<0){
break;
}
if(m<=zombieblood/5&&random_number%3==1&&zz>=2){
cout<<"怪物使用了"<<"小补丹"<<endl;
m+=3;
if(m>zombieblood){
m=zombieblood;
}
}
if(blood>=3&&blood>=zombieblood/2&&random_number%4==1&&zz>=5&&blood>=(blood1+kk)/3*2){
cout<<"怪物使用了"<<"火球术"<<endl;
blood-=3;
}
spirit1=random_number%spirit;
random_number=random(0,zombiehurt-1);
if(spirit1-random_number%zombiehurt>=0){
blood-=0;
cout<<"怪物造成了"<<0<<"点伤害"<<endl;
Sleep(500);
}else{
blood+=floor(spirit1-random_number%zombiehurt);
cout<<"怪物造成了"<<abs(floor(spirit1-random_number%zombiehurt))<<"点伤害"<<endl;
Sleep(500);
}
system("cls");
if(blood<0){
cout<<"game over"<<endl<<"记录:"<<cnt<<"只"<<endl<<endl;
system("pause");
return 0;
}
}
cout<<"成功击败怪物!";
cnt++;
Sleep(1000);
system("cls");
random_number=random(0,15*zombiehurt-1);
if(random_number%15==0||random_number%15==1||random_number%15==2||random_number%15==3){
cout<<"你获得了小补丹";
if(ju1==" "){
ju1="小补丹";
Sleep(1000);
system("cls");
}else if(ju2==" "){
ju2="小补丹";
Sleep(1000);
system("cls");
}else if(ju3==" "){
ju3="小补丹";
Sleep(1000);
system("cls");
}else if(ju4==" "){
ju4="小补丹";
Sleep(1000);
system("cls");
}else if(ju5==" "){
ju5="小补丹";
Sleep(1000);
system("cls");
}else{
cout<<",背包不足";
Sleep(1000);
system("cls");
}
}
else if(random_number%15==4||random_number%15==5){
cout<<"你获得了大补丹";
if(ju1==" "){
ju1="大补丹";
Sleep(1000);
system("cls");
}else if(ju2==" "){
ju2="大补丹";
Sleep(1000);
system("cls");
}else if(ju3==" "){
ju3="大补丹";
Sleep(1000);
system("cls");
}else if(ju4==" "){
ju4="大补丹";
Sleep(1000);
system("cls");
}else if(ju5==" "){
ju5="大补丹";
Sleep(1000);
system("cls");
}else{
cout<<",背包不足";
Sleep(1000);
system("cls");
}
}
else if(random_number%15==6||random_number%15==7||random_number%15==8||random_number%15==9){
cout<<"你获得了火球术";
if(ju1==" "){
ju1="火球术";
Sleep(1000);
system("cls");
}else if(ju2==" "){
ju2="火球术";
Sleep(1000);
system("cls");
}else if(ju3==" "){
ju3="火球术";
Sleep(1000);
system("cls");
}else if(ju4==" "){
ju4="火球术";
Sleep(1000);
system("cls");
}else if(ju5==" "){
ju5="火球术";
Sleep(1000);
system("cls");
}else{
cout<<",背包不足";
Sleep(1000);
system("cls");
}
}
else if(random_number%15==10||random_number%15==11){
cout<<"你获得了大火球术";
if(ju1==" "){
ju1="大火球术";
Sleep(1000);
system("cls");
}else if(ju2==" "){
ju2="大火球术";
Sleep(1000);
system("cls");
}else if(ju3==" "){
ju3="大火球术";
Sleep(1000);
system("cls");
}else if(ju4==" "){
ju4="大火球术";
Sleep(1000);
system("cls");
}else if(ju5==" "){
ju5="大火球术";
Sleep(1000);
system("cls");
}else{
cout<<",背包不足";
Sleep(1000);
system("cls");
}
}
else if(random_number%15==12){
cout<<"你获得了破防术";
if(ju1==" "){
ju1="破防术";
Sleep(1000);
system("cls");
}else if(ju2==" "){
ju2="破防术";
Sleep(1000);
system("cls");
}else if(ju3==" "){
ju3="破防术";
Sleep(1000);
system("cls");
}else if(ju4==" "){
ju4="破防术";
Sleep(1000);
system("cls");
}else if(ju5==" "){
ju5="破防术";
Sleep(1000);
system("cls");
}else{
cout<<",背包不足";
Sleep(1000);
system("cls");
}
}
random_number=rand();
exp+=zz;
maxexp=2*grade+3;
if(exp>=maxexp){
cout<<"请加点。"<<"生命按1("<<blood1+kk<<")伤害按2("<<hurt-1<<")防御按3("<<spirit-1<<")";
while(1){
int d=0;
c=getch();
if(c=='1'){
blood=blood+2;kk=kk+2;
break;
}else if(c=='2'){
hurt++;
break;
}else if(c=='3'){
spirit++;
break;
}
}
system("cls");
exp-=maxexp;
grade++;
}
}
}
return 0;
}
无尽打怪
整挺好的,
srs()
好评awa,
建议:
不推荐用 rand()%6
这种写法,
rand()%6
所实现的是生成随机数 0~5
的数字,
但 rand()%6
所生成的 0~5
的数字概率不是一样,
给你一个更完美的函数:
long long random(long long a,long long b){
return double(rand())/(RAND_MAX+1)*(max(a,b)-min(a,b)+1)+min(a,b);
}
这样 0~5
这些数字概率就是一样的了
其实可以在使用大火球术或小火球术的时候判断一下怪物的血量是否为0,不然在怪物血量为<=0时必须再打一次
推荐大家去试一下
挺好玩的
特别是魔改一下
的确,
我还发现了,玩家血量=0时还能坚持一下(<0没遇到过,不清楚),
不知道是故意的还是bug
改了一下
#include<iostream>
#include<iomanip>
#include<cmath>
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
using namespace std;
long long random(long long a,long long b){
return double(rand())/(RAND_MAX+1)*(max(a,b)-min(a,b)+1)+min(a,b);
}
void srs(){
SYSTEMTIME c;
GetSystemTime(&c);
srand(time(0)*1000+c.wMilliseconds);
}
int main(){
int blood=0,blood1=5,zombieblood=2,spirit=1,spirit1=1,zombiespirit=1,zz=1,zombiespirit1=0,hurt=3,zombiehurt=2,m,n,b;
int g[10],f=0,exp=0,plusexp=0,zombieexp,maxexp=5,grade=1,kk=0,xp=0;
string ju1=" ",ju2=" ",ju3=" ",ju4=" ",ju5=" ";
char c;
long long cnt=0;
srs();
int random_number=rand();
while(1){
blood1=5;
blood=blood1+kk;
for(int i=0;i<grade;i++){
zombieblood=2;
zombiespirit=1;
zombiehurt=2;
srs();
Sleep(5);
random_number=random(0,5);
if(random_number%6==5){
zz++;
}
for(int j=1;j<zz;j++){
srs();
Sleep(5);
random_number=random(0,19);
if(random_number%4==1){
zombiehurt++;
srs();
Sleep(5);
random_number=rand();
}else if(random_number%5==2){
zombiespirit++;
srs();
Sleep(5);
random_number=rand();
}
else{
zombieblood+=2;
srs();
Sleep(5);
random_number=rand();
}
}
m=zombieblood;
b=zombiehurt;
n=zombiespirit;
maxexp=2*grade+3;
while(m>0){
blood1=5;
while(1){
cout<<"你碰到了怪物,它的血"<<m<<",伤"<<b-1<<",防御"<<zombiespirit-1<<","<<zz<<"级"<<endl;
cout<<"你的血"<<blood<<",伤"<<hurt-1<<",防御"<<spirit-1<<"。攻击按q,道具按1到5"<<endl;
cout<<"1."<<ju1<<endl;
cout<<"2."<<ju2<<endl;
cout<<"3."<<ju3<<endl;
cout<<"4."<<ju4<<endl;
cout<<"5."<<ju5<<endl;
cout<<"**已击败"<<cnt<<"只怪物**"<<endl<<endl<<"当前"<<exp<<"点经验"<<","<<"还差"<<maxexp-exp<<"点经验升级"<<endl<<"****"<<grade<<"级****"<<endl<<endl<<endl;
c=getch();
if(c=='q'){
Sleep(5);
srs();
Sleep(5);
random_number=random(0,zombiespirit-1);
n=random_number;
srs();
random_number=random(0,hurt-1);
if(n-random_number%hurt>=0){
m-=0;
cout<<"你造成了"<<0<<"点伤害"<<endl;
Sleep(500);
}else{
m+=floor(n-random_number%hurt);
cout<<"你造成了"<<abs(floor(n-random_number%hurt))<<"点伤害"<<endl;
Sleep(500);
}
srs();
random_number=random(0,3*4*spirit-1);
break;
}
if(c=='1'&&ju1=="小补丹"){
blood+=3;
ju1=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='1'&&ju1=="大补丹"){
blood+=7;
ju1=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='1'&&ju1=="火球术"){
m-=3;
ju1=" ";
}
if(c=='1'&&ju1=="大火球术"){
m-=6;
ju1=" ";
}
if(c=='1'&&ju1=="破防术"){
zombiespirit=1;
ju1=" ";
}
if(c=='2'&&ju2=="小补丹"){
blood+=3;
ju2=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='2'&&ju2=="大补丹"){
blood+=7;
ju2=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='2'&&ju2=="火球术"){
m-=3;
ju2=" ";
}
if(c=='2'&&ju2=="大火球术"){
m-=6;
ju2=" ";
}
if(c=='2'&&ju2=="破防术"){
zombiespirit=1;
ju2=" ";
}
if(c=='3'&&ju3=="小补丹"){
blood+=3;
ju3=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='3'&&ju3=="大补丹"){
blood+=7;
ju3=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='3'&&ju3=="火球术"){
m-=3;
ju3=" ";
}
if(c=='3'&&ju3=="大火球术"){
m-=6;
ju3=" ";
}
if(c=='3'&&ju3=="破防术"){
zombiespirit=1;
ju3=" ";
}
if(c=='4'&&ju4=="小补丹"){
blood+=3;
ju4=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='4'&&ju4=="大补丹"){
blood+=7;
ju4=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='4'&&ju4=="火球术"){
m-=3;
ju4=" ";
}
if(c=='4'&&ju4=="大火球术"){
m-=6;
ju4=" ";
}
if(c=='4'&&ju4=="破防术"){
zombiespirit=1;
ju4=" ";
}
if(c=='5'&&ju5=="小补丹"){
blood+=3;
ju5=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='5'&&ju5=="大补丹"){
blood+=7;
ju5=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='5'&&ju5=="火球术"){
m-=3;
ju5=" ";
}
if(c=='5'&&ju5=="大火球术"){
m-=6;
ju5=" ";
}
if(c=='5'&&ju5=="破防术"){
zombiespirit=1;
ju5=" ";
}
system("cls");
}
if(m<0){
break;
}
if(m<=zombieblood/5&&random_number%3==1&&zz>=2){
srs();
random_number=rand();
cout<<"怪物使用了"<<"小补丹"<<endl;
m+=3;
if(m>zombieblood){
m=zombieblood;
}
}
if(blood>=3&&blood>=zombieblood/2&&random_number%4==1&&zz>=5&&blood>=(blood1+kk)/3*2){
srs();
random_number=rand();
cout<<"怪物使用了"<<"火球术"<<endl;
blood-=3;
}
spirit1=random_number%spirit;
srs();
random_number=random(0,zombiehurt-1);
if(spirit1-random_number%zombiehurt>=0){
blood-=0;
cout<<"怪物造成了"<<0<<"点伤害"<<endl;
Sleep(500);
}else{
blood+=floor(spirit1-random_number%zombiehurt);
cout<<"怪物造成了"<<abs(floor(spirit1-random_number%zombiehurt))<<"点伤害"<<endl;
Sleep(500);
}
srs();
random_number=rand();
system("cls");
if(blood<0){
cout<<"game over"<<endl<<"记录:"<<cnt<<"只"<<endl<<endl;
system("pause");
return 0;
}
}
cout<<"成功击败怪物!";
cnt++;
Sleep(1000);
system("cls");
srs();
random_number=random(0,15*zombiehurt-1);
if(random_number%15==0||random_number%15==1||random_number%15==2||random_number%15==3){
cout<<"你获得了小补丹";
if(ju1==" "){
ju1="小补丹";
Sleep(1000);
system("cls");
srs();
random_number=rand();
}else if(ju2==" "){
ju2="小补丹";
Sleep(1000);
system("cls");
srs();
random_number=rand();
}else if(ju3==" "){
ju3="小补丹";
Sleep(1000);
system("cls");
srs();
random_number=rand();
}else if(ju4==" "){
ju4="小补丹";
Sleep(1000);
system("cls");
srs();
random_number=rand();
}else if(ju5==" "){
ju5="小补丹";
Sleep(1000);
system("cls");
srs();
random_number=rand();
}else{
cout<<",背包不足";
Sleep(1000);
system("cls");
srs();
random_number=rand();
}
}
else if(random_number%15==4||random_number%15==5){
cout<<"你获得了大补丹";
if(ju1==" "){
ju1="大补丹";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else if(ju2==" "){
ju2="大补丹";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else if(ju3==" "){
ju3="大补丹";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else if(ju4==" "){
ju4="大补丹";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else if(ju5==" "){
ju5="大补丹";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else{
cout<<",背包不足";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}
}
else if(random_number%15==6||random_number%15==7||random_number%15==8||random_number%15==9){
cout<<"你获得了火球术";
if(ju1==" "){
ju1="火球术";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else if(ju2==" "){
ju2="火球术";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else if(ju3==" "){
ju3="火球术";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else if(ju4==" "){
ju4="火球术";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else if(ju5==" "){
ju5="火球术";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else{
cout<<",背包不足";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}
}
else if(random_number%15==10||random_number%15==11){
cout<<"你获得了大火球术";
if(ju1==" "){
ju1="大火球术";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else if(ju2==" "){
ju2="大火球术";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else if(ju3==" "){
ju3="大火球术";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else if(ju4==" "){
ju4="大火球术";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else if(ju5==" "){
ju5="大火球术";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else{
cout<<",背包不足";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}
}
else if(random_number%15==12){
cout<<"你获得了破防术";
if(ju1==" "){
ju1="破防术";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else if(ju2==" "){
ju2="破防术";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else if(ju3==" "){
ju3="破防术";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else if(ju4==" "){
ju4="破防术";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else if(ju5==" "){
ju5="破防术";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}else{
cout<<",背包不足";
Sleep(1000);
system("cls");
srand(time(0));
random_number=rand();
}
}
srs();
random_number=rand();
exp+=zz;
maxexp=2*grade+3;
//xp=grade;
if(exp>=maxexp){
cout<<"请加点。"<<"生命按1("<<blood1+kk<<")伤害按2("<<hurt-1<<")防御按3("<<spirit-1<<")";
while(1){
int d=0;
c=getch();
if(c=='1'){
blood=blood+2;kk=kk+2;
break;
}else if(c=='2'){
hurt++;
break;
}else if(c=='3'){
spirit++;
break;
}
}
system("cls");
exp-=maxexp;
grade++;
}
}
}
return 0;
}
还是有 random_number%5
这种写法,建议全改一下,不然概率是不一样的
这次很好
话说都用了万能头了还写那么多头文件干嘛?
万能头中不包含#include <windows.h>
和#include <conio.h>
这两个游戏必备头文件
前面还有一个取随机数,现在概率是一样的
不对,不对,还有问题
#include<iostream>
#include<iomanip>
#include<cmath>
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
using namespace std;
long long random(long long a,long long b){
return double(rand())/(RAND_MAX+1)*(max(a,b)-min(a,b)+1)+min(a,b);
}
void srs(){
SYSTEMTIME c;
GetSystemTime(&c);
srand(time(0)*1000+c.wMilliseconds);
}
int main(){
int blood=0,blood1=5,zombieblood=2,spirit=1,spirit1=1,zombiespirit=1,zz=1,zombiespirit1=0,hurt=3,zombiehurt=2,m,n,b;
int g[10],f=0,exp=0,plusexp=0,zombieexp,maxexp=5,grade=1,kk=0,xp=0;
string ju1=" ",ju2=" ",ju3=" ",ju4=" ",ju5=" ";
char c;
long long cnt=0;
int random_number;
srs();
while(1){
blood1=5;
blood=blood1+kk;
for(int i=0;i<grade;i++){
zombieblood=2;
zombiespirit=1;
zombiehurt=2;
Sleep(5);
random_number=random(0,5);
if(random_number%6==5){
zz++;
}
for(int j=1;j<zz;j++){
Sleep(5);
random_number=random(0,19);
if(random_number%4==1){
zombiehurt++;
Sleep(5);
random_number=rand();
}else if(random_number%5==2){
zombiespirit++;
Sleep(5);
random_number=rand();
}
else{
zombieblood+=2;
Sleep(5);
random_number=rand();
}
}
m=zombieblood;
b=zombiehurt;
n=zombiespirit;
maxexp=2*grade+3;
while(m>0){
blood1=5;
while(1){
cout<<"你碰到了怪物,它的血"<<m<<",伤"<<b-1<<",防御"<<zombiespirit-1<<","<<zz<<"级"<<endl;
cout<<"你的血"<<blood<<",伤"<<hurt-1<<",防御"<<spirit-1<<"。攻击按q,道具按1到5"<<endl;
cout<<"1."<<ju1<<endl;
cout<<"2."<<ju2<<endl;
cout<<"3."<<ju3<<endl;
cout<<"4."<<ju4<<endl;
cout<<"5."<<ju5<<endl;
cout<<"**已击败"<<cnt<<"只怪物**"<<endl<<endl<<"当前"<<exp<<"点经验"<<","<<"还差"<<maxexp-exp<<"点经验升级"<<endl<<"****"<<grade<<"级****"<<endl<<endl<<endl;
c=getch();
if(c=='q'){
Sleep(5);
Sleep(5);
random_number=random(0,zombiespirit-1);
n=random_number;
srs();
random_number=random(0,hurt-1);
if(n-random_number%hurt>=0){
m-=0;
cout<<"你造成了"<<0<<"点伤害"<<endl;
Sleep(500);
}else{
m+=floor(n-random_number%hurt);
cout<<"你造成了"<<abs(floor(n-random_number%hurt))<<"点伤害"<<endl;
Sleep(500);
}
random_number=random(0,3*4*spirit-1);
break;
}
if(c=='1'&&ju1=="小补丹"){
blood+=3;
ju1=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='1'&&ju1=="大补丹"){
blood+=7;
ju1=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='1'&&ju1=="火球术"){
m-=3;
ju1=" ";
}
if(c=='1'&&ju1=="大火球术"){
m-=6;
ju1=" ";
}
if(c=='1'&&ju1=="破防术"){
zombiespirit=1;
ju1=" ";
}
if(c=='2'&&ju2=="小补丹"){
blood+=3;
ju2=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='2'&&ju2=="大补丹"){
blood+=7;
ju2=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='2'&&ju2=="火球术"){
m-=3;
ju2=" ";
}
if(c=='2'&&ju2=="大火球术"){
m-=6;
ju2=" ";
}
if(c=='2'&&ju2=="破防术"){
zombiespirit=1;
ju2=" ";
}
if(c=='3'&&ju3=="小补丹"){
blood+=3;
ju3=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='3'&&ju3=="大补丹"){
blood+=7;
ju3=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='3'&&ju3=="火球术"){
m-=3;
ju3=" ";
}
if(c=='3'&&ju3=="大火球术"){
m-=6;
ju3=" ";
}
if(c=='3'&&ju3=="破防术"){
zombiespirit=1;
ju3=" ";
}
if(c=='4'&&ju4=="小补丹"){
blood+=3;
ju4=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='4'&&ju4=="大补丹"){
blood+=7;
ju4=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='4'&&ju4=="火球术"){
m-=3;
ju4=" ";
}
if(c=='4'&&ju4=="大火球术"){
m-=6;
ju4=" ";
}
if(c=='4'&&ju4=="破防术"){
zombiespirit=1;
ju4=" ";
}
if(c=='5'&&ju5=="小补丹"){
blood+=3;
ju5=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='5'&&ju5=="大补丹"){
blood+=7;
ju5=" ";
if(blood>blood1+kk){
blood=blood1+kk;
}
}
if(c=='5'&&ju5=="火球术"){
m-=3;
ju5=" ";
}
if(c=='5'&&ju5=="大火球术"){
m-=6;
ju5=" ";
}
if(c=='5'&&ju5=="破防术"){
zombiespirit=1;
ju5=" ";
}
system("cls");
}
if(m<0){
break;
}
if(m<=zombieblood/5&&random_number%3==1&&zz>=2){
random_number=rand();
cout<<"怪物使用了"<<"小补丹"<<endl;
m+=3;
if(m>zombieblood){
m=zombieblood;
}
}
if(blood>=3&&blood>=zombieblood/2&&random_number%4==1&&zz>=5&&blood>=(blood1+kk)/3*2){
random_number=rand();
cout<<"怪物使用了"<<"火球术"<<endl;
blood-=3;
}
spirit1=random_number%spirit;
random_number=random(0,zombiehurt-1);
if(spirit1-random_number%zombiehurt>=0){
blood-=0;
cout<<"怪物造成了"<<0<<"点伤害"<<endl;
Sleep(500);
}else{
blood+=floor(spirit1-random_number%zombiehurt);
cout<<"怪物造成了"<<abs(floor(spirit1-random_number%zombiehurt))<<"点伤害"<<endl;
Sleep(500);
}
random_number=rand();
system("cls");
if(blood<0){
cout<<"game over"<<endl<<"记录:"<<cnt<<"只"<<endl<<endl;
system("pause");
return 0;
}
}
cout<<"成功击败怪物!";
cnt++;
Sleep(1000);
system("cls");
random_number=random(0,15*zombiehurt-1);
if(random_number%15==0||random_number%15==1||random_number%15==2||random_number%15==3){
cout<<"你获得了小补丹";
if(ju1==" "){
ju1="小补丹";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju2==" "){
ju2="小补丹";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju3==" "){
ju3="小补丹";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju4==" "){
ju4="小补丹";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju5==" "){
ju5="小补丹";
Sleep(1000);
system("cls");
random_number=rand();
}else{
cout<<",背包不足";
Sleep(1000);
system("cls");
random_number=rand();
}
}
else if(random_number%15==4||random_number%15==5){
cout<<"你获得了大补丹";
if(ju1==" "){
ju1="大补丹";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju2==" "){
ju2="大补丹";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju3==" "){
ju3="大补丹";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju4==" "){
ju4="大补丹";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju5==" "){
ju5="大补丹";
Sleep(1000);
system("cls");
random_number=rand();
}else{
cout<<",背包不足";
Sleep(1000);
system("cls");
random_number=rand();
}
}
else if(random_number%15==6||random_number%15==7||random_number%15==8||random_number%15==9){
cout<<"你获得了火球术";
if(ju1==" "){
ju1="火球术";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju2==" "){
ju2="火球术";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju3==" "){
ju3="火球术";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju4==" "){
ju4="火球术";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju5==" "){
ju5="火球术";
Sleep(1000);
system("cls");
random_number=rand();
}else{
cout<<",背包不足";
Sleep(1000);
system("cls");
random_number=rand();
}
}
else if(random_number%15==10||random_number%15==11){
cout<<"你获得了大火球术";
if(ju1==" "){
ju1="大火球术";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju2==" "){
ju2="大火球术";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju3==" "){
ju3="大火球术";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju4==" "){
ju4="大火球术";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju5==" "){
ju5="大火球术";
Sleep(1000);
system("cls");
random_number=rand();
}else{
cout<<",背包不足";
Sleep(1000);
system("cls");
random_number=rand();
}
}
else if(random_number%15==12){
cout<<"你获得了破防术";
if(ju1==" "){
ju1="破防术";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju2==" "){
ju2="破防术";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju3==" "){
ju3="破防术";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju4==" "){
ju4="破防术";
Sleep(1000);
system("cls");
random_number=rand();
}else if(ju5==" "){
ju5="破防术";
Sleep(1000);
system("cls");
random_number=rand();
}else{
cout<<",背包不足";
Sleep(1000);
system("cls");
random_number=rand();
}
}
random_number=rand();
exp+=zz;
maxexp=2*grade+3;
//xp=grade;
if(exp>=maxexp){
cout<<"请加点。"<<"生命按1("<<blood1+kk<<")伤害按2("<<hurt-1<<")防御按3("<<spirit-1<<")";
while(1){
int d=0;
c=getch();
if(c=='1'){
blood=blood+2;kk=kk+2;
break;
}else if(c=='2'){
hurt++;
break;
}else if(c=='3'){
spirit++;
break;
}
}
system("cls");
exp-=maxexp;
grade++;
}
}
}
return 0;
}
现在肯定对了
我该说什么好呢,还有rand()%n这种写法,慢慢调,不急,
而且原写法用变量存的rand的值,然后再if里%n,
直接将rand()改成random(a,b)是不对的,应当根据你想要的效果确定a,b的值,再在if里直接将判断变量等于几,或制定概率,比如:
int rand_num=random(1,6);
if(rand_num==1||rand_num==2||rand_num==3)({//if(rand_num>=1&&rand_num<=3)
cout<<"1/2的概率";
}
else if(rand_num==4||rand_num==5)({
cout<<"1/3的概率";
}
else{//else if(rand_num==6)
cout<<"1/6的概率";
}
我想的是random()不是%n这样用
你只是将rand的取值范围缩小了,本质上还是概率不相同,比如
int rand_num=random(0,6);
if(rand_num%4==1){
//……
}
算一下可知0~3的概率还是不相同
他是指:
#include<iostream>
#include<iomanip>
#include<cmath>
这三个
所以求了公倍数
例如:
random_number=random(0,3*4*spirit-1);
看到了,这下应该是对的
可以将random_num=rand()删掉了,我看了的,大多都是让rand()单单调用,没有参与判断,足够均匀的情况下,单单调用rand()是不会影响运行效果,代码长度也可以做的精简
你碰到了怪物,它的血-14816,伤1,防御0,2级
你的血7,伤2,防御0。攻击按q,道具按1到5
1.火球术
2.破防术
3.火球术
4.
5.火球术
已击败6只怪物
当前6点经验,还差1点经验升级
2级
没修改过复制粘贴
你碰到了怪物,它的血-22914,伤2,防御0,4级
你的血9,伤2,防御0。攻击按q,道具按1到5
1.火球术
2.火球术
3.火球术
4.火球术
5.火球术
已击败9只怪物
当前7点经验,还差2点经验升级
3级