adding cs142 code
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user