NerfUS game coordinator for the Nerf gun firing range
Dependencies: HardwareInterface mbed-rtos mbed
Fork of NerfUS by
source/PlayableGame.cpp@18:469c8b2a9af9, 2017-03-27 (annotated)
- Committer:
- Ismael Balafrej
- Date:
- Mon Mar 27 11:15:50 2017 -0400
- Branch:
- PlayableGame
- Revision:
- 18:469c8b2a9af9
- Parent:
- 17:48474266a361
- Child:
- 19:33e8cd56630f
Fixed compiling error
Who changed what in which revision?
User | Revision | Line number | New 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 |
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 | } |