Преглед на файлове

defined common colors and states of play in qwixx.h
this allowed dice.cpp to be cleaner in code and it is now easier to add other colors down the road.
game.cpp has some rules, states, pieces and players.
playercard also benefits from the defined colors from qwixx.h (cleaner code)

wes преди 4 години
родител
ревизия
533fe0bf7e
променени са 9 файла, в които са добавени 95 реда и са изтрити 57 реда
  1. 14 49
      Qwixx/dice.cpp
  2. 11 0
      Qwixx/dice.h
  3. 29 0
      Qwixx/game.cpp
  4. 0 1
      Qwixx/main.cpp
  5. 13 0
      Qwixx/playerCard.cpp
  6. 10 0
      Qwixx/playerCard.h
  7. 6 0
      Qwixx/qwixx.h
  8. 5 0
      Qwixx/rollDice/qwixx.h
  9. 7 7
      Qwixx/toDo.md

+ 14 - 49
Qwixx/dice.cpp

@@ -1,56 +1,21 @@
-#include <string>
-#include <vector>
-class Dice {
-    public:
-        int white1, white2, red, yellow, green, blue;
-        int roll();
-        void print();
-};
+#include "dice.h"
+Dice::Dice(){
+    srand(time(NULL));
+}
 int Dice::roll() {
     std::vector<int> output;
     // generate 6 random numbers to assign to each die
-    for (int i = 0; i<6; i++) {
+    for (int i = 0; i<colors; i++) {
         // store numbers generated from rand into output
-        output.push_back((rand() % 6) + 1);
-    }
-    white1 = output[0];
-    white2 = output[1];
-    red = output[2];
-    yellow = output[3];
-    green = output[4];
-    blue = output[5];    
+        dice.push_back((rand() % 6) + 1);
+    }    
     return 15;
 }
 void Dice::print() {
-    fprintf (stdout, "White1 Dice: %d\n", white1);
-    fprintf (stdout, "White2 Dice: %d\n", white2);
-    fprintf (stdout, "Yellow Dice: %d\n", yellow);
-    fprintf (stdout, "Red Dice: %d\n", red);
-    fprintf (stdout, "Blue Dice: %d\n", blue);
-    fprintf (stdout, "Green Dice: %d\n", green);
-}
-/* Dice humphe;
-humphe = new Dice();
-humphe.rollDice();
-
-fprintf(stdout, "the red die %d\n", humphe.red);
-
-
-struct SDie {
-    int number;
-    std::string color;
-};
-
-class CDie {
-    int number; std::string color;
-    int roll();
-};
-
-
-SDie greebDie = {1, "brellow"};
-
-CDie yellowDie;
-yellowDie = newC Die();
-yellowDie.number = 1;
-yellowDie.color = "preple";
-yellowDie.roll(); */
+    fprintf (stdout, "White1 Dice: %d\n", dice[white1]);
+    fprintf (stdout, "White2 Dice: %d\n", dice[white2]);
+    fprintf (stdout, "Yellow Dice: %d\n", dice[yellow]);
+    fprintf (stdout, "Red Dice: %d\n", dice[red]);
+    fprintf (stdout, "Blue Dice: %d\n", dice[blue]);
+    fprintf (stdout, "Green Dice: %d\n", dice[green]);
+}

+ 11 - 0
Qwixx/dice.h

@@ -0,0 +1,11 @@
+#include <vector>
+#include <iostream>
+#include <time.h>
+#include "qwixx.h"
+class Dice {
+    public:
+        std::vector<int> dice;
+        Dice();
+        int roll();
+        void print();
+};

+ 29 - 0
Qwixx/game.cpp

@@ -0,0 +1,29 @@
+#include "qwixx.h"
+#include "dice.h"
+#include "playerCard.h"
+class Game {
+    public:
+    std::vector<PlayerCard> players; 
+    int state; 
+    Dice dice;
+    // rules as methods of game
+    bool addPlayer(std::string name);  
+};
+Game::Game() {
+    // set the state of game
+    state = NOT_STARTED;
+    // dice have been initialized with random seed
+};
+bool Game::addPlayer(std::string name){
+    if (NOT_STARTED == state){
+        PlayerCard newplayer(name);
+        players.push_back(newplayer);
+        fprintf (stdout, "added: %s to the game", name);
+        return true;
+    }
+    else{
+        fprintf(stdout, "player %s was not added to the game", name);
+        return false;
+    }
+
+};

+ 0 - 1
Qwixx/main.cpp

@@ -6,7 +6,6 @@
 std::vector<int> rollDice();
 int main (){
     fprintf (stdout,"Qwixx initiated!\n");
-    srand(time(NULL));
     Dice dice;
     dice.roll();
     dice.print();

+ 13 - 0
Qwixx/playerCard.cpp

@@ -0,0 +1,13 @@
+#include "playerCard.h"
+PlayerCard::PlayerCard(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;
+        rows.push_back(empty);  
+        for (int i = 0; i<CHECKBOXES; i++){
+            rows[j].push_back(false);
+        }
+    }
+    savedName = name;
+    penaltyCount = 0;
+}

+ 10 - 0
Qwixx/playerCard.h

@@ -0,0 +1,10 @@
+#include <vector>
+#include "qwixx.h"
+#include <string>
+class PlayerCard {
+    public: 
+    std::vector<std::vector<bool>> rows;
+    int penaltyCount;
+    PlayerCard(std::string);
+    std::string savedName;
+};

+ 6 - 0
Qwixx/qwixx.h

@@ -0,0 +1,6 @@
+#ifndef QWIXX
+    #define QWIXX
+    #define CHECKBOXES 12
+    enum{NOT_STARTED, STARTED, FINISHED, PLAYING};
+    enum {red, yellow, green, blue, white1, white2, colors};
+#endif

+ 5 - 0
Qwixx/rollDice/qwixx.h

@@ -0,0 +1,5 @@
+#ifndef QWIXX
+    #define QWIXX
+    #define CHECKBOXES 12
+    enum {red, yellow, green, blue, white1, white2, colors}
+#endif

+ 7 - 7
Qwixx/toDo.md

@@ -1,14 +1,14 @@
 # Start making the player card
 ## the game is set up
-- each player gets a card 
- - called playerCard for player to mark their points
- - has 4 different colored rows 
- - rows are numbered 2-12 with boxes for scoring
-- there are six six-sided dice
- - two white die, a blue, a red, a yellow and green die.
+- each player gets a card
+ - ~~called playerCard for player to mark their points~~
+ - has 4 different colored rows (direction rule, add lockout, label boxes, rules for boxes)
+ - ~~rows are numbered 2-12 with boxes for scoring~~
+- ~~there are six six-sided dice~~
+ - ~~two white die, a blue, a red, a yellow and green die.~~
 
 ## players take turns
-1.  ~~roll the dice~~ (completed 20JUL28)
+1.  ~~roll the dice~~ (completed 20JUL28) **add a true random number for when dice is initialized**
 1.  all players may add points to their card
  - sum both white dice and optionally add points to any color on card
 1.  the player whose turn it is sums one white and one colored dice and may add points to that color on card