123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- #include "game.h"
- Game::Game() {
-
- for(int i = 0; i<white1;i++){
- lockOut.push_back(false);
- }
-
- state = NOT_STARTED;
-
- };
- bool Game::addPlayer(std::string name){
- if(NOT_STARTED == state){
- PlayerCard newplayer(name);
- players.push_back(newplayer);
- fprintf (stdout, "added: %s to the game\n", name.c_str());
- return true;
- }
- else{
- fprintf(stdout, "player %s was not added to the game\n", name.c_str());
- return false;
- }
- };
- void Game::score(){
-
- std::vector<int> pointsGuide = {0,1,3,6,10,15,21,28,36,45,55,66,78};
-
- for(int i = 0;i <players.size();i++){
-
- players[i].score = 0;
-
- players[i].score -= players[i].penaltyCount*PENALTY_VALUE;
-
- for(int j = 0;j <white1;j++){
- int count = 0;
-
- for(int k =0;k <CHECKBOXES;k++){
- if(true == players[i].rowColors[j][k]){
- count++;
- }
- }
- players[i].score += pointsGuide[count];
- }
- }
-
-
- for(int i = 0;i<players.size();i++){
-
- if(players[i].penaltyCount == MAX_PENALTY){state = FINISHED;}
- }
-
- int lockCount = 0;
- for(int i = 0;i<lockOut.size();i++){
- if(true == lockOut[i]){lockCount++;}
- }
- if(MAX_LOCKOUT <= lockCount){
- state = FINISHED;
- }
- }
- void Game::turn(PlayerCard activePlayer) {
-
- for(int i = 0; i <players.size();i++){
- players[i].isTurnDone = false;
- }
-
- dice.roll();
-
- while(true){
- bool temp = true;
- for(int i = 0; i <players.size();i++){
- temp = temp && players[i].isTurnDone;
- }
- if(temp){break;}
- Sleep(1);
- }
-
- score();
- }
- std::string Game::send()
- {
- std::string output;
-
-
- for(int i = 0; i < players.size(); i++)
- {
-
- for(int j = 0; j < white1; j++)
- {
-
- for(int k = 0; k < CHECKBOXES;k++)
- {
-
- output.push_back(players[i].rowColors[j][k] ? 'T' : 'F');
- }
- }
- }
- fprintf(stdout, "the output is: %s\n", output.c_str());
- return output;
- }
- void Game::receive(std::string userInput){
-
-
- }
|