1
1

olok.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "olok.h"
  2. Olok::Olok()
  3. {
  4. clear();
  5. }
  6. void Olok::clear()
  7. {
  8. // clear the grid to be rebuilt as empty
  9. grid.clear();
  10. // make 11 boxes for each colored row (not the white ones)
  11. for(int j = 0; j<white1; j++)
  12. {
  13. RowColor empty;
  14. grid.push_back(empty);
  15. for (int i = 0; i<CHECKBOXES; i++)
  16. {
  17. grid[j].row.push_back(false);
  18. }
  19. }
  20. // clear penalty count
  21. penaltyCount = 0;
  22. }
  23. // get checked off box count for a specific color
  24. int Olok::getXCount(int color)
  25. {
  26. return grid[color].xCount;
  27. }
  28. // add checked off box to a specific index on a color
  29. void Olok::addX(int color, int index)
  30. {
  31. grid[color].row[index] = true;
  32. grid[color].lastIndex = index;
  33. }
  34. // check for last value of index
  35. int Olok::getLastIndex(int color)
  36. {
  37. return grid[color].lastIndex;
  38. }
  39. // add any Xs from input Olok into this Olok
  40. void Olok::addOlok(Olok o)
  41. {
  42. // find changes in currentTurnOlok and transfer to cumulativeOlok
  43. for(int j = 0;j <o.grid.size();j++)
  44. {
  45. // loop over all Xs in a color
  46. for(int k = 0;k <o.grid[j].row.size();k++)
  47. {
  48. // check for true values in currentTurnOlok's grid
  49. if(true ==o.grid[j].row[k])
  50. {
  51. // transfer true values from currentTurnOlok's grid to cumulativeOlok's grid
  52. grid[j].row[k] = true;
  53. }
  54. }
  55. }
  56. // player selects to add penalty, increase the penalty count
  57. penaltyCount += o.penaltyCount;
  58. }
  59. std::string Olok::toString(void) {
  60. std::string output;
  61. // check each row on the grid on the scoresheet
  62. for(int j = 0; j < grid.size(); j++)
  63. {
  64. // check each box on the row and then store output
  65. for(int k = 0; k < grid[j].row.size();k++)
  66. {
  67. // look at checkbox value, add it to output
  68. output.push_back(grid[j].row[k] ? 'T' : 'F');
  69. }
  70. }
  71. // add penalty count to output
  72. output.push_back(penaltyCount + '0');
  73. return output;
  74. }