-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cpp
81 lines (65 loc) · 2.11 KB
/
Player.cpp
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
#include <iostream>
#include <string>
#include <vector>
#include "Player.h"
using namespace std;
Player::Player(string name) : Unit(name, INIT_PLAYER_HEALTH, 0, 0, 0, DeathEffects(0, 0, 0, 0, 0)){
_bad_decisions = 0;
_rock = 1;
_paper = 1;
_scissors = 1;
}
bool Player::is_monster() {
return false;
}
bool Player::is_player() {
return true;
}
void Player::attack(Unit* other) {
switch(stance_result(get_stance(), other->get_stance())){
case 1: // our stance wins!
other->set_health(other->get_health() - stance_stat(get_stance()));
break;
case 0: // it was a tie
other->set_health(other->get_health() - 1);
break;
case -1:// our stance lost :(
// deal no damage
break;
}
}
void Player::activate_death_effects(DeathEffects effects) {
add_speed(effects.speed);
set_health(get_health() + effects.health);
_rock += effects.rock;
_paper += effects.paper;
_scissors += effects.scissors;
}
void Player::do_decision(Decision dec) {
if (dec.dest == INVALID_DESTINATION || dec.stance == INVALID_STANCE) {
_bad_decisions ++;
if (_bad_decisions > BAD_DECISIONS_ALLOWED) {
set_health(0);
die();
}
}
change_destination(dec.dest);
set_stance(dec.stance);
}
string Player::get_string() {
return "Name: " + get_name() + ", health = " + to_string(get_health()) + ", speed = " + to_string(get_speed()) + ", rock = " + to_string(_rock) + ", paper = " + to_string(_paper) + ", scissors = " + to_string(_scissors) + ", stance = " + get_stance_str(get_stance()) + ", destination = " + to_string(get_destination()) + ", movement_counter = " + to_string(get_movement_counter());
}
json Player::to_json() {
json j = Unit::to_json();
j["Type"] = "Player";
j["Rock"] = _rock;
j["Paper"] = _paper;
j["Scissors"] = _scissors;
return j;
}
int Player::stance_stat(int stance_id){
if (stance_id == STANCE_ROCK) return _rock;
else if (stance_id == STANCE_PAPER) return _paper;
else if (stance_id == STANCE_SCISSORS) return _scissors;
else return 0;
}