0

Can anyone see the problem with my method ATTACK

#include "Monster.h"
#include "Player.h"
#include "Weapon.h"
#include <iostream>
using namespace std;


Monster::Monster(std::string Name, int health, int hitPoints,
		    int miss, int damage,const std::string& weaponName)

{
	Name = Name;
	hitPoints = hitPoints;
	Weapon weapon;
	miss = miss;
	damage = damage;
	weapon.Name = weaponName;



}

bool Monster::Death()
{
	return hitPoints <= 0;
}
std::string Monster::getName()
{
	return Name;
}


void Monster::attack(Player& player)
{
	cout << "A " << Name << " attacks you "
		<<"with a " << weapon.Name << endl;
		int damage = weapon.weaponHitPoints;
		int totalDamage = damage;
		if(totalDamage <= 0)
		{
			cout << "The monster's attack failed to "
				<< "penetrate your armour." << endl;
		}
		else
		{
			cout << "You are hit for " << totalDamage
				<< " damage!" << endl;
			player.takeDamage(totalDamage);
		}
	}
	else 
	{
		cout << "The " << Name << "missed!" << endl;
	}
	cout << endl;
}
2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by pendo826
0

Did you figure the problem out? I see it is marked as solved but you didn't edit your post or post your solution.

The problem I see is that you are missing an if() to go with your bottom else statement.

0

Did you figure the problem out? I see it is marked as solved but you didn't edit your post or post your solution.

The problem I see is that you are missing an if() to go with your bottom else statement.

Ye thanks i figured it out i just had a block on my brain lol. Thanks anyway.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.