Ok so I've been messing with this all morning, and I fix one output and just break the others. I need this to end in 2 ways:
player wins:
HURRICANE KICK (or other move)
===========
==YOU WIN==
===========
Player loses:
HURRICANE KICK (or other move)
The opponent attacked you!!! (-20)
=========
==YOU LOSE===
========
Issue is with 'opponent attacked you!!!'. It cant show up before saying the player wins, but has to show before player loses. I've moved it around so "YOU WIN" works right now, but when the player's health hits 0 the code goes one more turn instead of displaying "YOU LOSE".
Example of what I mean:
The opponent attacked you!!! (-20) ///it should display you lose after this line
player health 0 === vs === opponent health: 50
choose one of the movies:
HADOUKEN
===========
====YOU LOSE=====
===========
'opponent attacked you!!!" also cant show up after an invalid input, which is why I used goto.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
# include <iostream>
# include <string>
using namespace std;
int main()
{
bool quit = false;
char inputkey;
int health=100;
int ophealth=100;
cout << "==============================================" << endl;
cout << "Welcome ot the Street Fighter Tutorial Game" << endl;
cout << "Attack the opponent until the healthbar is 0" << endl;
cout << "==============================================" << endl;
while (!quit){
cout << endl;
cout << "Player Health: " << health << " ===== VS ===== Opponent Health: " << ophealth << endl;
cout << endl;
tstart: cout << "Choose one of the moves:" << endl;
cout << "(1) Hadouken: 10 HP (2) Shoryuken: 15 HP (3) Hurricane Kick: 20 HP" <<endl;
cin >> inputkey;
if(inputkey=='1'){
ophealth-=10;
cout<<"HADOUKEN"<<endl;
cout<<endl;
}else if(inputkey=='2'){
ophealth-=15;
cout<<"SHORYUKEN"<<endl;
cout<<endl;
}else if(inputkey=='3'){
ophealth-=20;
cout<<"HURRICANE KICK"<<endl;
cout<<endl;\
}else{
cout<<"Invalid menu selection. Please try again."<<endl;
cout<<endl;
goto tstart;
}
if(ophealth<=0&&health>=1){
cout<<"=============================================="<<endl;
cout<<"====================YOU WIN==================="<<endl;
cout<<"=============================================="<<endl;
quit=true;
}else if(ophealth>=1&&health==0){
cout<<"=============================================="<<endl;
cout<<"====================YOU LOSE=================="<<endl;
cout<<"=============================================="<<endl;
quit=true;
}else{
cout<<"The opponent attacked you!!! (-20)"<<endl;
health-=20;
}
}
return 0;
}
| |