Hello Guys ! Look at my new game ! :]

Write your question here.
This game has a lot of bugs but it still looks good for me ! Im a beginner and learning C++ its really fun (Im 13 years old )
yeah first time posting on cplusplus.com
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
  #include <iostream>
#include <string>


int main(){
	
	int myHealth = 400; // My Health
	int enemyHealth = 410; // Enemy's Health
	int attack; // The attack of the user
	int mana = 450; // The energy of the user
	
	std::cout << "enemy's health : 410  || Your health : 400 ||BE CAREFUL " << std::endl;;
	std::cout << "Enemys health : 410" << std::endl;
	std::cout << "Your HEALTH : 400 " << std::endl;
	std::cout << " Your max attacks : 100" << std::endl;
	std::cout << " YOUR ENERGY ( MANA ) : 450 " << std::endl;
	std::cout << " if u do attacks less than 50 you will have more mana ( with more mana u can do more damage to enemy) " << std::endl;

	std::cin >> attack;
	if (attack > 100) { //if users enters wrong number
		std::cout << "Your max attack is 100 not " << attack << " please quit and enter the game again " << std::endl;
	}
	if (attack < 51) { //if users enter number less than 50 //
		mana = mana - 70;
		enemyHealth = enemyHealth - attack;
		if (enemyHealth < 0) {
			std::cout << "You Win" << std::endl;
		}
		std::cout << "mana remain " << mana << " enemy's health : " << enemyHealth << std::endl;	
		int x = 0; //this variable helps user to enters 3 more attacks //
		while (x <= 3) {
			std::cin >> attack;
			x++;
			std::cout << "enemy's remain health : " << enemyHealth - attack << std::endl;
		}
		
	}
	system("pause");
	return 0;
}
Last edited on
Great, now it's time to make full use of those variables that you defined early in main:

std::cout << "enemy's health : " << enemyHealth << " || Your health : " << myHealth << " ||BE CAREFUL " << std::endl;

This way, if you decide to change the value of the enemyHealth, you only have to change it at the top of main, you don't have to track down every time that number might be mentioned.

Next: what happens if the user enters 75? You can catch that with an else if statement:
1
2
3
4
5
6
7
8
if (attack < 51)
{
     // do stuff for attack 50 or less
}
else if(attack >= 51 && attack <= 100)
{
    // do stuff for attacks between 51 and 100
}
Last edited on
I like it, it's a good start!
Don't give up and you'll make it perfect.

For example, consider that in your row 34:
std::cout << "enemy's remain health : " << enemyHealth - attack << std::endl;
You are not modifying the value in variable enemyHealth.

In your row 25
enemyHealth = enemyHealth - attack;
you do it the right way.

Happy coding!
Topic archived. No new replies allowed.