-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.cpp
More file actions
62 lines (56 loc) · 1.54 KB
/
game.cpp
File metadata and controls
62 lines (56 loc) · 1.54 KB
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
#include <iostream>
#include "game.h"
#include <string>
#include "character.h"
using namespace std;
Game::Game(){
current_turn = 0;
num_of_characters = 0;
}
void Game::RemoveCharacter(int index){
if(index < 0 || index > 1){
cout << "Invalid index!" << endl;
}
else{
if(players[index] != nullptr){
players[index] = nullptr;
if(index == 0)
swap(players[0],players[1]);
num_of_characters--;
}
}
}
void Game::AddCharacter(Character *c){
if(num_of_characters == 2)
cout << "Character limit reached, please wait for the next game!" << endl;
else{
players[num_of_characters] = c;
num_of_characters++;
}
}
void Game::NextTurn(){
if(num_of_characters < 2)
cout << "Need more players!" << endl;
else if(players[0]->getHealth() >= 0 && players[1]->getHealth() >= 0){
players[0]->Attack(players[1]);
if(players[1]->getHealth() < 0){
cout << players[0]->getName() << " wins!" << endl;
}
else{
players[1]->Attack(players[0]);
if(players[0]->getHealth() < 0)
cout << players[1]->getName() << " wins!" << endl;
}
}
else{
if(players[0]->getHealth() < 0)
cout << players[1]->getName() << " wins!" << endl;
else cout << players[0]->getName() << " wins!" << endl;
}
}
void Game::Print(){
for(int a = 0; a < num_of_characters; a++){
players[a]->Print();
cout << "---" << endl;
}
}