school/cs142/smcquay/cootie/player.cc

68 lines
1.6 KiB
C++
Raw Normal View History

2016-04-06 20:45:34 -07:00
#include "dice.h"
#include "player.h"
#include <iostream>
using namespace std;
player::player(int id) : id(id), head(false), body(false),
hat(false), eyes(false), mouth(false), legs(0) {}
ostream & operator<<(ostream & os, const player & e) {
os << "{id: " << e.id
<< ", body: " << e.body
<< ", head: " << e.head
<< ", hat: " << e.hat
<< ", eyes: " << e.eyes
<< ", mouth: " << e.mouth
<< ", legs: " << e.legs
<< "}";
return os;
}
void player::turn() {
bool turn_finished = false;
while(not turn_finished) {
int cur_roll = roll();
turn_finished = true;
if(cur_roll == 1) {
if(not body) {
turn_finished = false;
body = true;
}
}
else if(body and cur_roll == 2) {
if(not head) {
turn_finished = false;
head = true;
}
}
else if(body and head) {
if (cur_roll == 3) {
turn_finished = false;
hat = true;
}
else if (cur_roll == 4) {
turn_finished = false;
eyes = true;
}
else if (cur_roll == 5) {
turn_finished = false;
mouth = true;
}
else if (cur_roll == 6) {
if (not (legs >= 6)) {
turn_finished = false;
legs++;
}
}
}
}
}
bool player::won() {
if(head and body and hat and eyes and mouth and legs == 6)
return true;
else
return false;
}