Просмотр исходного кода

added a way for users to join the game in receive method.

wes 4 лет назад
Родитель
Сommit
28c05a4dd1
1 измененных файлов с 10 добавлено и 0 удалено
  1. 10 0
      Qwixx/game.cpp

+ 10 - 0
Qwixx/game.cpp

@@ -138,6 +138,16 @@ struct Turn Game::receive(std::string userInput)
     Turn turnInProgress;
     std::string playerSecret, original = userInput;
     int playerNumber = -1, pos = 0;
+    // check for user request to add themselves to game
+    // userInput == add+stringOfAnyLength
+    if("add" == userInput.substr(0,3))
+    {
+        // add player to game
+        addPlayer(userInput.substr(3));
+        ScoreSheet lastPlayer = players.back();
+        // send player secret - for now it is only printed below
+        fprintf(stdout, "Player %s has a secret of: %d",lastPlayer.savedName, lastPlayer.secretNumber);
+    }
     // look for the position of a comma in userInput
     for(int i = 0;i < userInput.size();i++)
     {