|
@@ -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();
|
|
|
|
|
|
- bool addPlayer(std::string name);
|
|
|
+ bool addPlayer(std::string name);
|
|
|
};
|
|
|
Game::Game() {
|
|
|
-
|
|
|
- state = NOT_STARTED;
|
|
|
+
|
|
|
+ for(int i = 0; i<white1;i++){
|
|
|
+ lockOut.push_back(false);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
};
|
|
|
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(){
|
|
|
+
|
|
|
+ std::vector<int> pointsGuide = {0,1,3,6,10,15,21,28,36,45,55,66,78};
|
|
|
+
|
|
|
+ for(int i = 0;i <players.size();i++){
|
|
|
+
|
|
|
+ players[i].score = 0;
|
|
|
+
|
|
|
+ players[i].score -= players[i].penaltyCount*PENALTY_VALUE;
|
|
|
+
|
|
|
+ for(int j = 0;j <white1;j++){
|
|
|
+ int count = 0;
|
|
|
+
|
|
|
+ for(int k =0;k <CHECKBOXES;k++){
|
|
|
+ if(true == players[i].rowColors[j][k]){
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ players[i].score += pointsGuide[count];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for(int i = 0;i<players.size();i++){
|
|
|
+
|
|
|
+ if(players[i].penaltyCount == MAX_PENALTY){state = FINISHED;}
|
|
|
+ }
|
|
|
+
|
|
|
+ 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) {
|
|
|
+
|
|
|
+ for(int i = 0; i <players.size();i++){
|
|
|
+ players[i].isTurnDone = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ dice.roll();
|
|
|
+
|
|
|
+ while(true){
|
|
|
+ bool temp = true;
|
|
|
+ for(int i = 0; i <players.size();i++){
|
|
|
+ temp = temp && players[i].isTurnDone;
|
|
|
+ }
|
|
|
+ if(temp){break;}
|
|
|
+ Sleep(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ score();
|
|
|
+}
|