|
@@ -1,23 +1,28 @@
|
|
|
#include "game.h"
|
|
|
-Game::Game() {
|
|
|
+Game::Game()
|
|
|
+{
|
|
|
// initialize the number of columns that each "color" will contain
|
|
|
lastColumnIndex = CHECKBOXES - 1;
|
|
|
// set up lockOut
|
|
|
- for(int i = 0; i<white1;i++){
|
|
|
+ for(int i = 0; i<white1;i++)
|
|
|
+ {
|
|
|
lockOut.push_back(false);
|
|
|
}
|
|
|
// set the state of game [how to move from state to state ("game logic?")]
|
|
|
state = NOT_STARTED;
|
|
|
// dice have been initialized with random seed
|
|
|
};
|
|
|
-bool Game::addPlayer(std::string name){
|
|
|
- if(NOT_STARTED == state){
|
|
|
+bool Game::addPlayer(std::string name)
|
|
|
+{
|
|
|
+ if(NOT_STARTED == state)
|
|
|
+ {
|
|
|
ScoreSheet newplayer(name);
|
|
|
players.push_back(newplayer);
|
|
|
fprintf (stdout, "added: %s to the game\n", name.c_str());
|
|
|
return true;
|
|
|
}
|
|
|
- else{
|
|
|
+ else
|
|
|
+ {
|
|
|
fprintf(stdout, "player %s was not added to the game\n", name.c_str());
|
|
|
return false;
|
|
|
}
|
|
@@ -87,6 +92,9 @@ void Game::turn(ScoreSheet activePlayer)
|
|
|
}
|
|
|
// score the cards
|
|
|
score();
|
|
|
+ // go to next player's turn
|
|
|
+ activePlayer++;
|
|
|
+ activePlayer %= players.size();
|
|
|
}
|
|
|
|
|
|
// generate text: per player(48boxes, penalty count), locked off rows, dice roll, game end(when it occurs) send it
|
|
@@ -125,6 +133,14 @@ void Game::receive(std::string userInput)
|
|
|
players[0].currentTurnOlok.clear();
|
|
|
// penalties are marked to card if user string = 1
|
|
|
// did the user send a number?
|
|
|
+ // ## Range Check to go into Receive ##
|
|
|
+ #ifdef WORKING_ON_RANGE_CHECK
|
|
|
+ // if index is too high or too low, throw an error
|
|
|
+ if(CHECKBOXES > index || 0 < index){fprintf(stdout,"Player[%d] %s index is too high or too low X\n", player, players[player].savedName);}
|
|
|
+ // if color is not valid throw an error
|
|
|
+ players[0].cumulativeOlok.isColor(red);
|
|
|
+ if(color){fprintf(stdout,"Player[%d] %s invalid color selected X\n", player, players[player].savedName);}
|
|
|
+ #endif
|
|
|
// if a user did not send a number no changes take place
|
|
|
// take the userinput (string) and parse it into parts
|
|
|
// what is the length of the userInput? length of 2, 4? (boxes 0-9 are represented as 00,01,02...)
|
|
@@ -132,19 +148,52 @@ void Game::receive(std::string userInput)
|
|
|
// convert userInput into number
|
|
|
// user number to change the boolean on corresponding spot on ScoreSheet
|
|
|
}
|
|
|
+
|
|
|
+/* add a checkbox to a specified players scoresheet user specifies player's: XXXX, the color, and index of the checkbox on the colored row
|
|
|
+ * dont know what XXXX is yet - but it will be used to find correct player
|
|
|
+ *
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * the white die and color combo must match the corresponding RowColor and index
|
|
|
+ *
|
|
|
+ */
|
|
|
+
|
|
|
+/*
|
|
|
+ * all players can do white die combination, active player can do a colored + white die combination.
|
|
|
+ *
|
|
|
+ * ## Things we need to know ##
|
|
|
+ * sum of both white die
|
|
|
+ * 8 sums of each of the white die and all of the colored die
|
|
|
+ * who is the active player for this turn
|
|
|
+ *
|
|
|
+ * ## How to do ##
|
|
|
+ * on a given turn, sum the white die and sum each of the white die and all of the colored die
|
|
|
+ * check to see if each players' requested move is valid
|
|
|
+ * does the player's requested move match the sum of the white die "satisfies all players can do white die combination"
|
|
|
+ * if the active player, check both white die and the color die they requested for move
|
|
|
+ * TODO: deal with subtley of active player not being able to re-use dice
|
|
|
+ * record if active player took at least a white dice move, a colored die move, or both
|
|
|
+ * if it is valid, add it to player card
|
|
|
+ * if it is not valid, return an error to player
|
|
|
+ */
|
|
|
void Game::addX(int player, int color, int index)
|
|
|
{
|
|
|
- // TODO: check that index and color match rolled die
|
|
|
+ /* TODO: check that index and color match rolled die
|
|
|
+ * ## Rule Check ##
|
|
|
+ * if index is not the sum of two dice throw an error
|
|
|
+ * if index is a sum AND color is correct allow it
|
|
|
+ */
|
|
|
+
|
|
|
// player can add an x to olok in last column if there are 5 x
|
|
|
if(lastColumnIndex == index)
|
|
|
{
|
|
|
- if(5 >= players[player].cumulativeOlok.getXCount(color))
|
|
|
+ if(LOCKOUT_QUALIFIER >= players[player].cumulativeOlok.getXCount(color))
|
|
|
{
|
|
|
players[player].currentTurnOlok.addX(color, index);
|
|
|
}
|
|
|
else{fprintf(stdout, "Player[%d] %s tried to check off column 12 without minimum X\n", player, players[player].savedName);}
|
|
|
}
|
|
|
- // player can add an x to olok from left to right
|
|
|
+ // player must add an x to olok from left to right
|
|
|
if(players[player].cumulativeOlok.getLastIndex(color) > index)
|
|
|
{
|
|
|
fprintf(stdout,"Player[%d] %s not following left to right rule X\n", player, players[player].savedName);
|