Bladeren bron

wrote prototypes for send/receive functions(did part of send) for a client/server model. fixed a few bugs in game.cpp (initialize, state, addPlayer).

wes 4 jaren geleden
bovenliggende
commit
f3034cbdcb
7 gewijzigde bestanden met toevoegingen van 100 en 52 verwijderingen
  1. 14 11
      Qwixx/dice.h
  2. 29 18
      Qwixx/game.cpp
  3. 23 0
      Qwixx/game.h
  4. 5 4
      Qwixx/main.cpp
  5. 15 12
      Qwixx/playerCard.h
  6. 4 2
      Qwixx/qwixx.h
  7. 10 5
      Qwixx/toDo.md

+ 14 - 11
Qwixx/dice.h

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

+ 29 - 18
Qwixx/game.cpp

@@ -1,38 +1,24 @@
-#include "qwixx.h"
-#include "dice.h"
-#include "playerCard.h"
-#include <windows.h>
-class Game {
-    public:
-    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);
-};
+#include "game.h"
 Game::Game() {
     // 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?")]
+    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);
+        fprintf (stdout, "added: %s to the game\n", name.c_str());
         return true;
     }
     else{
-        fprintf(stdout, "player %s was not added to the game", name);
+        fprintf(stdout, "player %s was not added to the game\n", name.c_str());
         return false;
     }
-
 };
 void Game::score(){
     // **CALCULATE EACH PLAYERS' SCORE**
@@ -89,3 +75,28 @@ void Game::turn(PlayerCard activePlayer) {
     // score the cards
     score();
 }
+std::string Game::send()
+{
+    std::string output;
+    // gernerate text: per player(48boxes, penalty count), locked off rows, dice roll, game end(when it occurs) send it
+    // look at each player card 
+    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 box on the player card and then store output
+            for(int k = 0; k < CHECKBOXES;k++)
+            {
+                // look at checkbox value, add it to output
+                output.push_back(players[i].rowColors[j][k] ? 'T' : 'F');
+            }
+        }
+    }
+    fprintf(stdout, "the output is: %s\n", output.c_str());
+    return output;
+}
+void Game::receive(std::string userInput){
+    // newest item checked off on row&column (maybe 2) or penalty
+    // once data is received, add it to the playerCard
+}

+ 23 - 0
Qwixx/game.h

@@ -0,0 +1,23 @@
+#ifndef GAME
+    #define GAME
+    #include "qwixx.h"
+    #include "dice.h"
+    #include "playerCard.h"
+    #include <windows.h>
+    class Game {
+        public:
+        std::vector<PlayerCard> players;
+        std::vector<bool> lockOut;
+        int state; 
+        Dice dice;
+        Game();
+        void turn(PlayerCard activePlayer);
+        void score();
+        std::string send();
+        void receive(std::string userInput);
+        // rules as methods of game
+        bool addPlayer(std::string name);
+        // rule for lockout to populate a locked out row so score function can check for locked rows
+        // rule for being able to lockout a row, check for last box marked off and set condition where the next box has to be higher than that previous box check
+    };
+#endif

+ 5 - 4
Qwixx/main.cpp

@@ -1,12 +1,13 @@
 #include <iostream>
 #include <stdlib.h>
-#include <time.h>
-#include <vector>
-#include "dice.cpp"
-std::vector<int> rollDice();
+#include "dice.h"
+#include "game.h"
 int main (){
     fprintf (stdout,"Qwixx initiated!\n");
     Dice dice;
     dice.roll();
     dice.print();
+    Game newgame;
+    newgame.addPlayer("itsMe");
+    newgame.send();
 }

+ 15 - 12
Qwixx/playerCard.h

@@ -1,12 +1,15 @@
-#include <vector>
-#include "qwixx.h"
-#include <string>
-class PlayerCard {
-    public: 
-    std::vector<std::vector<bool>> rowColors;
-    int penaltyCount;
-    PlayerCard(std::string);
-    std::string savedName;
-    bool isTurnDone;
-    int score;
-};
+#ifndef PLAYERCARD
+    #define PLAYERCARD
+    #include <vector>
+    #include "qwixx.h"
+    #include <string>
+    class PlayerCard {
+        public: 
+        std::vector<std::vector<bool>> rowColors;
+        int penaltyCount;
+        PlayerCard(std::string);
+        std::string savedName;
+        bool isTurnDone;
+        int score;
+    };
+#endif

+ 4 - 2
Qwixx/qwixx.h

@@ -1,9 +1,11 @@
 #ifndef QWIXX
     #define QWIXX
+    enum{NOT_STARTED, STARTED, FINISHED, PLAYING};
+    // to add a color in the future, place it before white1 below
+    enum {red, yellow, green, blue, white1, white2, colors};
     #define CHECKBOXES 12
+    #define CHECKBOX_COUNT (CHECKBOXES*white1)
     #define PENALTY_VALUE 5
     #define MAX_PENALTY 4
     #define MAX_LOCKOUT 2
-    enum{NOT_STARTED, STARTED, FINISHED, PLAYING};
-    enum {red, yellow, green, blue, white1, white2, colors};
 #endif

+ 10 - 5
Qwixx/toDo.md

@@ -13,14 +13,19 @@
  - 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
 1.  the player whose turn it is adds penalty if no points taken
-1.  scoring phase
- - at the end of the turn, the game may end if there are enough points on any player's card
-     - if any one player has 4 penalties, the game is over
-     - if any 2 rows are locked out, the game is over
+1.  ~~scoring phase~~
+ - ~~at the end of the turn, the game may end if there are enough points on any player's card~~
+     - ~~if any one player has 4 penalties, the game is over~~
+     - ~~if any 2 rows are locked out, the game is over~~
 
 ### notes on turns
-**create end of turn in game
+** create end of turn in game
 **add time constraint to game later**
+**use sockets to make a networkable game and also send data back/forth**
+** 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
+*** what comes in from players: newest item checked off on row&column (maybe 2) or penalty
 
 ## the game is ended
 - list the scores and indicate the winner