NerfUS game coordinator for the Nerf gun firing range

Dependencies:   HardwareInterface mbed-rtos mbed

Fork of NerfUS by NerfUS

Committer:
Ismael Balafrej
Date:
Thu Mar 30 13:40:36 2017 -0400
Branch:
PlayableGame
Revision:
19:33e8cd56630f
Parent:
18:469c8b2a9af9
W/e

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ismael Balafrej 17:48474266a361 1 #include "PlayableGame.hpp"
Ismael Balafrej 17:48474266a361 2
Ismael Balafrej 18:469c8b2a9af9 3 PlayableGame::PlayableGame(std::vector<TargetInfo> *targets, RandomNumberGenerator& random_number_generator) :
Ismael Balafrej 17:48474266a361 4 random_number_generator(random_number_generator)
Ismael Balafrej 17:48474266a361 5 {
Ismael Balafrej 17:48474266a361 6 }
Ismael Balafrej 17:48474266a361 7
Ismael Balafrej 17:48474266a361 8 bool PlayableGame::IsWeaponValid(int weaponId)
Ismael Balafrej 17:48474266a361 9 {
Ismael Balafrej 17:48474266a361 10 return true;
Ismael Balafrej 17:48474266a361 11 }
Ismael Balafrej 17:48474266a361 12
Ismael Balafrej 18:469c8b2a9af9 13 TargetInfo *PlayableGame::GetRandomTarget(int timeout_ms)
Ismael Balafrej 17:48474266a361 14 {
Ismael Balafrej 18:469c8b2a9af9 15 TargetInfo* new_target;
Ismael Balafrej 18:469c8b2a9af9 16 new_target = &(this->targets->at(random_number_generator.get(0, this->targets->size())));
Ismael Balafrej 18:469c8b2a9af9 17
Ismael Balafrej 18:469c8b2a9af9 18 new_target->type = random_number_generator.get(0, 1) == 0 ? TARGET_TYPE_ALLY : TARGET_TYPE_ENEMY;
Ismael Balafrej 18:469c8b2a9af9 19 new_target->timeout_ms = timeout_ms;
Ismael Balafrej 17:48474266a361 20
Ismael Balafrej 17:48474266a361 21 return new_target;
Ismael Balafrej 17:48474266a361 22 }
Ismael Balafrej 17:48474266a361 23
Ismael Balafrej 17:48474266a361 24 int PlayableGame::GetPoints()
Ismael Balafrej 17:48474266a361 25 {
Ismael Balafrej 17:48474266a361 26 return points;
Ismael Balafrej 17:48474266a361 27 }
Ismael Balafrej 17:48474266a361 28
Ismael Balafrej 19:33e8cd56630f 29 void PlayableGame::Start()
Ismael Balafrej 19:33e8cd56630f 30 {
Ismael Balafrej 19:33e8cd56630f 31 iteration_timer.start(getTargetSpeed);
Ismael Balafrej 19:33e8cd56630f 32 }
Ismael Balafrej 19:33e8cd56630f 33
Ismael Balafrej 19:33e8cd56630f 34 void PlayableGame::Stop()
Ismael Balafrej 19:33e8cd56630f 35 {
Ismael Balafrej 19:33e8cd56630f 36 iteration_timer.stop();
Ismael Balafrej 19:33e8cd56630f 37 }
Ismael Balafrej 19:33e8cd56630f 38
Ismael Balafrej 19:33e8cd56630f 39 void PlayableGame::TimerDoIteration()
Ismael Balafrej 19:33e8cd56630f 40 {
Ismael Balafrej 19:33e8cd56630f 41 TargetInfo * nextTarget = GetNextTarget();
Ismael Balafrej 19:33e8cd56630f 42 nextTarget->riseTarget();
Ismael Balafrej 19:33e8cd56630f 43 }
Ismael Balafrej 19:33e8cd56630f 44
Ismael Balafrej 17:48474266a361 45 GameStats PlayableGame::GetStats()
Ismael Balafrej 17:48474266a361 46 {
Ismael Balafrej 17:48474266a361 47 stats.accuracy = stats.numberOfHits * 10000 / (stats.numberOfHits + stats.numberOfMiss);
Ismael Balafrej 17:48474266a361 48 return stats;
Ismael Balafrej 17:48474266a361 49 }