Coordinator v2
Dependencies: NerfUSXbee PinDetect EthernetInterface JSON MFRC522 WebSocketClient mbed-rtos mbed
Diff: src/GameCoordinator.cpp
- Revision:
- 2:019d8848cf7e
- Parent:
- 1:e1c5259b7d9a
- Child:
- 3:501120a68c11
diff -r e1c5259b7d9a -r 019d8848cf7e src/GameCoordinator.cpp --- a/src/GameCoordinator.cpp Mon Apr 10 15:02:24 2017 -0400 +++ b/src/GameCoordinator.cpp Tue Apr 11 12:40:05 2017 -0400 @@ -13,7 +13,7 @@ game_modes.push_back(speed_mode); //Starting internal thread - Tget_next_round = Thread(osPriorityNormal, 800); + Tget_next_round = Thread(osPriorityNormal, 1020); Tget_next_round.start(this, &GameCoordinator::get_next_round); } @@ -22,6 +22,9 @@ current_game = game_modes[configs->game_id]; target_timeout = configs->max_reflex_time; number_of_targets = configs->number_of_target; + current_game->reset(); + timer.reset(); + timer.start(); ticker.attach(callback(this, &GameCoordinator::ticker_callback), current_game->getTimeBetweenTargets() / 1000.0); } @@ -29,7 +32,20 @@ { ticker.detach(); LPC_TIM3->TC = 0; - //TODO: send stats back to server + timer.stop(); + ServerEvent stats; + stats.data = current_game->GetStats(); + stats.data.gameLength = timer.read_ms(); + if (stats.data.targets != 0) + { + stats.data.averageReflexTime = stats.data.gameLength / stats.data.targets; + } + + strcpy(stats.event, "report"); + if (on_game_finish != NULL) + { + on_game_finish(stats); + } } void GameCoordinator::ticker_callback() @@ -50,9 +66,19 @@ } else { - //TODO: how to select enemy or ally ? - nextTarget->rise(rand() % 2, target_timeout); + //TODO: how to select enemy or ally ? rand() % 2 + nextTarget->rise(0, target_timeout); } Thread::yield(); } +} + +void GameCoordinator::target_hit(int time_taken) +{ + current_game->OnTargetHit(time_taken); +} + +void GameCoordinator::target_miss() +{ + current_game->OnTargetMiss(); } \ No newline at end of file