GameManager.cpp
Code:
#include "ShopClass.h"
#include "BattleClass.h"
#include "GameManager.h"
#include <iostream>
#include <cctype>
using namespace std;
void GameManager::Manager()
{
int money = 200;
int lives = 3;
int attack = 0;
int defense = 0;
ShopClass shop;
BattleClass battle;
cout << "Current Status:\n";
cout << "Money: $" << money << "\n";
cout << "Lives: " << lives << "\n";
cout << "Attack Points: " << attack << "\n";
cout << "Defense Points: " << defense << "\n";
cout << "Would you like to visit the shop or battle robots?\n(Please enter either Shop or Battle)\n";
cin >> ShopBattle;
if (ShopBattle == "Shop" || ShopBattle == "shop") {
shop.Shop();
} else if (ShopBattle == "Battle" || ShopBattle == "battle") {
battle.Battle();
} else {
cout << "Error: Invalid Input";
}
}
int GameManager::GetMoney()
{
return money;
}
int GameManager::GetAttack()
{
return attack;
}
int GameManager::GetDefense()
{
return defense;
}
int GameManager::GetLives()
{
return lives;
}
void GameManager::AddMoney(int amount)
{
money =+ amount;
if (money < 0)
money = 0;
}
void GameManager::Lives()
{
GameManager manager;
lives =- 1;
if (lives == 0)
cout << "Game Over\n";
cout << "Would you like to start again? (y or n)";
cin >> restart;
if (tolower(restart) == 'y') {
money = 200;
lives = 3;
attack = 0;
defense = 0;
manager.Manager();
} else if (tolower(restart) == 'n') {
} else {
cout << "Error: Invalid Input\n";
manager.Lives();
}
}
void GameManager::AddAttack(int amount)
{
attack =+ amount;
}
void GameManager::AddDefense(int amount)
{
defense =+ amount;
}
..and an example of code that needs to use some of the variables
Code:
if (manager.GetAttack() >= 1){
cout << "Attack Successful\nYou Won $200\n\n";
manager.AddMoney(200);
} else {
cout << "You Lost\n\n";
manager.Lives();
}