13 Replies - 534 Views - Last Post: 05 August 2014 - 01:50 PM Rate Topic: -----

#1 Rithian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 22-January 14

Not Understanding What Is Happening

Posted 03 August 2014 - 09:00 PM

Hi there, sorry for just dropping of the map, but been really busy at work. Anyway I began work on a text based rpg battle program and I do not understand why the formula I wrote is give me a weird number. Here is the code (there is a lot of it)

(my head files) Header_Files.h
#ifndef HEADER_FILES_H
#define HEADER_FILES_H

#include <string>
#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

#endif



(my classes file) Classes.h
#ifndef CLASSES_H
#define CLASSES_H

#include "Header_Files.h"

class Characters
{
private:
	string Name;
	int Level;
	int HitPoints;
	int ManaPoints;
	int Strength; // adds to damage and defence
	int Intelligence; // adds to magic damage
	int Constitution; // adds to hit points
	int Dexterity; // adds to evasion and attack (and defence only if higher than strength)
	int Wisdom; // adds to mana points and magic attack
	int Charisma; // adds to magic defence
	int Weapon;
	int Armor;
	int Accessory1;
	int Accessory2;
	int Gold;
	int Experience;
	int Max_HP;
	int Max_MP;
	int Attack;
	int MagicAttack;
	int Damage;
	int MagicDamage;
	int Defence;
	int MagicDefence;
	int Evasion;

public:
	// character constuctor
	Characters(string NAME, int L, int MHP, int MMP, 
		int STR, int INT, int CON, int DEX, int WIS, int CHA, 
		int WEAPON, int ARMOR, int ACCESSORY1, int ACCESSORY2, 
		int GOLD, int EXPERIENCE,
		int ATTACK, int MAGICATTACK, int DEFENCE, int MAGICDEFENCE, int EVASION);

	//set functions
	void SetName(string name);
	void SetLevel(int level);
	void SetMaxHealth(int maxhp);
	void SetHealth();
	void SetMaxMana(int maxmp);
	void SetMana();
	void SetStrength(int strength);
	void SetIntelligence(int intelligence);
	void SetConstitution(int constitution);
	void SetDexterity(int dexterity);
	void SetWisdom(int wisdom);
	void SetCharisma(int charisma);
	void SetWeapon(int weapon);
	void SetArmor(int armor);
	void SetAccessory1(int accessory1);
	void SetAccessory2(int accessory2);
	void SetGold(int gold);
	void SetExperience(int experience);
	void SetAttack(int attack);
	void SetMagicAttack(int magicattack);
	void SetDamage(int damage);
	void SetMagicDamage(int magicdamage);
	void SetDefence(int defence);
	void SetMagicDefence(int magicdefence);
	void SetEvasion(int evasion);

	string GetName() {return Name;}
	int GetLevel() {return Level;}
	int GetMaxHealth() {return Max_HP;}
	int GetCurrentHealth() {return HitPoints;}
	int GetMaxMana() {return Max_MP;}
	int GetCurrentMana() {return ManaPoints;}
	int GetStrength() {return Strength;}
	int GetIntelligence() {return Intelligence;}
	int GetConstitution() {return Constitution;}
	int GetDexterity() {return Dexterity;}
	int GetWisdom() {return Wisdom;}
	int GetCharisma() {return Charisma;}
	int GetWeapon() {return Weapon;}
	int GetArmor() {return Armor;}
	int GetAccessory1() {return Accessory1;}
	int GetAccessory2() {return Accessory2;}
	int GetGold() {return Gold;}
	int GetExperience() {return Experience;}
	int GetAttack() {return Attack;}
	int GetMagicAttack() {return MagicAttack;}
	int GetDamage() {return Damage;}
	int GetDefence() {return Defence;}
	int GetMagicDamage() {return MagicDamage;}
	int GetMagicDefence() {return MagicDefence;}
	int GetEvasion() {return Evasion;}
};

Characters Char1(), Char2(), Char3();

class Weapons
{
private:
	string WeaponName;
	int StrengthBonus;
	int IntelligenceBonus;
	int AttackBonusModifier;
	int MagicAttackBonusModifier;
	int DamageModifier;
	int MagicDamageModifier;

public:
	Weapons(string WEAPONNAME, int STRBON, int INTBON, 
						 int ABM, int MABM, 
						 int DM,  int MDM);
	void SetWeaponName(string weapon_name);
	void SetStrengthBonus(int strengthbonus);
	void SetIntelligenceBonus(int intelligencebonus);
	void SetAttackBonusModifier(int attackmodifier);
	void SetMagicAttackBonusModifier(int magicattackmodifier);
	void SetDamageModifier(int damagemodifier);
	void SetMagicDamageModifier(int magicdamagemodifier);

	string GetWeaponName() {return WeaponName;}
	int GetStrengthBonus() {return StrengthBonus;}
	int GetIntelligenceBonus() {return IntelligenceBonus;}
	int GetAttackBonusModifier() {return AttackBonusModifier;}
	int GetMagicAttackBonusModifier() {return MagicAttackBonusModifier;}
	int GetDamageModifier() {return DamageModifier;}
	int GetMagicDamageModifier() {return MagicDamageModifier;}
};

Weapons Weap1(), Weap2(), Weap3();

class Armors
{
private:
	string ArmorName;
	int DexterityBonus;
	int DefenceBonus;
	int MagicDefenceBonus;
	int EvasionBonus;

public:
	Armors(string ARMORNAME, int DEXBON,
			int DEFBON, int MDEFBON, int EVABON);
	void SetArmorName(string armorname);
	void SetDexterityBonus(int dexteritybonus);
	void SetDefenceBonus(int defencebonus);
	void SetMagicDefenceBonus(int magicdefencebonus);
	void SetEvasionBonus(int evasionbonus);

	string GetArmorName() {return ArmorName;}
	int GetArmorDexterityBonus() {return DexterityBonus;}
	int GetArmorDefenceBonus() {return DefenceBonus;}
	int GetArmorMagicDefenceBonus() {return MagicDefenceBonus;}
	int GetArmorEvasionBonus() {return EvasionBonus;}
};

Armors Armor1(), Armor2(), Armor3();

class Accessories
{
	string AccessoryName;
	int StrengthBonus;
	int IntelligenceBonus;
	int ConstitutionBonus;
	int DexterityBonus;
	int WisdomBonus;
	int CharismaBonus;
	int AttackBonus;
	int MagicAttackBonus;
	int DefenceBonus;
	int MagicDefenceBonus;
	int EvasionBonus;

public:
	Accessories (string ACCESSORYNAME, int ACCSTRBON, int ACCINTBON, int ACCCONBON,
					int ACCDEXBON, int ACCWISBON, int ACCCHABON, 
					int ACCATTBON, int ACCMAGATTBON, int ACCDEFBON, int ACCMAGDEFBON,
					int ACCEVABON);
	void SetAccessoryName (string accessoryname);
	void SetAccessoryStrengthBonus(int strengthbonus);
	void SetAccessoryIntelligenceBonus(int intelligencebonus);
	void SetAccessoryConstitutionBonus(int constitutionbonus);
	void SetAccessoryDexterityBonus(int dexterityBonus);
	void SetAccessoryWisdomBonus(int wisdombonus);
	void SetAccessoryCharismaBonus(int charismabonus);
	void SetAccessoryAttackBonus(int attackbonus);
	void SetAccessoryMagicAttackBonus(int magicattackbonus);
	void SetAccessoryDefenceBonus(int defencebonus);
	void SetAccessoryMagicDefenceBonus(int magicdefencebonus);
	void SetAccessoryEvasionBonus(int evasionbonus);

	string GetAccessoryName() {return AccessoryName;}
	int GetAccessoryStrengthBonus() {return StrengthBonus;}
	int GetAccessoryIntelligenceBonus() {return IntelligenceBonus;}
	int GetAccessoryConstitutionBonus() {return ConstitutionBonus;}
	int GetAccessoryDexterityBonus() {return DexterityBonus;}
	int GetAccessoryWisdomBonus() {return WisdomBonus;}
	int GetAccessoryCharismaBonus() {return CharismaBonus;}
	int GetAccessoryAttackBonus() {return AttackBonus;}
	int GetAccessoryMagicAttackBonus() {return MagicAttackBonus;}
	int GetAccessoryDefenceBonus() {return DefenceBonus;}
	int GetAccessoryMagicDefenceBonus() {return MagicDefenceBonus;}
	int GetAccessoryEvasionBonus() {return EvasionBonus;}
};

Accessories Accessory1(), Accessory2(), Accessory3(), 
			Accessory4(), Accessory5(), Accessory6();

class Items
{
private:
	string ItemName;
	int HealthRestored;
	bool Revive;

public:
	Items(string ITEMNAME, int HEALTHRESTORED, bool ISALIVE);
	void SetItemName(string itemname);
	void SetItemHealthRestored(int healthrestored);
	void SetItemRevive(bool revive);

	string GetItemName() {return ItemName;}
	int GetItemHealthRestored() {return HealthRestored;}
	bool GetItemRevive() {return Revive;}
};

Items Item1(), Item2(), Item3();

class Enemies
{
private:
	string EnemyName;
	int EnemyLevel;
	int EnemyHitPoints;
	int EnemyManaPoints;
	int EnemyStrength;
	int EnemyIntelligence;
	int EnemyConstitution;
	int EnemyDexterity;
	int EnemyWisdom;
	int EnemyCharisma;
	int EnemyMax_HP;
	int EnemyMax_MP;
	int EnemyAttack;
	int EnemyMagicAttack;
	int EnemyDamage;
	int EnemyMagicDamage;
	int EnemyDefence;
	int EnemyMagicDefence;
	int EnemyEvasion;
	int EnemyGoldReward;
	int EnemyExperienceReward;

public:
	Enemies(string ENEMYNAME, int ENEMYLEVEL, int EMHP, int EMMP,
		int ESTR, int EINT, int ECON, int EDEX, int EWIS, int ECHA,
		int EATT, int EMAGATT, int EDEF, int EMAGDEF, int E_Eva,
		int GOLDREWARD, int EXPERIENCEREWARD);
	
	void SetEnemyName(string enemyname);
	void SetEnemyLevel(int enemylevel);
	void SetEnemyMaxHealth(int maxhp);
	void SetEnemyHealth();
	void SetEnemyMaxMana(int maxmp);
	void SetEnemyMana();
	void SetEnemyStrength(int enemystrength);
	void SetEnemyIntelligence(int enemyintelligence);
	void SetEnemyConstitution(int enemyconstitution);
	void SetEnemyDexterity(int enemydexterity);
	void SetEnemyWisdom(int enemywisdom);
	void SetEnemyCharisma(int enemycharisma);
	void SetEnemyAttack(int enemyattack);
	void SetEnemyMagicAttack(int enemymagicattack);
	void SetEnemyDamage(int enemydamage);
	void SetEnemyMagicDamage(int enemymagicdamage);
	void SetEnemyDefence(int enemydefence);
	void SetEnemyMagicDefence(int enemymagicdefence);
	void SetEnemyEvasion(int enemyevasion);
	void SetEnemyGoldReward(int enemygoldreward);
	void SetEnemyExperienceReward(int enemy_experiencereward);

	string GetEnemyName() {return EnemyName;}
	int GetEnemyLevel() {return EnemyLevel;}
	int GetEnemyMaxHealth() {return EnemyMax_HP;}
	int GetEnemyCurrentHealth() {return EnemyHitPoints;}
	int GetEnemyMaxMana() {return EnemyMax_MP;}
	int GetEnemyCurrentMana() {return EnemyManaPoints;}
	int GetEnemyStrength() {return EnemyStrength;}
	int GetEnemyIntelligence() {return EnemyIntelligence;}
	int GetEnemyConstitution() {return EnemyConstitution;}
	int GetEnemyDexterity() {return EnemyDexterity;}
	int GetEnemyWisdom() {return EnemyWisdom;}
	int GetEnemyCharisma() {return EnemyCharisma;}
	int GetEnemyAttack() {return EnemyAttack;}
	int GetEnemyMagicAttack() {return EnemyMagicAttack;}
	int GetEnemyDamage() {return EnemyDamage;}
	int GetEnemyMagicDamage() {return EnemyMagicDamage;}
	int GetEnemyDefence() {return EnemyDefence;}
	int GetEnemyMagicDefence() {return EnemyMagicDefence;}
	int GetEnemyEvasion() {return EnemyEvasion;}
	int GetEnemyGoldReward() {return EnemyGoldReward;}
	int GetEnemyExperienceReward() {return EnemyExperienceReward;}
};

Enemies Enem1(), Enem2(), Enem3(), Boss();

#endif



(my classes cpp file) Classes.cpp
#include "Classes.h"

// all character class functions
Characters::Characters(string NAME, int L, int MHP, int MMP, 
					   int STR, int INT, int CON, int DEX, int WIS, int CHA, 
					   int WEAPON, int ARMOR, int ACCESSORY1, int ACCESSORY2, 
					   int GOLD, int EXPERIENCE,
					   int ATTACK, int MAGICATTACK, int DEFENCE, int MAGICDEFENCE, int EVASION)
{
	SetName(NAME);
	SetLevel(L);
	SetMaxHealth(MHP);
	SetMaxMana(MMP);
	SetStrength(STR);
	SetIntelligence(INT);
	SetConstitution(CON);
	SetDexterity(DEX);
	SetWisdom(WIS);
	SetCharisma(CHA);
	SetWeapon(WEAPON);
	SetArmor(ARMOR);
	SetAccessory1(ACCESSORY1);
	SetAccessory2(ACCESSORY2);
	SetGold(GOLD);
	SetAttack(ATTACK);
	SetMagicAttack(MAGICATTACK);
	SetDefence(DEFENCE);
	SetMagicDefence(MAGICDEFENCE);
	SetEvasion(EVASION);
}

void Characters::SetName(string name)
{
	Name = name;
}

void Characters::SetLevel(int level)
{
	Level = level;
}

void Characters::SetMaxHealth(int maxhp)
{
	Max_HP = (Constitution * (maxhp * Level) / 10);
}

void Characters::SetHealth()
{
	HitPoints = Max_HP;
}

void Characters::SetMaxMana(int maxmp)
{
	Max_MP = (Wisdom * (maxmp * Level) / 50);
}

void Characters::SetMana()
{
	ManaPoints = Max_MP;
}

void Characters::SetStrength(int strength)
{
	Strength = strength;
}

void Characters::SetIntelligence(int intelligence)
{
	Intelligence = intelligence;
}

void Characters::SetConstitution(int constitution)
{
	Constitution = constitution;
}

void Characters::SetDexterity(int dexterity)
{
	Dexterity = dexterity;
}

void Characters::SetWisdom(int wisdom)
{
	Wisdom = wisdom;
}

void Characters::SetCharisma(int charisma)
{
	Charisma = charisma;
}

void Characters::SetWeapon(int weapon)
{
	Weapon = weapon;
}

void Characters::SetArmor(int armor)
{
	Armor = armor;
}

void Characters::SetAccessory1(int accessory1)
{
	Accessory1 = accessory1;
}

void Characters::SetAccessory2(int accessory2)
{
	Accessory2 = accessory2;
}

void Characters::SetGold(int gold)
{
	Gold = gold;
}

void Characters::SetExperience(int experience)
{
	Experience = experience;
}

void Characters::SetAttack(int attack)
{
	Attack = ((((Dexterity + Level + attack)^3 / 32) + 32) / 16);
}

void Characters::SetMagicAttack(int magicattack)
{
	MagicAttack = ((((Wisdom + Level + magicattack)^3 / 32) + 32) / 16);
}

void Characters::SetDefence(int defence)
{
	if (Dexterity > Strength)
	{
		Defence = ((((Dexterity + Level + defence)^3 / 32) + 32) / 16);
	}
	else
	{
		Defence = ((((Strength + Level + defence)^3 / 32) + 32) / 16);
	}
}

void Characters::SetMagicDefence(int magicdefence)
{
	MagicDefence = ((((Charisma + Level + magicdefence)^3 / 32) + 32) / 16);
}

void Characters::SetEvasion(int evasion)
{
	Evasion = (Dexterity * (evasion * Level) / 98);
}

void Characters::SetDamage(int damage)
{
	Damage = (Attack + ((Strength / 2) + damage));
}

void Characters::SetMagicDamage(int magicdamage)
{
	MagicDamage = (MagicAttack + ((Intelligence / 2) + magicdamage));
}

// all weapon class functions
Weapons::Weapons(string WEAPONNAME, int STRBON, int INTBON, int ABM, int MABM, int DM, int MDM)
{
	SetWeaponName(WEAPONNAME);
	SetStrengthBonus(STRBON);
	SetIntelligenceBonus(INTBON);
	SetAttackBonusModifier(ABM);
	SetMagicAttackBonusModifier(MABM);
	SetDamageModifier(DM);
	SetMagicDamageModifier(MDM);
}
void Weapons::SetWeaponName(string weapon_name)
{
	WeaponName = weapon_name;
}

void Weapons::SetStrengthBonus(int strengthbonus)
{
	StrengthBonus = strengthbonus;
}

void Weapons::SetIntelligenceBonus(int intelligencebonus)
{
	IntelligenceBonus = intelligencebonus;
}

void Weapons::SetAttackBonusModifier(int attackmodifier)
{
	AttackBonusModifier = attackmodifier;
}

void Weapons::SetMagicAttackBonusModifier(int magicattackmodifier)
{
	MagicAttackBonusModifier = magicattackmodifier;
}

void Weapons::SetDamageModifier(int damagemodifier)
{
	DamageModifier = damagemodifier;
}

void Weapons::SetMagicDamageModifier(int magicdamagemodifier)
{
	MagicDamageModifier = magicdamagemodifier;
}

// all armor class functions
Armors::Armors(string ARMORNAME, int DEXBON, int DEFBON, int MDEFBON, int EVABON)
{
	SetArmorName(ARMORNAME);
	SetDexterityBonus(DEXBON);
	SetDefenceBonus(DEFBON);
	SetMagicDefenceBonus(MDEFBON);
	SetEvasionBonus(EVABON);
}

void Armors::SetArmorName(string armorname)
{
	ArmorName = armorname;
}

void Armors::SetDexterityBonus(int dexteritybonus)
{
	DexterityBonus = dexteritybonus;
}

void Armors::SetDefenceBonus(int defencebonus)
{
	DefenceBonus = defencebonus;
}

void Armors::SetMagicDefenceBonus(int magicdefencebonus)
{
	MagicDefenceBonus = magicdefencebonus;
}

void Armors::SetEvasionBonus(int evasionbonus)
{
	EvasionBonus = evasionbonus;
}

// all accessory class functions
Accessories::Accessories(string ACCESSORYNAME, int ACCSTRBON, int ACCINTBON, int ACCCONBON, 
						 int ACCDEXBON, int ACCWISBON, int ACCCHABON, 
						 int ACCATTBON, int ACCMAGATTBON, int ACCDEFBON, int ACCMAGDEFBON, 
						 int ACCEVABON)
{
	SetAccessoryName(ACCESSORYNAME);
	SetAccessoryStrengthBonus(ACCSTRBON);
	SetAccessoryIntelligenceBonus(ACCINTBON);
	SetAccessoryConstitutionBonus(ACCCONBON);
	SetAccessoryDexterityBonus(ACCDEXBON);
	SetAccessoryWisdomBonus(ACCWISBON);
	SetAccessoryCharismaBonus(ACCCHABON);
	SetAccessoryAttackBonus(ACCATTBON);
	SetAccessoryMagicAttackBonus(ACCMAGATTBON);
	SetAccessoryDefenceBonus(ACCDEFBON);
	SetAccessoryMagicDefenceBonus(ACCMAGDEFBON);
	SetAccessoryEvasionBonus(ACCEVABON);
}

void Accessories::SetAccessoryName(std::string accessoryname)
{
	AccessoryName = accessoryname;
}

void Accessories::SetAccessoryStrengthBonus(int strengthbonus)
{
	StrengthBonus = strengthbonus;
}

void Accessories::SetAccessoryIntelligenceBonus(int intelligencebonus)
{
	IntelligenceBonus = intelligencebonus;
}

void Accessories::SetAccessoryConstitutionBonus(int constitutionbonus)
{
	ConstitutionBonus = constitutionbonus;
}

void Accessories::SetAccessoryDexterityBonus(int dexteritybonus)
{
	DexterityBonus = dexteritybonus;
}

void Accessories::SetAccessoryWisdomBonus(int wisdombonus)
{
	WisdomBonus = wisdombonus;
}

void Accessories::SetAccessoryCharismaBonus(int charismabonus)
{
	CharismaBonus = charismabonus;
}

void Accessories::SetAccessoryAttackBonus(int attackbonus)
{
	AttackBonus = attackbonus;
}

void Accessories::SetAccessoryMagicAttackBonus(int magicattackbonus)
{
	MagicAttackBonus = magicattackbonus;
}

void Accessories::SetAccessoryDefenceBonus(int defencebonus)
{
	DefenceBonus = defencebonus;
}

void Accessories::SetAccessoryMagicDefenceBonus(int magicdefencebonus)
{
	MagicDefenceBonus = magicdefencebonus;
}

void Accessories::SetAccessoryEvasionBonus(int evasionbonus)
{
	EvasionBonus = evasionbonus;
}

// all items class functions
Items::Items(string ITEMNAME, int HEALTHRESTORED, bool REVIVE)
{
	SetItemName(ITEMNAME);
	SetItemHealthRestored(HEALTHRESTORED);
	SetItemRevive(REVIVE);
}

void Items::SetItemName(string itemname)
{
	ItemName = itemname;
}

void Items::SetItemHealthRestored(int healthrestored)
{
	HealthRestored = healthrestored;
}

void Items::SetItemRevive(bool revive)
{
	Revive = revive;
}

Enemies::Enemies(std::string ENEMYNAME, int ENEMYLEVEL, int EMHP, int EMMP, 
				 int ESTR, int EINT, int ECON, int EDEX, int EWIS, int ECHA, 
				 int EATT, int EMAGATT, int EDEF, int EMAGDEF, int E_EVA, 
				 int GOLDREWARD, int ENEMY_EXPERIENCEREWARD)
{
	SetEnemyName(ENEMYNAME);
	SetEnemyLevel(ENEMYLEVEL);
	SetEnemyMaxHealth(EMHP);
	SetEnemyMaxMana(EMMP);
	SetEnemyStrength(ESTR);
	SetEnemyIntelligence(EINT);
	SetEnemyConstitution(ECON);
	SetEnemyDexterity(EDEX);
	SetEnemyWisdom(EWIS);
	SetEnemyCharisma(ECHA);
	SetEnemyAttack(EATT);
	SetEnemyMagicAttack(EMAGATT);
	SetEnemyDefence(EDEF);
	SetEnemyMagicDefence(EMAGDEF);
	SetEnemyEvasion(E_EVA);
	SetEnemyGoldReward(GOLDREWARD);
	SetEnemyExperienceReward(ENEMY_EXPERIENCEREWARD);
}

void Enemies::SetEnemyName (string enemyname)
{
	EnemyName = enemyname;
}

void Enemies::SetEnemyLevel(int enemylevel)
{
	EnemyLevel = enemylevel;
}

void Enemies::SetEnemyMaxHealth(int enemymaxhp)
{
	EnemyMax_HP = ((EnemyConstitution * (enemymaxhp * EnemyLevel)) / 10);
}

void Enemies::SetEnemyHealth()
{
	EnemyHitPoints = EnemyMax_HP;
}

void Enemies::SetEnemyMaxMana (int enemymaxmp)
{
	EnemyMax_MP = (EnemyWisdom * (enemymaxmp * EnemyLevel) / 50);
}

void Enemies::SetEnemyMana()
{
	EnemyManaPoints = EnemyMax_MP;
}

void Enemies::SetEnemyStrength(int enemystrength)
{
	EnemyStrength = enemystrength;
}

void Enemies::SetEnemyIntelligence(int enemyintelligence)
{
	EnemyIntelligence = enemyintelligence;
}

void Enemies::SetEnemyConstitution(int enemyconstitution)
{
	EnemyConstitution = enemyconstitution;
}

void Enemies::SetEnemyDexterity(int enemydexterity)
{
	EnemyDexterity = enemydexterity;
}

void Enemies::SetEnemyWisdom(int enemywisdom)
{
	EnemyWisdom = enemywisdom;
}

void Enemies::SetEnemyCharisma(int enemycharisma)
{
	EnemyCharisma = enemycharisma;
}

void Enemies::SetEnemyAttack(int enemyattack)
{
	EnemyAttack = ((((EnemyDexterity + EnemyLevel + enemyattack)^3 / 32) + 32) / 16);
}

void Enemies::SetEnemyMagicAttack(int enemymagicattack)
{
	EnemyMagicAttack = ((((EnemyWisdom + EnemyLevel + enemymagicattack)^3 / 32) + 32) / 16);
}

void Enemies::SetEnemyDefence(int enemydefence)
{
	if (EnemyDexterity > EnemyStrength)
	{
		EnemyDefence = ((((EnemyDexterity + EnemyLevel + enemydefence)^3 / 32) + 32) / 16);
	}
	else
	{
		EnemyDefence = ((((EnemyStrength + EnemyLevel + enemydefence)^3 / 32) + 32) / 16);
	}
}

void Enemies::SetEnemyMagicDefence(int enemymagicdefence)
{
	EnemyMagicDefence = ((((EnemyCharisma + EnemyLevel + enemymagicdefence)^3 / 32) + 32) / 16);
}

void Enemies::SetEnemyEvasion(int enemyevasion)
{
	EnemyEvasion = (EnemyDexterity * (enemyevasion * EnemyLevel) / 98);
};

void Enemies::SetEnemyDamage(int enemydamage)
{
	EnemyDamage = (EnemyAttack + ((EnemyStrength / 2) + enemydamage));
}

void Enemies::SetEnemyMagicDamage(int enemymagicdamage)
{
	EnemyMagicDamage = (EnemyMagicAttack + ((EnemyIntelligence / 2) + enemymagicdamage));
}

void Enemies::SetEnemyGoldReward(int enemygoldreward)
{
	EnemyGoldReward = enemygoldreward;
}

void Enemies::SetEnemyExperienceReward(int enemy_experiencereward)
{
	EnemyExperienceReward = enemy_experiencereward;
}



(my list of character etcetera) CharEnemItemList.h
#ifndef CHARENEMITEMLIST_H
#define CHARENEMITEMLIST_H

#include "Classes.h"

string InputName;

Characters Character1()
{
	cout << "Please Enter Your Name Here: ";
	cin >> InputName;
	cout << endl;
	return Characters(InputName, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
}

Characters Character2()
{
	return Characters("Maria", 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); 
}

Characters Character3()
{
	return Characters("George", 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
}

Weapons Weapon1()
{
	return Weapons("Sword", 0,0,0,0,0,0);
}

Weapons Weapon2()
{
	return Weapons("Staff", 0,0,0,0,0,0);
}

Weapons Weapon3()
{
	return Weapons("Axe", 0,0,0,0,0,0);
}

Armors Armors1()
{
	return Armors("Leather Vest", 0,0,0,0);
}

Armors Armors2()
{
	return Armors("Silk Robe", 0,0,0,0);
}

Armors Armors3()
{
	return Armors("Steel Plate", 0,0,0,0);
}

Enemies Enemy1()
{
	return Enemies("Goblin", 1,100,50,0,0,5,0,0,0,0,0,0,0,0,0,0);
}

Enemies Enemy2()
{
	return Enemies("Kobold", 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
}

Enemies Enemy3()
{
	return Enemies("Lizard", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
}

void go()
{
	cout << "Hello ";
}

#endif



(my battle file) Battle.h
#ifndef BATTLE_H
#define BATTLE_H

#include "CharEnemItemList.h"
#include "Classes.h"

void Initiative()
{
	int FirstStrike;
	int BackAttack;
	int char1_init;
	int char2_init;
	int char3_init;
	int enem1_init;
	int enem2_init;
	int enem3_init;
	int Standard = 4;

	FirstStrike = rand() % 5 + 1;
	BackAttack = rand() % 5 + 1;
	char1_init = rand() % 10 + 1;
	char2_init = rand() % 10 + 1;
	char3_init = rand() % 10 + 1;
	enem1_init = rand() % 10 + 1;
	enem2_init = rand() % 10 + 1;
	enem3_init = rand() % 10 + 1;

	if (FirstStrike > Standard || BackAttack > Standard)
	{
		if (FirstStrike > BackAttack)
		{
			if (char1_init > char2_init && char1_init > char3_init)
			{
			}
			else if (char2_init > char1_init && char2_init > char3_init)
			{
			}
			else if (char3_init > char1_init && char3_init > char2_init)
			{
			}
		}
		else
		{
			if (enem1_init > enem2_init && enem1_init > enem3_init)
			{
			}
			else if(enem2_init > enem1_init && enem1_init > enem3_init)
			{
			}
			else if(enem3_init > enem1_init && enem3_init > enem2_init)
			{
			}
		}
	}
	
}

void Battle()
{
	Characters Char1 = Character1();
	Characters Char2 = Character2();
	Characters Char3 = Character3();
	Enemies Enem1 = Enemy1();
	Enemies Enem2 = Enemy2();
	Enemies Enem3 = Enemy3();
	bool bip = true;
	int PartyHealth = Char1.GetMaxHealth() + Char2.GetMaxHealth() + Char3.GetMaxHealth();
	int EnemyHealth = Enem1.GetEnemyMaxHealth() + Enem2.GetEnemyMaxHealth() + Enem3.GetEnemyMaxHealth();

	while (bip == true)
	{
		cout << "\t\t" << Enem1.GetEnemyName() << "\t\t";
		cout << Enem2.GetEnemyName() << "\t\t";
		cout << Enem3.GetEnemyName() << endl;

		cout << "\t\t" << Enem1.GetEnemyCurrentHealth() << "\t\t";
		
		if (EnemyHealth <= 0)
		{
			bip = false;
		}

		if (PartyHealth <= 0)
		{
			bip = false;
		}
	}
}

void char1_actions()
{
}


#endif



(my main file) main.cpp
#include "Battle.h"

int main ()
{	
	Battle();

	system("PAUSE");
	return 0;
}



My problem (if that is what you want to call it) is in the battle file when it displays the enemies hp. If you leave it at get Enem1.GetEnemyCurrentHealth() (like it is now) you get this huge negative number and if you change it to Enem1.GetEnemyMax_HP() you will get a -8. Now I am good at math and based on my health formula Enem1.GetEnemyMax_HP() should equal 50 points and theoretically (based on previous int to int conversions I have done before) Enem1.GetEnemyCurrentHealth() should equal whatever Enem1.GetEnemyMax_HP() is. I will continue to try to fix my problem, but any insight, advise, explanation, or help would be greatly appreciated. Thanks in advance:)

Is This A Good Question/Topic? 0
  • +

Replies To: Not Understanding What Is Happening

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3576
  • View blog
  • Posts: 11,126
  • Joined: 05-May 12

Re: Not Understanding What Is Happening

Posted 03 August 2014 - 09:12 PM

Your GetEnemyCurrentHealth() just returns the value of the EnemyHitPoints member variable. That member is only set when you call SetEnemyHealth(). I'm not seeing where you call SetEnemyHealth(), which then leads me to conclude that you are using an uninitialized variable which can contain any random data.
Was This Post Helpful? 0
  • +
  • -

#3 Rithian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 22-January 14

Re: Not Understanding What Is Happening

Posted 03 August 2014 - 09:13 PM

I fixed the Enem1.GetCurrentHealth problem (I forgot to put SetEnemyHealth() in the Enemies constructor) but I am still working on my formula problem.
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3576
  • View blog
  • Posts: 11,126
  • Joined: 05-May 12

Re: Not Understanding What Is Happening

Posted 03 August 2014 - 09:17 PM

Post the updated code.
Was This Post Helpful? 0
  • +
  • -

#5 Rithian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 22-January 14

Re: Not Understanding What Is Happening

Posted 04 August 2014 - 04:42 AM

Here is the updated code (it is only one file, the rest stay the same)

Classes.cpp
#include "Classes.h"

// all character class functions
Characters::Characters(string NAME, int L, int MHP, int MMP, 
					   int STR, int INT, int CON, int DEX, int WIS, int CHA, 
					   int WEAPON, int ARMOR, int ACCESSORY1, int ACCESSORY2, 
					   int GOLD, int EXPERIENCE,
					   int ATTACK, int MAGICATTACK, int DEFENCE, int MAGICDEFENCE, int EVASION)
{
	SetName(NAME);
	SetLevel(L);
	SetMaxHealth(MHP);
	SetHealth();
	SetMaxMana(MMP);
	SetMana();
	SetStrength(STR);
	SetIntelligence(INT);
	SetConstitution(CON);
	SetDexterity(DEX);
	SetWisdom(WIS);
	SetCharisma(CHA);
	SetWeapon(WEAPON);
	SetArmor(ARMOR);
	SetAccessory1(ACCESSORY1);
	SetAccessory2(ACCESSORY2);
	SetGold(GOLD);
	SetAttack(ATTACK);
	SetMagicAttack(MAGICATTACK);
	SetDefence(DEFENCE);
	SetMagicDefence(MAGICDEFENCE);
	SetEvasion(EVASION);
}

void Characters::SetName(string name)
{
	Name = name;
}

void Characters::SetLevel(int level)
{
	Level = level;
}

void Characters::SetMaxHealth(int maxhp)
{
	Max_HP = (Constitution * (maxhp * Level) / 10);
}

void Characters::SetHealth()
{
	HitPoints = Max_HP;
}

void Characters::SetMaxMana(int maxmp)
{
	Max_MP = (Wisdom * (maxmp * Level) / 50);
}

void Characters::SetMana()
{
	ManaPoints = Max_MP;
}

void Characters::SetStrength(int strength)
{
	Strength = strength;
}

void Characters::SetIntelligence(int intelligence)
{
	Intelligence = intelligence;
}

void Characters::SetConstitution(int constitution)
{
	Constitution = constitution;
}

void Characters::SetDexterity(int dexterity)
{
	Dexterity = dexterity;
}

void Characters::SetWisdom(int wisdom)
{
	Wisdom = wisdom;
}

void Characters::SetCharisma(int charisma)
{
	Charisma = charisma;
}

void Characters::SetWeapon(int weapon)
{
	Weapon = weapon;
}

void Characters::SetArmor(int armor)
{
	Armor = armor;
}

void Characters::SetAccessory1(int accessory1)
{
	Accessory1 = accessory1;
}

void Characters::SetAccessory2(int accessory2)
{
	Accessory2 = accessory2;
}

void Characters::SetGold(int gold)
{
	Gold = gold;
}

void Characters::SetExperience(int experience)
{
	Experience = experience;
}

void Characters::SetAttack(int attack)
{
	Attack = ((((Dexterity + Level + attack)^3 / 32) + 32) / 16);
}

void Characters::SetMagicAttack(int magicattack)
{
	MagicAttack = ((((Wisdom + Level + magicattack)^3 / 32) + 32) / 16);
}

void Characters::SetDefence(int defence)
{
	if (Dexterity > Strength)
	{
		Defence = ((((Dexterity + Level + defence)^3 / 32) + 32) / 16);
	}
	else
	{
		Defence = ((((Strength + Level + defence)^3 / 32) + 32) / 16);
	}
}

void Characters::SetMagicDefence(int magicdefence)
{
	MagicDefence = ((((Charisma + Level + magicdefence)^3 / 32) + 32) / 16);
}

void Characters::SetEvasion(int evasion)
{
	Evasion = (Dexterity * (evasion * Level) / 98);
}

void Characters::SetDamage(int damage)
{
	Damage = (Attack + ((Strength / 2) + damage));
}

void Characters::SetMagicDamage(int magicdamage)
{
	MagicDamage = (MagicAttack + ((Intelligence / 2) + magicdamage));
}

// all weapon class functions
Weapons::Weapons(string WEAPONNAME, int STRBON, int INTBON, int ABM, int MABM, int DM, int MDM)
{
	SetWeaponName(WEAPONNAME);
	SetStrengthBonus(STRBON);
	SetIntelligenceBonus(INTBON);
	SetAttackBonusModifier(ABM);
	SetMagicAttackBonusModifier(MABM);
	SetDamageModifier(DM);
	SetMagicDamageModifier(MDM);
}
void Weapons::SetWeaponName(string weapon_name)
{
	WeaponName = weapon_name;
}

void Weapons::SetStrengthBonus(int strengthbonus)
{
	StrengthBonus = strengthbonus;
}

void Weapons::SetIntelligenceBonus(int intelligencebonus)
{
	IntelligenceBonus = intelligencebonus;
}

void Weapons::SetAttackBonusModifier(int attackmodifier)
{
	AttackBonusModifier = attackmodifier;
}

void Weapons::SetMagicAttackBonusModifier(int magicattackmodifier)
{
	MagicAttackBonusModifier = magicattackmodifier;
}

void Weapons::SetDamageModifier(int damagemodifier)
{
	DamageModifier = damagemodifier;
}

void Weapons::SetMagicDamageModifier(int magicdamagemodifier)
{
	MagicDamageModifier = magicdamagemodifier;
}

// all armor class functions
Armors::Armors(string ARMORNAME, int DEXBON, int DEFBON, int MDEFBON, int EVABON)
{
	SetArmorName(ARMORNAME);
	SetDexterityBonus(DEXBON);
	SetDefenceBonus(DEFBON);
	SetMagicDefenceBonus(MDEFBON);
	SetEvasionBonus(EVABON);
}

void Armors::SetArmorName(string armorname)
{
	ArmorName = armorname;
}

void Armors::SetDexterityBonus(int dexteritybonus)
{
	DexterityBonus = dexteritybonus;
}

void Armors::SetDefenceBonus(int defencebonus)
{
	DefenceBonus = defencebonus;
}

void Armors::SetMagicDefenceBonus(int magicdefencebonus)
{
	MagicDefenceBonus = magicdefencebonus;
}

void Armors::SetEvasionBonus(int evasionbonus)
{
	EvasionBonus = evasionbonus;
}

// all accessory class functions
Accessories::Accessories(string ACCESSORYNAME, int ACCSTRBON, int ACCINTBON, int ACCCONBON, 
						 int ACCDEXBON, int ACCWISBON, int ACCCHABON, 
						 int ACCATTBON, int ACCMAGATTBON, int ACCDEFBON, int ACCMAGDEFBON, 
						 int ACCEVABON)
{
	SetAccessoryName(ACCESSORYNAME);
	SetAccessoryStrengthBonus(ACCSTRBON);
	SetAccessoryIntelligenceBonus(ACCINTBON);
	SetAccessoryConstitutionBonus(ACCCONBON);
	SetAccessoryDexterityBonus(ACCDEXBON);
	SetAccessoryWisdomBonus(ACCWISBON);
	SetAccessoryCharismaBonus(ACCCHABON);
	SetAccessoryAttackBonus(ACCATTBON);
	SetAccessoryMagicAttackBonus(ACCMAGATTBON);
	SetAccessoryDefenceBonus(ACCDEFBON);
	SetAccessoryMagicDefenceBonus(ACCMAGDEFBON);
	SetAccessoryEvasionBonus(ACCEVABON);
}

void Accessories::SetAccessoryName(std::string accessoryname)
{
	AccessoryName = accessoryname;
}

void Accessories::SetAccessoryStrengthBonus(int strengthbonus)
{
	StrengthBonus = strengthbonus;
}

void Accessories::SetAccessoryIntelligenceBonus(int intelligencebonus)
{
	IntelligenceBonus = intelligencebonus;
}

void Accessories::SetAccessoryConstitutionBonus(int constitutionbonus)
{
	ConstitutionBonus = constitutionbonus;
}

void Accessories::SetAccessoryDexterityBonus(int dexteritybonus)
{
	DexterityBonus = dexteritybonus;
}

void Accessories::SetAccessoryWisdomBonus(int wisdombonus)
{
	WisdomBonus = wisdombonus;
}

void Accessories::SetAccessoryCharismaBonus(int charismabonus)
{
	CharismaBonus = charismabonus;
}

void Accessories::SetAccessoryAttackBonus(int attackbonus)
{
	AttackBonus = attackbonus;
}

void Accessories::SetAccessoryMagicAttackBonus(int magicattackbonus)
{
	MagicAttackBonus = magicattackbonus;
}

void Accessories::SetAccessoryDefenceBonus(int defencebonus)
{
	DefenceBonus = defencebonus;
}

void Accessories::SetAccessoryMagicDefenceBonus(int magicdefencebonus)
{
	MagicDefenceBonus = magicdefencebonus;
}

void Accessories::SetAccessoryEvasionBonus(int evasionbonus)
{
	EvasionBonus = evasionbonus;
}

// all items class functions
Items::Items(string ITEMNAME, int HEALTHRESTORED, bool REVIVE)
{
	SetItemName(ITEMNAME);
	SetItemHealthRestored(HEALTHRESTORED);
	SetItemRevive(REVIVE);
}

void Items::SetItemName(string itemname)
{
	ItemName = itemname;
}

void Items::SetItemHealthRestored(int healthrestored)
{
	HealthRestored = healthrestored;
}

void Items::SetItemRevive(bool revive)
{
	Revive = revive;
}

Enemies::Enemies(std::string ENEMYNAME, int ENEMYLEVEL, int EMHP, int EMMP, 
				 int ESTR, int EINT, int ECON, int EDEX, int EWIS, int ECHA, 
				 int EATT, int EMAGATT, int EDEF, int EMAGDEF, int E_EVA, 
				 int GOLDREWARD, int ENEMY_EXPERIENCEREWARD)
{
	SetEnemyName(ENEMYNAME);
	SetEnemyLevel(ENEMYLEVEL);
	SetEnemyMaxHealth(EMHP);
	SetEnemyHealth();
	SetEnemyMaxMana(EMMP);
	SetEnemyMana();
	SetEnemyStrength(ESTR);
	SetEnemyIntelligence(EINT);
	SetEnemyConstitution(ECON);
	SetEnemyDexterity(EDEX);
	SetEnemyWisdom(EWIS);
	SetEnemyCharisma(ECHA);
	SetEnemyAttack(EATT);
	SetEnemyMagicAttack(EMAGATT);
	SetEnemyDefence(EDEF);
	SetEnemyMagicDefence(EMAGDEF);
	SetEnemyEvasion(E_EVA);
	SetEnemyGoldReward(GOLDREWARD);
	SetEnemyExperienceReward(ENEMY_EXPERIENCEREWARD);
}

void Enemies::SetEnemyName (string enemyname)
{
	EnemyName = enemyname;
}

void Enemies::SetEnemyLevel(int enemylevel)
{
	EnemyLevel = enemylevel;
}

void Enemies::SetEnemyMaxHealth(int enemymaxhp)
{
	EnemyMax_HP = ((EnemyConstitution * (enemymaxhp * EnemyLevel)) / 10);
}

void Enemies::SetEnemyHealth()
{
	EnemyHitPoints = EnemyMax_HP;
}

void Enemies::SetEnemyMaxMana (int enemymaxmp)
{
	EnemyMax_MP = (EnemyWisdom * (enemymaxmp * EnemyLevel) / 50);
}

void Enemies::SetEnemyMana()
{
	EnemyManaPoints = EnemyMax_MP;
}

void Enemies::SetEnemyStrength(int enemystrength)
{
	EnemyStrength = enemystrength;
}

void Enemies::SetEnemyIntelligence(int enemyintelligence)
{
	EnemyIntelligence = enemyintelligence;
}

void Enemies::SetEnemyConstitution(int enemyconstitution)
{
	EnemyConstitution = enemyconstitution;
}

void Enemies::SetEnemyDexterity(int enemydexterity)
{
	EnemyDexterity = enemydexterity;
}

void Enemies::SetEnemyWisdom(int enemywisdom)
{
	EnemyWisdom = enemywisdom;
}

void Enemies::SetEnemyCharisma(int enemycharisma)
{
	EnemyCharisma = enemycharisma;
}

void Enemies::SetEnemyAttack(int enemyattack)
{
	EnemyAttack = ((((EnemyDexterity + EnemyLevel + enemyattack)^3 / 32) + 32) / 16);
}

void Enemies::SetEnemyMagicAttack(int enemymagicattack)
{
	EnemyMagicAttack = ((((EnemyWisdom + EnemyLevel + enemymagicattack)^3 / 32) + 32) / 16);
}

void Enemies::SetEnemyDefence(int enemydefence)
{
	if (EnemyDexterity > EnemyStrength)
	{
		EnemyDefence = ((((EnemyDexterity + EnemyLevel + enemydefence)^3 / 32) + 32) / 16);
	}
	else
	{
		EnemyDefence = ((((EnemyStrength + EnemyLevel + enemydefence)^3 / 32) + 32) / 16);
	}
}

void Enemies::SetEnemyMagicDefence(int enemymagicdefence)
{
	EnemyMagicDefence = ((((EnemyCharisma + EnemyLevel + enemymagicdefence)^3 / 32) + 32) / 16);
}

void Enemies::SetEnemyEvasion(int enemyevasion)
{
	EnemyEvasion = (EnemyDexterity * (enemyevasion * EnemyLevel) / 98);
};

void Enemies::SetEnemyDamage(int enemydamage)
{
	EnemyDamage = (EnemyAttack + ((EnemyStrength / 2) + enemydamage));
}

void Enemies::SetEnemyMagicDamage(int enemymagicdamage)
{
	EnemyMagicDamage = (EnemyMagicAttack + ((EnemyIntelligence / 2) + enemymagicdamage));
}

void Enemies::SetEnemyGoldReward(int enemygoldreward)
{
	EnemyGoldReward = enemygoldreward;
}

void Enemies::SetEnemyExperienceReward(int enemy_experiencereward)
{
	EnemyExperienceReward = enemy_experiencereward;
}


This post has been edited by Skydiver: 04 August 2014 - 05:22 AM
Reason for edit:: Fixed botched code tags.

Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3576
  • View blog
  • Posts: 11,126
  • Joined: 05-May 12

Re: Not Understanding What Is Happening

Posted 04 August 2014 - 05:25 AM

Notice that your SetEnemyMaxHealth() is using other uninitialized variables.

I highly recommend learning how to use a debugger. If you set a breakpoint on the function, and step through it, you'll see this problem more visually.
Was This Post Helpful? 1
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6064
  • View blog
  • Posts: 23,520
  • Joined: 23-August 08

Re: Not Understanding What Is Happening

Posted 04 August 2014 - 05:36 AM

Other suggestion:

Your classes are misnamed. Characters and Weapons each represent a *single* Character or Weapon and would therefore be better named as Character and Weapon
Was This Post Helpful? 0
  • +
  • -

#8 Rithian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 22-January 14

Re: Not Understanding What Is Happening

Posted 04 August 2014 - 07:39 AM

Well I feel stupid right now LOL. The problem was so simple that I didn't see it. All I need to do was to move the Hp variables down below the charisma variable. Thanks Skydiver for posting that my formula was using uninitialized variables. It reminded me about c++'s order of operations which I had forgotten about.
Was This Post Helpful? 0
  • +
  • -

#9 jimblumberg  Icon User is offline

  • member icon


Reputation: 4075
  • View blog
  • Posts: 12,578
  • Joined: 25-December 09

Re: Not Understanding What Is Happening

Posted 04 August 2014 - 10:28 AM

I also don't recommend using the using declaration in the global scope of a header file. And making a header file whose only purpose is to include other header files is a very bad practice. Always include the required include files in the file/s that require those includes.

Jim
Was This Post Helpful? 0
  • +
  • -

#10 Rithian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 22-January 14

Re: Not Understanding What Is Happening

Posted 04 August 2014 - 06:43 PM

View Postjimblumberg, on 04 August 2014 - 10:28 AM, said:

I also don't recommend using the using declaration in the global scope of a header file. And making a header file whose only purpose is to include other header files is a very bad practice. Always include the required include files in the file/s that require those includes.

Jim


Well Jim, I have to agree with you, but as this is a test program for a game I'm hoping to make, I was lazy (i know not a good thing and very bad habit to start while coding) and went with this shorthand. When I actually start on the full game code (which hopefully will get upgraded from a text based game to one with sound and graphics) it will not have this lazy handicap.
Was This Post Helpful? 0
  • +
  • -

#11 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3576
  • View blog
  • Posts: 11,126
  • Joined: 05-May 12

Re: Not Understanding What Is Happening

Posted 04 August 2014 - 09:47 PM

Be aware that the ^ operator is the bitwise XOR operator. It is not the exponent operator like used in other languages.
Was This Post Helpful? 0
  • +
  • -

#12 jimblumberg  Icon User is offline

  • member icon


Reputation: 4075
  • View blog
  • Posts: 12,578
  • Joined: 25-December 09

Re: Not Understanding What Is Happening

Posted 04 August 2014 - 09:54 PM

Quote

but as this is a test program for a game I'm hoping to make,

So what, bad design is bad design. If you're too lazy to properly design your program in small test cases I doubt very much that you'll take the time to do things right when you start your "actual program". Using good programming habits in all your programs, even small test programs, is habit forming. Likewise using bad habits is also habit forming. So quit being "lazy" and do things right the first time.

Jim
Was This Post Helpful? 0
  • +
  • -

#13 accedeholdings  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 04-August 14

Re: Not Understanding What Is Happening

Posted 04 August 2014 - 09:55 PM

Is there any way to shorten this code? Thanks for the inputs.
Was This Post Helpful? 0
  • +
  • -

#14 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1347
  • View blog
  • Posts: 4,642
  • Joined: 19-February 09

Re: Not Understanding What Is Happening

Posted 05 August 2014 - 01:50 PM

View Postaccedeholdings, on 05 August 2014 - 04:55 AM, said:

Is there any way to shorten this code? Thanks for the inputs.


Hi, yes, the Character and the Enemy share many attributes, so an inherited class of shared attributes would be possible.

Also, if the attributes had a class then the setters and getters would not need to be defined for each attribute.

class Character_Attribute 
{
  private:
    int attribute_value;

  public:
    int  get() const;
    void set(int value);
};

// use in class
Character_Attribute strength;

strength.set(15);


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1