#include "stdafx.h"
#include <iostream>
#include <string>
usingnamespace std;
class Goblin
{
public:
Goblin(unsignedshort StartHealth, unsignedshort StartStrength, unsignedshort Attack, unsignedshort Magic);
void BeAttacked();
void Attack();
void Magic();
int GetHealth();
void IncreaseHealth();
void DecreaseHealth(unsignedshort damage);
void NewGame();
void Rules();
void Quit();
private:
int health;
int strength;
int magic;
int attack;
};
int main()
{
Goblin John(12,10,10,10);
int menuchoice;
cout << "Main Menu\n";
cout << "1. New Game\n";
cout << "2. Rules\n";
cout << "3. Quit\n";
cin >> menuchoice;
switch (menuchoice)
{
case 1:
John.NewGame();
break;
case 2:
John.Rules();
break;
case 3:
John.Quit();
break;
}
int attack;
cout << "Attack using magic or strength?:";
cin >> attack;
switch (attack)
{
case 1:
John.Magic();
break;
case 2:
John.Attack();
break;
}
}
Goblin::Goblin(unsignedshort StartHealth,unsignedshort StartStrength,unsignedshort Attack, unsignedshort Magic):
health(StartHealth),
strength(StartStrength)
{
}
void Goblin::Attack()
{
cout << "I'm attacking with " << strength << " strength and " << attack << "attack!\n";
}
void Goblin::BeAttacked()
{
cout << "Aaaarggghh\n";
DecreaseHealth(2);
}
void Goblin::DecreaseHealth(unsignedshort Damage)
{
health = health - Damage;
cout << "You took " << Damage << "damage!\n";
}
int Goblin::GetHealth()
{
return health;
}
void Goblin::Magic()
{
cout << "You attacked using " << magic << "magic!\n";
}
void Goblin::NewGame()
{
string character;
cout << "New game!\n";
cin >> character;
string * name = &character;
}
void Goblin::Quit()
{
cout << "You quit\n";
}
void Goblin::Rules()
{
cout << "Rules\n";
}
No compiler or runtime errors, however when I run and go to the function NewGame, it does not cout, and only takes the cin.
When I try to attack using magic it gives me a negative integer such as -8456864 for magic level...Same thing for attack level if I attack using strength.