Help!

For my programming final we have to make this "game".
It just has characters and stats and reads in movements from a data file. If the players come within 10 units, the moving player attacks the stationary player. The attack is equal to the attacking players strength * their weapon damage/1000, * the opponent's shield/100. (Yes the teacher messed up the shield stats so that the higher block amount means they actually take more damage.)
Anyway, it runs fine, it reds in the right numbers, outputs everything correctly. however, no one's health changes. I can't figure out why. Any help would be great.

The code for an attack looks like this:
Prototype:
void p1p2Battle(int p1Health, int MACH_DMG, int p2Shield, int& p2Health, string p1Name, string p2Name, ofstream& dout);

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
 if (p1Health > 0)	//if p1 health is above 0
		{
			din >> move;		// din the movement
			p1Loc = p1Loc + move; // add the movement to p1's location
			if (p1Loc > 99)			// if location is more than 100
				p1Loc = p1Loc % 100;	// then the new location equals the remainder 
										// over 100
			
			//determines if p1 and p2 are within battle range
			p1p2Range = p1Loc - p2Loc;	
			// if the range between players is within 10 spaces
			if (p1p2Range > -10 && p1p2Range < 10)
			{
				// call func p1p2battle to determine p2 health remaining
				p1p2Battle(p1Health, MACH_DMG, p2Shield, p2Health, p1Name, p2Name, dout);
			}

			// determines if p1 and p3 are within battle range
			p1p3Range = p1Loc - p2Loc;
			//if the range between players is within 10 spaces
			if (p1p3Range > -10 && p1p3Range < 10)
			{
				// call func p1p3battle to determine p3 remaining health
				p1p3Battle(p1Health, MACH_DMG, p3Shield, p3Health, p1Name, p3Name, dout);
			}
		}


Then the functions are:
1
2
3
4
5
6
7
8
9
10
void p1p2Battle(int p1Health, int MACH_DMG, int p2Shield, int& p2Health, string p1Name, string p2Name, ofstream& dout)
{
	// p2 health = p2health minus p1health times the weapon damage divided by 1000. 
	// value is reduced by multiplying p2 shield/100
	p2Health = p2Health - (((p1Health * MACH_DMG) / 1000)* (p2Shield / 100));

	// outputs a record of the battle for the round summary
	dout << p1Name << "Attacks " << p2Name << "." << endl;

}


Then just switched with data for the others. Can anyone see why the health won't change?
Last edited on
What's the value of p2Shield MACH_DMG and p1Health?

It looks like it's a integer division problem (999/1000 = 0).
Add a .0 after 1000 and 100 to make it a double division:

p2Health = p2Health - (((p1Health * MACH_DMG) / 1000.0)* (p2Shield / 100.0));
const int MACH_DMG = 83; //strike power of machete

p2Shield and p1Health are read in from a file (so he can switch it and have it still run).
But for this file

p2Shield = 53

p1Health = 242

He told us to use integers and not worry about floats or anything.



EDIT: I just added the .0 to the ends of 1000 and 100. It works now. Thanks so much.
Last edited on
slestr94 wrote:
Yes the teacher messed up the shield stats so that the higher block amount means they actually take more damage.


slestr94 wrote:
He told us to use integers and not worry about floats or anything.


Lol motivated prof you've got there- cool base project though, with a couple tweaks you could make a simple text based rpg style style game. I've never taken any programming courses myself, but I am glad you are doing something that's relatively useful/fun. My buddies university 4th year final involved drawing a train sprite moving from the left side to the right side of the screen...
Topic archived. No new replies allowed.