Help please

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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* 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>
using namespace 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;

Regards Isaac Skelton
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:

I moved it here.
Topic archived. No new replies allowed.