need help with rpg fights

oddly, after a battle with any monster including after changing the hp, strength, etc, your health always goes down to one.

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
  #include <iostream>

#include <string>

using namespace std;
	
class player
{

public:

string name;

int hp;

int maxhp;

int food;

int hunger;

int selection;

int defense;

int strength;

};

class monster
{
public:

	int hp;

	int defense;

	int strength;

};

int main()
{

	system("title Adventure!");

	Dead:

	system("CLS");

	player player;

	int day = 0;

	player.defense = 3;

	player.hp = 100;
		
	player.food = 0;
	
	player.hunger = 0;

	player.maxhp = 100;

	player.strength = 10;

	cout << "Who are you?" << endl;

	cin >> player.name;

	system("CLS");
	
	cout << "Ok " << player.name << ", you have awoken deep in a forest, you remember nothing except your name." << endl;
	
	system("Pause");
	
	system("CLS");
	
	while(true){

		cout << "Day: " << day << endl << "Food: " << player.food << endl << "Health: " << player.hp << endl << "Hunger: " << player.hunger << "/35" << endl << "What shall you do today?" << endl << "1.Forage for food." << endl << "2.Nothing." << endl << "3.Explore." << endl;
		
		cin >> player.selection;
		
		system("CLS");

		if(player.selection == 1) player.food = player.food + 2;

		if((player.selection == 2)&&((player.hp < player.maxhp)&&(player.food > 0)))player.hp++;
		
		if(player.selection == 3)
		{

			monster monster;

			monster.hp = 100;

			monster.strength = 3;
			
			monster.defense = 2;

			cout << "You encounter a monster!" << endl << "Enemy HP: " << monster.hp << endl << "Your AP: " << player.strength << endl << "your HP: "  << player.hp << endl << "1. Fight." << endl << "2. Run." << endl;

			cin >> player.selection;
			
			if(player.selection == 1)
			{
				while((player.hp > 0)||(monster.hp > 0))
				{
					
					if(player.defense < monster.strength) player.hp = player.hp - (monster.strength - player.defense);
					if(monster.defense < player.strength) monster.hp = monster.hp - (player.strength - monster.defense);
				
				}
			}
			system("CLS");
		}	
Last edited on
oddly, after a battle with any monster including after changing the hp, strength, etc, your health always goes down to one.


Oddly, a battle can never end until both the player's hp and the monster's hp are less than or equal to 0.

while((player.hp > 0)||(monster.hp > 0))

should be

while((player.hp > 0) && (monster.hp > 0))
Topic archived. No new replies allowed.