olok.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 tempRow;
  14. tempRow.color = j;
  15. tempRow.direction = j < (white1/2) ? RIGHT_TO_LEFT : LEFT_TO_RIGHT;
  16. // make 11 numbers for each row based on direction
  17. for (int i = 0; i<CHECKBOXES; i++)
  18. {
  19. tempRow.number.push_back(RIGHT_TO_LEFT == tempRow.direction ? (DICE_SUM_MIN+i) : (DICE_SUM_MAX+i));
  20. }
  21. grid.push_back(tempRow);
  22. for (int i = 0; i<CHECKBOXES; i++)
  23. {
  24. grid[j].row.push_back(false);
  25. }
  26. }
  27. // clear penalty count
  28. penaltyCount = 0;
  29. }
  30. // get checked off box count for a specific color
  31. int Olok::getXCount(int color)
  32. {
  33. for(int i = 0; i < grid.size(); i++)
  34. {
  35. if(color != grid[i].color){continue;}
  36. return grid[i].xCount;
  37. }
  38. return 0;
  39. }
  40. // add checked off box to a specific index on a color
  41. void Olok::addX(int color, int index)
  42. {
  43. for(int i = 0; i < grid.size(); i++)
  44. {
  45. if(color != grid[i].color){continue;}
  46. grid[i].row[index] = true;
  47. grid[i].lastIndex = index;
  48. }
  49. }
  50. // check for last value of index
  51. int Olok::getLastIndex(int color)
  52. {
  53. for(int i = 0; i < grid.size(); i++)
  54. {
  55. if(color != grid[i].color){continue;}
  56. return grid[i].lastIndex;
  57. }
  58. return CHECKBOXES;
  59. }
  60. // add any Xs from input Olok into this Olok
  61. void Olok::addOlok(Olok o)
  62. {
  63. // find changes in currentTurnOlok and transfer to cumulativeOlok
  64. for(int j = 0;j <o.grid.size();j++)
  65. {
  66. // loop over all Xs in a color
  67. for(int k = 0;k <o.grid[j].row.size();k++)
  68. {
  69. // check for true values in currentTurnOlok's grid
  70. if(true ==o.grid[j].row[k])
  71. {
  72. // transfer true values from currentTurnOlok's grid to cumulativeOlok's grid
  73. grid[j].row[k] = true;
  74. }
  75. }
  76. }
  77. // player selects to add penalty, increase the penalty count
  78. penaltyCount += o.penaltyCount;
  79. }
  80. std::string Olok::toString(void)
  81. {
  82. std::string output;
  83. // check each row on the grid on the scoresheet
  84. for(int j = 0; j < grid.size(); j++)
  85. {
  86. // check each box on the row and then store output
  87. for(int k = 0; k < grid[j].row.size();k++)
  88. {
  89. // look at checkbox value, add it to output
  90. output.push_back(grid[j].row[k] ? 'T' : 'F');
  91. }
  92. }
  93. // add penalty count to output
  94. output.push_back(penaltyCount + '0');
  95. return output;
  96. }
  97. // check to see if color matches one of the RowColor(s) on grid
  98. boolean Olok::isColor(int color)
  99. {
  100. for(int i = 0; i < grid.size(); i++)
  101. {
  102. if(color != grid[i].color){continue;}
  103. return true;
  104. }
  105. return false;
  106. }