]> git.uio.no Git - private-olgabo.git/commitdiff
sc
authorolgabo <olgabo@ifi.uio.no>
Thu, 25 Oct 2012 14:41:58 +0000 (16:41 +0200)
committerolgabo <olgabo@ifi.uio.no>
Thu, 25 Oct 2012 14:41:58 +0000 (16:41 +0200)
projects/dumbclient/Game.cpp
projects/dumbclient/Game.h

index 677840f02cd028afa615918e5a364aa18330d0b4..633f4b7c16f4f8f3707c71b3b6b37271b9728ad6 100644 (file)
@@ -14,7 +14,7 @@
 #define CG_PLAYERS 001
 #define CM_PLAYERS 011
 #define CAMERA_STEP 1500
-#define STEPS 1000
+#define STEPS 500
 
 //-------------------------------------------------------------------------------------
 Game::Game(string server, int port, string nickname, int delay)
@@ -47,6 +47,12 @@ void Game::init()
     newScoreUpdate = false;
     animation = 0;
     otherPlayer = 0;
+    gettimeofday(&gameStart, NULL);
+    struct timeval gameDuration;
+    gameDuration.tv_sec = 420;
+    gameDuration.tv_usec = 0;
+    timeradd(&gameStart, &gameDuration, &gameEnd);
+
     
 
     if (gameServer != "offline")
@@ -541,6 +547,7 @@ bool Game::frameRenderingQueued(const FrameEvent &evt)
     moveCats(evt);
     printStepsLeft();
     printPlayerScore();
+    printTime();
 
     gettimeofday(&curTime, NULL);
     Real t = curTime.tv_sec - msgTime.tv_sec;
@@ -1463,6 +1470,16 @@ void Game::createPlayer(int id)
         stepsBoard->showOnTop();
         stepsBoard->setFontName("BlueHighway-12");
         stepsBoardNode->attachObject(stepsBoard);
+
+        SceneNode* timeBoardNode = cameraNode->createChildSceneNode(Vector3( 5, 21.4, -8.5));
+        timeBoard = new MovableText("timeBoard", " . " );
+        timeBoard->setTextAlignment(MovableText::H_LEFT, MovableText::V_ABOVE); 
+        timeBoard->setColor(ColourValue::Black);
+        timeBoard->setCharacterHeight(0.8);
+        timeBoard->showOnTop();
+        timeBoard->setFontName("BlueHighway-12");
+        timeBoardNode->attachObject(timeBoard);
+       
        
         if (nickName.length() > 0)
             playerCaption = nickName;
@@ -1901,6 +1918,12 @@ void Game::moveCats(const FrameEvent &evt)
 
 void Game::exit()
 {
+    gettimeofday(&gameEnd, NULL);
+    struct timeval gameDuration;
+
+    timersub(&gameEnd, &gameStart, &gameDuration);
+
+
     memset(sendbuffer, 0, BUFFERSIZE);
     int size = sizeof(struct timeval) + sizeof(Vector3) + sizeof(Quaternion) + sizeof(int);        
     client->sendMessage(sendbuffer, size);
@@ -1910,17 +1933,20 @@ void Game::exit()
     cout << "------------------- SCORE ----------------------\n";
 
     cerr << "printing score\n"; 
-
-    const std::string filename = "results/" + 
+    
+    const std::string filename = "results/" + nickName + "/" +
                                  StringConverter::toString(delay_ms) + "-" + 
                                  StringConverter::toString(sessionId) + "-" + 
                                  StringConverter::toString(myPlayerId) + ".txt";
+    
+    const std::string testfilename = "test.txt";
     ofstream file;
+
     file.open(filename.c_str(), ios::out|ios::app|ios::binary);
     
     file << score.size() << "\n";
 
-    for (i = 0; i < score.size(); i++)
+  /*  for (i = 0; i < score.size(); i++)
     {
         scoreunit current = score.at(i);
         file << current.timestamp.tv_sec << " " << 
@@ -1947,7 +1973,14 @@ void Game::exit()
        
         cout << "from player " << current.playerA << " to " << current.playerB << "\n";
         
-    }
+    }*/
+
+    file << "punch(done:ack:rec) " << localPlayer->PunchesDone << " " << localPlayer->PunchesDoneAck << " " <<  localPlayer->PunchesReceived << "\n";
+    file << "handshake " << " " << localPlayer->HandshakesDone << " " << localPlayer->HandshakesDoneAck << "\n";
+    file << "RPS " << localPlayer->RPSDone << " " << localPlayer->RPSDoneAck << " " << localPlayer->RPSReceived << "\n";
+    file << "wave " << localPlayer->WavesDone << localPlayer->WavesDoneAck << " " << localPlayer->WavesReceived <<"\n";
+    file << "game(duration(sec)) " << gameDuration.tv_sec << "\n";
+       
     file.close();
 
     cout << localPlayer->HandshakesDone << " handshakes done\n";
@@ -2019,6 +2052,20 @@ void Game::correctScore()
     }
     newScoreUpdate = false;
 }
+void Game::printTime()
+{
+    std::string caption = "Time left (sec): ";
+    struct timeval now;
+    struct timeval timeLeft;
+    gettimeofday(&now, NULL);
+   
+    timersub(&gameEnd, &now, &timeLeft);
+    caption = caption + StringConverter::toString(timeLeft.tv_sec);
+    
+    timeBoard->setCaption(caption);
+    if (timeLeft.tv_sec <= 0)
+        exit();
+}
   
 
 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
index 3d4a4bd0757befd8c933324e92d8826cc8e23b3a..9436960fb3f6f131a6d77374b53a6d8b089eb3cd 100644 (file)
@@ -119,6 +119,7 @@ protected:
     bool canWave(Player* player);
     void updateRealState();
     void correctScore();
+    void printTime();
 
     std::deque<Entity *> collisionObjects;
     
@@ -130,6 +131,7 @@ protected:
     MovableText* msgBoard;
     MovableText* scoreBoard;
     MovableText* stepsBoard;
+    MovableText* timeBoard;
    // Camera* second;
               
     Real mToggle;    // The time left until next toggle
@@ -193,6 +195,9 @@ protected:
     struct timeval msgTime;
     struct timeval curTime;
 
+    struct timeval gameStart;
+    struct timeval gameEnd;
+
    // bool verify;
     bool newRealState;
     bool newScoreUpdate;