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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
#include "stdafx.h"
#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
class Weapon
{
friend class Player;
string m_name;
int m_damage;
public:
Weapon(string, int);
string GetName() { return m_name; };
int GetDamage() { return m_damage; };
void SetName(string name) { m_name = name; };
void SetDamage(int damage) { m_damage = damage; };
};
Weapon::Weapon(
string name = "",
int damage = 0)
{
SetName(name);
SetDamage(damage);
}
class Player
{
string m_name;
Weapon m_weapon;
int m_strength;
public:
friend class Weapon;
Player(string, //name
Weapon, //weapon
int); //strength
string GetName() { return m_name; };
Weapon GetWeapon() { return m_weapon; };
int GetStrength() { return m_strength; };
void SetName(string name) { m_name = name; };
void SetWeapon(Weapon weapon) { m_weapon = weapon; };
void SetStrength(int strength) { m_strength = strength; };
int Attack()
{ //Better to calc and return damage here?
return 0;
}
};
Player::Player(
string name,
Weapon weapon,
int strength)
{
SetName(name);
SetWeapon(weapon);
SetStrength(strength);
}
void Battle(Player);
int main()
{
Weapon none("None", 0); //(name, damage)
Weapon sword("Sword", 10);
Weapon axe("Axe", 20);
Player playerOne("Conan", none, 2); //(name, weapon, strength)
cout << "Choose weapon\n1 Sword\n2 Axe" << endl;
int choice;
cin >> choice;
switch (choice)
{
case 1:
cout << "You take the Sword" << endl;
playerOne.SetWeapon(sword);
Battle(playerOne);
break;
case 2:
cout << "You take the Axe" << endl;
playerOne.SetWeapon(axe);
Battle(playerOne);
break;
default:
cout << "Choose 1 or 2" << endl;
break;
}
return 0;
}
void Battle(Player)
{
bool playerAlive = true;
cout << "You are fighting a skeleton\n" << endl;;
do
{
cout << "1 Attack\n2 Run\n" << endl;
int choice;
cin >> choice;
switch (choice)
{
case 1:
cout << "You attack!\n" << endl;
//function to go here
//how to access both classes and call their functions from here?
//Needs to get damage member of Weapon and player strength
//to calculate total damage, something like
//(((PlayerStrength()*10)+100)*WeaponDamage())/100;
int pause;
cin >> pause;
break;
case 2:
break;
default:
break;
}
} while (playerAlive = true);
}
|