/*
* DESCRIPTION: THIS GAME IS A GAME WHERE YOU MUST USE YOUR ATTACKS TO TAKE DOWN THE OTHER CHARACTER.
* HOPEFUL UPDATES: I AM HOPING TO ADD IN A GUI EVENTUALLY, AFTER I FINISH THE C++ CODE I WILL BEGIN ON A JAVA VERSION WITH A GUI.
* MAYBE IF I GET MORE ENVOLVED I WILL ADD IN A LEVEL UP SECTION WHERE YOU CAN BYE NEW ITEMS/ATTACK OR NEW CHARACTERS.
* MADE BY: SKELDEV
* AUTHOR: ISAAC SKELTON
* NOTES: LEAVE THIS COMMENT IN HERE
* THIS IS MY SECOND C++ GAME
* DATE CREATED: 06/09/2012
*/
#include <iostream>
#include <string>
usingnamespace std;
int main() //MAIN FUNCTION
{
mainMenu: //MAIN MENU ANCHOR FOR "GOTO" COMMAND
//TEXT ON THE MAIN MENU SCREEN
cout << "\n\n\n\n\n\n\n\n\n\nWelcome to Creature Wars\n\n\n";
cout << "Type in one of the numbers below to enter your option\n\n";
cout << "1) Play Game\n";
cout << "2) Exit\n";
cout << "Option:\t";
//INTEGER VARIABLE NAME FOR USERS INPUT (CIN)
int mainInput;
//USERS INPUT FOR MAIN MENU OPTION
cin >> mainInput;
//IF USER INPUT EQUALS 1
if(mainInput == 1) {
selectionMenuAnchor:
cout << "\n\n\n\n\n\n\n\n\n\nSelect Difficulty\n";
cout << "1) Easy\n";
cout << "2) Medium\n";
cout << "3) Hard\n";
cout << "4) Return to Main Menu\n";
//USER INPUT VARIABLE FOR DIFFICULTY MENU SELECTION
int difficultyInput;
//USERS INPUT FOR DIFFICULTY MENU SELECTION
cin >> difficultyInput;
//IF USER INPUT EQUALS 1
if(difficultyInput == 1) {
//CREATE A ATTACK SECTION ANCHOR
attackSection:
//EASY GAME
//YOUR LIFE VARIABLE
int yourLifeLineAmount = 100;
//THEIR LIFE VARIABLE
int theirLifeLineAmount = 100;
//LIFE LINES VISABLE TO USER USING COUT
cout << "Your Life " << yourLifeLineAmount << "\n";
cout << "There Life " << theirLifeLineAmount << "\n\n";
//ATTACK MENU TITLE COUT
cout << "Your Attack List\n";
//USER INPUT VARIABLE FOR ATTACK ITEM SELECTION
int attackSelection;
//PUNCH - UNLIMITED
//COMBO PUNCHES x2 PER ROUND
//LIFE DRAINER x1 PER ROUND
//HEALER x1 PER ROUND
//SQUASH x1 PER ROUND IF OVER 50 POINTS IN TWO ATTACKS
//ATTACK SELECTION LIST COUT
cout << "1) Punch: UNLIMITED\n";
int comboUsesLeft = 2;
int drainUsesLeft = 1;
int healUsesLeft = 1;
int squashUsesLeft = 0;
cout << "2) Combo Punch: " << comboUsesLeft << endl; //VARIABLE GETS HOW MANY COMBO PUNCHES THE USER HAS LEFT
cout << "3) Life Drainer: " << drainUsesLeft << endl; //VARIABLE GETS HOW MANY LIFE DRAINERS THE USER HAS LEFT
cout << "4) Heal Yourself: " << healUsesLeft << endl; //VARIABLE GETS HOW MANY HEALERS THE USER HAS LEFT
cout << "5) Squash: " << squashUsesLeft << endl; //VARIABLE GETS HOW MANY SQUASHES THE USER HAS LEFT
//GETS USERS INPUT FOR ATTACK ITEM SELECTION
cin >> attackSelection;
//IF USER INPUT EQUALS 1
if(attackSelection == 1) {
//PUNCHES TAKE AWAY 5 HP
theirLifeLineAmount = theirLifeLineAmount - 5;
}
//IF USER INPUT EQUALS 2
if(attackSelection == 2) {
//COMBO'S TAKE AWAY 20 HP
theirLifeLineAmount = theirLifeLineAmount - 20;
//VARIABLES FOR HOW MANY OF COMBO'S THEY HAVE LEFT
int comboUsesLeft = 2;
//MINUS ONE USE IF IT IS USED
comboUsesLeft - 1;
//IF THERE ARE NO MORE COMBO'S LEFT THIS WILL HAPPEN
if(comboUsesLeft = 0) {
//DISABLE COMBO PUNCHES
}
}
//IF USER INPUT EQUALS 3
if(attackSelection == 3) {
//DRAINER TAKES AWAY 40 HP
theirLifeLineAmount - 40;
//VARIABLE FOR HOW MANY DRAINERS THEY HAVE LEFT
int drainUsesLeft = 1;
//MINUS ONE USE IF IT IS USED
drainUsesLeft - 1;
//IF THERE ARE NO MORE DRAINERS LEFT THIS WILL HAPPEN
if(drainUsesLeft == 0) {
//DISABLE DRAINER
}
}
//IF USER INPUT EQUALS 4
if(attackSelection == 4) {
//HEALER GIVES YOU 30 HP
yourLifeLineAmount + 30;
//VARIABLE FOR HOW MANY HEALERS THEY HAVE LEFT
int healUsesLeft = 1;
//MINUS ONE USE IF IT IS USED
healUsesLeft - 1;
//IF THERE ARE NO MORE HEALERS LEFT THIS WILL HAPPEN
if(healUsesLeft == 0) {
//DISABLE HEALER
}
}
//IF USER INPUT EQAULS 5
if(attackSelection == 5) {
//SQUASH TAKES AWAY A TURN FROM THE COMPUTER OR USER
}
//IF NONE OF THEM IS SELECTED
else {
//GOTO THE ATTACK SECTION (ATTACK SELECTION MENU)
goto attackSection;
}
}
//IF USERS INPUT EQAULS 2 (MEDIUM)
if(difficultyInput == 2) {
}
//IF USERS INPUT EQUALS 3 (HARD)
if(difficultyInput == 3) {
}
//IF USERS INPUT EQUALS 4 (MAIN MENU)
if(difficultyInput == 4) {
//GOTO MAIN MENU
goto mainMenu;
}
//IF NOTHING WAS TYPED IN THIS WILL OCCUR
else {
//TEXT
cout << "Nothing was selected, reseting difficulty for reuse...";
//GOTO THE SELECTION MENU ANCHOR
goto selectionMenuAnchor;
}
if(mainInput == 2) {
cout << "Exiting...";
}
else {
cout << "Nothing was selected, reseting main menu for reuse...";
goto mainMenu;
}
}
}
Your Life 100
There Life 100
Your Attack List
1) Punch: UNLIMITED
2) Combo Punch: 2
3) Life Drainer: 1
4) Heal Yourself: 1
5) Squash: 0
1
Your Life 100
There Life 100
Your Attack List
1) Punch: UNLIMITED
2) Combo Punch: 2
3) Life Drainer: 1
4) Heal Yourself: 1
5) Squash: 0
I have only displayed one section of this applications output because thats the bit with a problem. As you can see the life stays the same even thought I have punched which is meant to take away 5 from there life, but it isn't. How can I resolve this problem. I have supplied you with all the source code that I have done and urgently wan't a solution so please help. The line that I think is the main for this problem is... theirLifeLineAmount = theirLifeLineAmount - 5;
The problem is you are declaring these variables at the start of the main game loop everytime.
1 2 3
int yourLifeLineAmount = 100;
//THEIR LIFE VARIABLE
int theirLifeLineAmount = 100;
So once it has finished your turn it goes back to the start here and their values get changed back to 100, ignoring whatever it was before. To solve this move those 2 variables so they are declared somewhere above the main loop so they wont get included every time.
On a side note it is generally looked down upon to go 'goto' as it can make code very hard to follow and make it harder to debug. I suggest you try using while/do-while loops instead.
It worked, thanks for the great answer. If you could, do you know how I could make the computer randomly select one of those choices as well. If not code maybe a website for a random command.
1 2 3 4 5 6 7
//EASY GAME
//YOUR LIFE VARIABLE
int yourLifeLineAmount = 100;
//THEIR LIFE VARIABLE
int theirLifeLineAmount = 100;
//CREATE A ATTACK SECTION ANCHOR
attackSection: