Browse Source

added olok in place of (junk code that was not figured out previously) to transfer player's input for turn for the end of turn.

wes 4 years ago
parent
commit
7ee6176e05
7 changed files with 69 additions and 67 deletions
  1. 0 26
      Qwixx/ScoreSheet.cpp
  2. 5 5
      Qwixx/ScoreSheet.h
  3. 25 34
      Qwixx/game.cpp
  4. 22 0
      Qwixx/olok.cpp
  5. 14 0
      Qwixx/olok.h
  6. 2 1
      Qwixx/qwixx.h
  7. 1 1
      Qwixx/toDo.md

+ 0 - 26
Qwixx/ScoreSheet.cpp

@@ -1,31 +1,5 @@
 #include "ScoreSheet.h"
 ScoreSheet::ScoreSheet(std::string name)
 {
-    // make 12 boxes for each colored row (not the white ones)
-    for(int j = 0; j<white1; j++)
-    {  
-        std::vector<bool> empty;
-        rowColors.push_back(empty);  
-        for (int i = 0; i<CHECKBOXES; i++)
-        {
-            rowColors[j].push_back(false);
-        }
-    }
-    // initialize player selection (this is player's current selected checkbox)
-    std::vector<int> t;
-    t.push_back(0);
-    selection.push_back(t);
-    t.push_back(0);
-    selection.push_back(t);
-    selection.push_back(t);
     savedName = name;
-    penaltyCount = 0;
-}
-void ScoreSheet::newSelection()
-{
-    selection[penalty][0] = 0;
-    selection[everyone][row] = -1;
-    selection[everyone][column] = -1;
-    selection[active][row] = -1;
-    selection[active][column] = -1;
 }

+ 5 - 5
Qwixx/ScoreSheet.h

@@ -3,15 +3,15 @@
     #include <vector>
     #include "qwixx.h"
     #include <string>
-    class ScoreSheet {
+    #include "olok.h"
+    class ScoreSheet
+    {
         public: 
-        std::vector<std::vector<bool>> rowColors;
-        int penaltyCount;
+        Olok cumulativeOlok;
+        Olok currentTurnOlok;
         ScoreSheet(std::string);
         std::string savedName;
         bool isTurnDone;
         int score;
-        std::vector<std::vector <int>> selection;
-        void newSelection();
     };
 #endif

+ 25 - 34
Qwixx/game.cpp

@@ -30,7 +30,7 @@ void Game::score()
         // clear each players' previous score
         players[i].score = 0;
         // calculate penalty amount
-        players[i].score -= players[i].penaltyCount*PENALTY_VALUE;
+        players[i].score -= players[i].cumulativeOlok.penaltyCount*PENALTY_VALUE;
         // check each color(row) on ScoreSheet
         for(int j = 0;j <white1;j++)
         {
@@ -38,7 +38,7 @@ void Game::score()
             // check each box in row
             for(int k =0;k <CHECKBOXES;k++)
             {
-                if(true == players[i].rowColors[j][k])
+                if(true == players[i].cumulativeOlok.grid[j][k])
                 {
                     count++;
                 }
@@ -51,7 +51,7 @@ void Game::score()
     for(int i = 0;i<players.size();i++)
     {
         // check for maximum penalty to see if game is over
-        if(players[i].penaltyCount == MAX_PENALTY){state = FINISHED;}      
+        if(players[i].cumulativeOlok.penaltyCount == MAX_PENALTY){state = FINISHED;}      
     }
     // check for lockout to see if game is over
     int lockCount = 0;
@@ -84,29 +84,24 @@ void Game::turn(ScoreSheet activePlayer)
         if(temp){break;}
         Sleep(1);
     }
-    // add selection to players' cards
+    // save data from currentTurnOlok into cumulativeOlok
     for(int i = 0; i <players.size();i++)
     {
-        int t;
-        // everyone can select a color and a check box
-        if(-1<(t = players[i].selection[everyone][row]))
+        // find changes in currentTurnOlok and transfer to cumulativeOlok
+        for(int j = 0;j < players[i].currentTurnOlok.grid.size();j++)
         {
-            int color = players[i].selection[everyone][row];
-            int checkbox = players[i].selection[everyone][column];
-            players[i].rowColors[color][checkbox] = true;
-        }
-        // active player can select a color and check box
-        if(-1<(t = players[i].selection[active][row]))
-        {
-            int color = players[i].selection[active][row];
-            int checkbox = players[i].selection[active][column];
-            players[i].rowColors[color][checkbox] = true;
+            for(int k = 0;k < players[i].currentTurnOlok.grid[j].size();k++)
+            {
+                // check for true values in currentTurnOlok's grid
+                if(true == players[i].currentTurnOlok.grid[j][k])
+                {
+                    // transfer true values from currentTurnOlok's grid to cumulativeOlok's grid
+                    players[i].cumulativeOlok.grid[j][k] = true;
+                }
+            }
         }
         // player selects to add penalty, increase the penalty count
-        if(0<(t = players[i].selection[penalty][0]))
-        {
-            players[i].penaltyCount++;
-        }
+         players[i].cumulativeOlok.penaltyCount += players[i].currentTurnOlok.penaltyCount;
     }
     // score the cards
     score();
@@ -122,21 +117,21 @@ std::string Game::send()
     {
         output.push_back(dice.dice[i] + '0');
     }
-    // look at each player card 
+    // look at each scoresheet
     for(int i = 0; i < players.size(); i++)
     {
-        // check each row on the player's card
-        for(int j = 0; j < white1; j++)
+        // check each row on the grid on the scoresheet
+        for(int j = 0; j < players[i].cumulativeOlok.grid.size(); j++)
         {
-            // check each box on the player card and then store output
-            for(int k = 0; k < CHECKBOXES;k++)
+            // check each box on the row and then store output
+            for(int k = 0; k < players[i].cumulativeOlok.grid[j].size();k++)
             {
                 // look at checkbox value, add it to output
-                output.push_back(players[i].rowColors[j][k] ? 'T' : 'F');
+                output.push_back(players[i].cumulativeOlok.grid[j][k] ? 'T' : 'F');
             }
         }
         // add penalty count to output
-        output.push_back(players[i].penaltyCount + '0');
+        output.push_back(players[i].cumulativeOlok.penaltyCount + '0');
     }
     // add locked off row to output
     for(int i = 0; i < lockOut.size();i++)
@@ -156,17 +151,13 @@ std::string Game::send()
 // "1"
 void Game::receive(std::string userInput)
 {
-    players[0].newSelection();
+    players[0].currentTurnOlok.clear();
     // penalties are marked to card if user string = 1
-    players[0].selection[penalty][0] = 1;
     // did the user send a number?
     // 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...)
-    players[0].selection[everyone][row] = green;
-    players[0].selection[everyone][column] = 5;
-    players[0].selection[active][row] = yellow;
-    players[0].selection[active][column] = 11;
+
     // convert userInput into number
     // user number to change the boolean on corresponding spot on ScoreSheet
 }

+ 22 - 0
Qwixx/olok.cpp

@@ -0,0 +1,22 @@
+#include "olok.h"
+Olok::Olok()
+{
+    clear();
+}
+void Olok::clear()
+{
+    // clear the grid to be rebuilt as empty
+    grid.clear();
+    // make 11 boxes for each colored row (not the white ones)
+    for(int j = 0; j<white1; j++)
+    {  
+        std::vector<bool> empty;
+        grid.push_back(empty);  
+        for (int i = 0; i<CHECKBOXES; i++)
+        {
+            grid[j].push_back(false);
+        }
+    }
+    // clear penalty count 
+    penaltyCount = 0;
+}

+ 14 - 0
Qwixx/olok.h

@@ -0,0 +1,14 @@
+#ifndef OLOK
+    #define OLOK
+    #include <vector>
+    #include "qwixx.h"
+    #include <string>
+    class Olok
+    {
+        public:
+        std::vector<std::vector<bool>> grid;
+        Olok();
+        void clear();
+        int penaltyCount;
+    };
+#endif

+ 2 - 1
Qwixx/qwixx.h

@@ -5,7 +5,8 @@
     enum{penalty, everyone, active, selectionSize};
     // to add a color in the future, place it before white1 below
     enum {red, yellow, green, blue, white1, white2, colors};
-    #define CHECKBOXES 12
+    // checkboxes represents the count of the sample space of the sum of rolling 2 dice
+    #define CHECKBOXES 11
     #define CHECKBOX_COUNT (CHECKBOXES*white1)
     #define PENALTY_VALUE 5
     #define MAX_PENALTY 4

+ 1 - 1
Qwixx/toDo.md

@@ -26,7 +26,7 @@
 - what is on the file that gets sent back and forth between server and players
 - what goes out to players: per player(48boxes, penalty count), locked off rows, dice roll, game end(when it occurs)
 - (20AUG04) Started working on send function, come back and finish it to denote a 4x12 grid to save checkboxes per row
-- (20AUG06) come back to `// add selection to players' cards` (kyle-plain it) to continue with `send/receive` 
+- ~~(20AUG06) come back to `// add selection to players' cards` (kyle-plain it) to continue with `send/receive`~~
     - before writing received create the rules that will affect receive function (e.g. which checkboxes are allowed to be clicked)
 - current make process involves compiling all object files from dice, game, playercard to create main.exe which has to be manually linked to these objects. update makefile to support object file code
 - what comes in from players: newest item checked off on row&column (maybe 2) or penalty