NerfUS game coordinator for the Nerf gun firing range

Dependencies:   HardwareInterface mbed-rtos mbed

Fork of NerfUS by NerfUS

Committer:
Ismael Balafrej
Date:
Fri Mar 17 17:19:42 2017 -0400
Branch:
PlayableGame
Revision:
17:48474266a361
Child:
18:469c8b2a9af9
First Commit of PlayableGame

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 17:48474266a361 3 PlayableGame::PlayableGame(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 17:48474266a361 13 TargetInfo PlayableGame::GetRandomTarget(int timeout_ms)
Ismael Balafrej 17:48474266a361 14 {
Ismael Balafrej 17:48474266a361 15 TargetInfo new_target;
Ismael Balafrej 17:48474266a361 16
Ismael Balafrej 17:48474266a361 17 new_target.id = random_number_generator.get(0, NUMBER_OF_TARGETS);
Ismael Balafrej 17:48474266a361 18 new_target.type = random_number_generator.get(0, 1) == 0 ? TARGET_TYPE_ALLY : TARGET_TYPE_ENEMY;
Ismael Balafrej 17:48474266a361 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 17:48474266a361 29 GameStats PlayableGame::GetStats()
Ismael Balafrej 17:48474266a361 30 {
Ismael Balafrej 17:48474266a361 31 stats.accuracy = stats.numberOfHits * 10000 / (stats.numberOfHits + stats.numberOfMiss);
Ismael Balafrej 17:48474266a361 32 return stats;
Ismael Balafrej 17:48474266a361 33 }