-
March 30th, 2017, 09:14 PM
#1
[RESOLVED] Beginner needs help
Why does my program crash. Also why does HE's(health) value so ridiculously high? One more question, why is at (attack) equal to 1 all the time?
My code:
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <unistd.h>
using namespace std;
int randVal(int min,int max){
return (rand() % (max - min + 1) + min);
}
int main(){
srand(time(NULL));
int bb1,bb2,bb3,hh,aa,HE,ll,tp,na,at,aaplus; //variables for monster one
int bb4,bb5,bb6,hh2,aa2,HE2,ll2,tp2,na2,at2,aaplus2; //variables for monster two
/* bb one through six are body
hh is head
aa is armour
at is attack
HE is health
ll is level
tp is type
na is name */
string Mhead[] = {"( 0 ^ 0 )","| 0 * 0 |","( =^_^= )","( >_< ) ","(<@> <@>)"};
string Mbody1[] = {"1#####1","[[[ ]]]","$ $ ","| ^||^ |"};
string Mbody2[] = {"1#####1","[[[ ]]]","$ $ ","| ^||^ |"};
string Mbody3[] = {"1#####1","[[[ ]]]","| | "," _/|_ "};
string Mname[] = {"Abra","Aipom","Amaura","Arbok","Archen","Aron","Bagon","Beedrill","Beldum","Bayleef","baltoy","Cacnea","Cascoon","Delphox","CHARIZARD",
"Deino","Deerling","Ditto","Dragonair","Drampa","Drowzee","Dustox","Electrabuzz","Emboar","Fearow","Golem","Grimer","Guzzlord","Hypno","Inkay","Invysaur",
"Jolteon","Jynx","Koffinf","Lapras","Latias","Latios","Charmander","Mew","Nidioking","Nidoqueen","Onix","Pichu","Pikachu"};
string Mtype[] = {"Fire","Water","Rock","Air"};
ll = randVal(1,100);
cout<<" input 0,1,2,3, or 4 \n";
cin>>hh;
if(hh < 0 || hh > 4){
cout<<" INVALID INPUT!! re-enter \n";
cin>>hh;
if(hh < 0 || hh > 4){
cout<<" really...";
sleep(3);
return 0;
}
}
cout<<" Now, input 0,1,2, or 3!\n";
cin>>bb1;
if(bb1 < 0 || bb1 > 3){
cout<<" INVALID INPUT!! re-enter \n";
cin>>bb1;
if(bb1 < 0 || bb1 > 3){
cout<<" really...";
sleep(3);
return 0;
}
}
cout<<" again \n";
cin>>bb2;
if(bb2 < 0 || bb2 > 3){
cout<<" INVALID INPUT!! re-enter \n";
cin>>bb2;
if(bb2 < 0 || bb2 > 3){
cout<<"really...";
sleep(3);
return 0;
}
}
cout<<" once more... \n";
cin>>bb3;
if(bb3 < 0 || bb3 > 3){
cout<<" INVALID INPUT!! re-enter \n";
cin>>bb3;
if(bb3 < 0 || bb3 > 3){
cout<< "really...";
sleep(3);
return 0;
}
}
//HEADS - hh
if(hh == 0){
tp = 0;
}
if(hh == 1){
tp == 0;
}
if(hh == 2){
tp == 1;
}
if(hh == 3){
tp == 2;
}
if(hh == 4){
tp == 3;
}
//BODY
//HEALTH - bb1
//HEAVY
if(bb1 == 0 || bb1 == 1){
HE == randVal(1,1150);
}
//LIGHT
if(bb1 == 2 || bb1 == 3){
HE == randVal(1,1000);
}
//ARMOUR - bb2 && bb3
//light
if(bb2 == 2 || bb2 == 3){
aa == randVal(0,450);
}
//HEAVY
if(bb2 == 0 || bb2 == 1){
aa == randVal(0,500);
}
//ARMOUR BOUNUS
//HEAVY
if(bb3 == 0 || bb3 == 1){
aaplus = randVal(0,100);
aa += aaplus;
}
//LIGHT
if(bb3 == 2 || bb3 == 3){
aaplus = randVal(0,50);
aa += aaplus;
}
//ATTACK - AT
//HEAVY
if(bb3 == 0 || bb3 == 1){
at == randVal(1,1000);
}
if(bb3 == 2 || bb3 == 3){
at == randVal(1,1150);
}
cout<<"-------------------- \n";
cout<<" YOUR MONSTER \n \n";
cout<<Mhead[hh]<<endl;
cout<<Mbody1[bb1]<<endl<<Mbody2[bb2]<<endl<<Mbody3[bb3]<<endl<<endl;
cout<<" Name: "<<Mname[na]<<endl;
cout<<" Level: "<<ll<<endl;
cout<<" Type: "<<Mtype[tp]<<endl;
cout<<" Health: "<<HE<<endl;
cout<<" Armour: "<<aa<<endl;
cout<<" Attack: "<<at<<endl;
sleep(4);
cout<<"-------------------- \n";
cout<<" HOSTILE MONSTER \n \n";
ll2 = randVal(1,100);
bb4 = randVal(0,3);
bb5 = randVal(0,3);
bb6 = randVal(0,3);
hh2 = randVal(0,4);
//HEADS - hh
if(hh ==0){
tp == 0;
}
if(hh = 1){
tp == 0;
}
if(hh = 2){
tp == 1;
}
if(hh == 3){
tp == 2;
}
if(hh == 4){
tp == 3;
}
//BODY
//HEALTH - bb4
//HEAVY
if(bb4 == 0 || bb4 == 1){
HE2 == randVal(1,1150);
}
//LIGHT
if(bb4 == 2 || bb4 == 3){
HE2 == randVal(1,1000);
}
//ARMOUR - bb5 && bb6
//light
if(bb5 == 2 || bb5 == 3){
aa2 == randVal(0,450);
}
//HEAVY
if(bb5 == 0 || bb5 == 1){
aa2 = randVal(0,500);
}
//ARMOUR BOUNUS
//HEAVY
if(bb6 == 0 || bb6 == 1){
aaplus2 = randVal(0,100);
aa2 += aaplus2;
}
//LIGHT
if(bb6 == 2 || bb6 == 3){
aaplus2 = randVal(0,50);
aa2 +=+ aaplus;
}
//ATTACK - AT
//HEAVY
if(bb6 == 0 || bb6 == 1){
at2 == randVal(1,1000);
}
if(bb6 == 2 || bb6 == 3){
at2 == randVal(1,1150);
}
cout<<Mhead[hh2]<<endl;
cout<<Mbody1[bb4]<<endl<<Mbody2[bb5]<<endl<<Mbody3[bb6]<<endl<<endl;
cout<<" Name: "<<Mname[na2]<<endl;
cout<<" Level: "<<ll2<<endl;
cout<<" Type: "<<Mtype[tp2]<<endl;
cout<<" Health: "<<HE2<<endl;
cout<<" Armour: "<<aa2<<endl;
cout<<" Attack: "<<at2<<endl;
sleep(4);
cout<<"-------------------- \n";
cout<<" !!!FIGHT!!! \n";
cout<<Mhead[hh]<<" "<<Mhead[hh2]<<endl;
cout<<Mbody1[bb1]<<" "<<Mbody1[bb4]<<endl;
cout<<Mbody2[bb2]<<" vs "<<Mbody2[bb5]<<endl;
cout<<Mbody3[bb3]<<" "<<Mbody3[bb6]<<endl;
HE += aa;
HE2 += aa2;
HE += aa;
HE2 += aa2;
while(HE > 0 && HE2 > 0){
sleep(3);
cout<<endl;
if(tp == tp2){
HE -= at2;
HE2 -= at;
cout<<" You used "<<Mtype[tp]<<" attack for "<<at<<endl;
cout<<" Their health is "<<HE2<<endl;
sleep(1);
cout<<" They used "<<Mtype[tp2]<<" attack for "<<at2<<endl;
cout<<" Your health is "<<HE<<endl;
sleep(2);
}
if(tp == 1 && tp2 == 2){
HE -= at2;
HE2 -= at;
cout<<" You used "<<Mtype[tp]<<" attack for "<<at<<endl;
cout<<" Their health is "<<HE2<<endl;
sleep(1);
cout<<" They used "<<Mtype[tp2]<<" attack for "<<at2<<endl;
cout<<" Your health is "<<HE<<endl;
sleep(2);
}
if(tp == 1 && tp2 == 3){
at2 *= 1.2;
HE -= at2;
HE2 -= at;
cout<<" You used "<<Mtype[tp]<<" attack for "<<at<<endl;
cout<<" Their health is "<<HE2<<endl;
sleep(1);
cout<<" They used "<<Mtype[tp2]<<" attacl for "<<at2<<endl;
cout<<" Your health is "<<HE<<endl;
sleep(2);
}
if(tp == 1 && tp2 == 0){
at *= 1.2;
HE -= at2;
HE2 -= at;
cout<<" You used "<<Mtype[tp]<<" attack for "<<at<<endl;
cout<<" Their health is "<<HE2<<endl;
sleep(1);
cout<<" They used "<<Mtype[tp2]<<" attack for "<<at2<<endl;
cout<<" Your health is "<<HE<<endl;
sleep(2);
}
if(tp == 0 && tp2 == 1){
at2 *= 1.2;
HE -= at2;
HE2 -= at;
cout<<" You used "<<Mtype[tp]<<" attack for "<<at<<endl;
cout<<" Their health is "<<HE2<<endl;
sleep(1);
cout<<" They used "<<Mtype[tp2]<<" attack for "<<at2<<endl;
cout<<" Your health is "<<HE<<endl;
sleep(2);
}
if(tp == 0 && tp2 == 2){
at *= 1.2;
HE -= at2;
HE2 -= at;
cout<<" You used "<<Mtype[tp]<<" attack for "<<at<<endl;
cout<<" Their health is "<<HE2<<endl;
sleep(1);
cout<<" They used "<<Mtype[tp2]<<" attack for "<<at2<<endl;
cout<<" Your health is "<<HE<<endl;
sleep(2);
}
if(tp == 0 && tp2 == 3){
HE -= at2;
HE2 -= at;
cout<<" You used "<<Mtype[tp]<<" attack for "<<at<<endl;
cout<<" Their health is "<<HE2<<endl;
sleep(1);
cout<<" They used "<<Mtype[tp2]<<" attack for "<<at2<<endl;
cout<<" Your health is "<<HE<<endl;
sleep(2);
}
if(tp == 2 && tp2 == 0){
at2 *= 1.2;
HE -= at2;
HE2 -= at;
cout<<" You used "<<Mtype[tp]<<" attack for "<<at<<endl;
cout<<" Their health is "<<HE2<<endl;
sleep(1);
cout<<" They used "<<Mtype[tp2]<<" attack for "<<at2<<endl;
cout<<" Your health is "<<HE<<endl;
sleep(2);
}
if(tp == 2 && tp2 == 1){
at2 *= 1.2;
HE -= at2;
HE2 -= at;
cout<<" You used "<<Mtype[tp]<<" attack for "<<at<<endl;
cout<<" Their health is "<<HE2<<endl;
sleep(1);
cout<<" They used "<<Mtype[tp2]<<" attack for "<<at2<<endl;
cout<<" Your health is "<<HE<<endl;
sleep(2);
}
if(tp == 2 && tp2 == 3){
at *= 1.2;
HE -= at2;
HE2 -= at;
cout<<" You used "<<Mtype[tp]<<" attack for "<<at<<endl;
cout<<" Their health is "<<HE2<<endl;
sleep(1);
cout<<" They used "<<Mtype[tp2]<<" attack for "<<at2<<endl;
cout<<" Your health is "<<HE<<endl;
sleep(2);
}
if(tp == 3 && tp2 == 0){
HE -= at2;
HE2 -= at;
cout<<" You used "<<Mtype[tp]<<" attack for "<<at<<endl;
cout<<" Their health is "<<HE2<<endl;
sleep(1);
cout<<" They used "<<Mtype[tp2]<<" attack for "<<at2<<endl;
cout<<" Your health is "<<HE<<endl;
sleep(2);
}
if(tp == 3 && tp2 == 1){
at *= 1.2;
HE -= at2;
HE2 -= at;
cout<<" You used "<<Mtype[tp]<<" attack for "<<at<<endl;
cout<<" Their health is "<<HE2<<endl;
sleep(1);
cout<<" They used "<<Mtype[tp2]<<" attack for "<<at2<<endl;
cout<<" Your health is "<<HE<<endl;
sleep(2);
}
if(tp == 3 && tp2 == 2){
at2 *= 1.2;
HE -= at2;
HE2 -= at;
cout<<" You used "<<Mtype[tp]<<" attack for "<<at<<endl<<endl;
cout<<" Their health is "<<HE2<<endl;
sleep(1);
cout<<" They used "<<Mtype[tp2]<<" attack for "<<at2<<endl<<endl;
cout<<" Your health is "<<HE<<endl;
sleep(2);
}
}
cout<<endl;
if(HE < 0 && HE2 > 0){
cout<<" YOUR MONSTER LOST \n";
cout<<" Their health is "<<HE2<<endl;
}
else if(HE2 < 0 && HE > 0){
cout<<" YOUR MONSTER WON!!!! \n";
cout<<" Your health is "<<HE<<endl;
}
else{
cout<<"!DRAW! \n";
}
string endGAME;
cout<<endl<<"type end to quit \n";
cin>>endGAME;
return 0;
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|