| 
					
				 | 
			
			
				@@ -1,21 +1,28 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 #include "qwixx.h" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 #include "dice.h" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 #include "playerCard.h" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+#include <windows.h> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 class Game { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    std::vector<PlayerCard> players;  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    std::vector<PlayerCard> players; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    std::vector<bool> lockOut; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     int state;  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     Dice dice; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    void turn(PlayerCard activePlayer); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    void score(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // rules as methods of game 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    bool addPlayer(std::string name);   
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    bool addPlayer(std::string name); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 Game::Game() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // set the state of game 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    state = NOT_STARTED; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // set up lockOut 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    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?")] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // dice have been initialized with random seed 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 bool Game::addPlayer(std::string name){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (NOT_STARTED == state){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if(NOT_STARTED == state){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         PlayerCard newplayer(name); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         players.push_back(newplayer); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         fprintf (stdout, "added: %s to the game", name); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -26,4 +33,59 @@ bool Game::addPlayer(std::string name){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void Game::score(){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // **CALCULATE EACH PLAYERS' SCORE** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    std::vector<int> pointsGuide = {0,1,3,6,10,15,21,28,36,45,55,66,78}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // check players' card for marked boxes 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for(int i = 0;i <players.size();i++){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // clear each players' previous score 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        players[i].score = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // calculate penalty amount 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        players[i].score -= players[i].penaltyCount*PENALTY_VALUE; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // check each color(row) on playerCard 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for(int j = 0;j <white1;j++){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            int count = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // check each box in row 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for(int k =0;k <CHECKBOXES;k++){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if(true == players[i].rowColors[j][k]){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    count++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            players[i].score += pointsGuide[count]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // **CHECK IF GAME IS DONE** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // check each player's card for penalties 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    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;}       
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // check for lockout to see if game is over 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    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) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // start all players' turns 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for(int i = 0; i <players.size();i++){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        players[i].isTurnDone = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // roll the dice 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    dice.roll(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // check to see if all players are done with turn 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    while(true){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bool temp = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for(int i = 0; i <players.size();i++){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            temp = temp && players[i].isTurnDone; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(temp){break;} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Sleep(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // score the cards 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    score(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |