NerfUS game coordinator for the Nerf gun firing range

Dependencies:   HardwareInterface mbed-rtos mbed

Fork of NerfUS by NerfUS

Committer:
Maxime Dupuis
Date:
Thu Feb 23 21:22:57 2017 -0500
Revision:
16:5e6c695468b6
Child:
18:469c8b2a9af9
Generate a random target course

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Maxime Dupuis 16:5e6c695468b6 1 #include "GameCoordinator.hpp"
Maxime Dupuis 16:5e6c695468b6 2
Maxime Dupuis 16:5e6c695468b6 3 GameCoordinator::GameCoordinator(RandomNumberGenerator& random_number_generator) :
Maxime Dupuis 16:5e6c695468b6 4 random_number_generator(random_number_generator)
Maxime Dupuis 16:5e6c695468b6 5 {
Maxime Dupuis 16:5e6c695468b6 6 }
Maxime Dupuis 16:5e6c695468b6 7
Maxime Dupuis 16:5e6c695468b6 8 std::vector<TargetInfo> GameCoordinator::generate_random_target_course(const int number_of_targets, const int timeout_ms)
Maxime Dupuis 16:5e6c695468b6 9 {
Maxime Dupuis 16:5e6c695468b6 10 std::vector<TargetInfo> target_course;
Maxime Dupuis 16:5e6c695468b6 11
Maxime Dupuis 16:5e6c695468b6 12 for(int i=0; i<number_of_targets; ++i)
Maxime Dupuis 16:5e6c695468b6 13 {
Maxime Dupuis 16:5e6c695468b6 14 TargetInfo new_target;
Maxime Dupuis 16:5e6c695468b6 15
Maxime Dupuis 16:5e6c695468b6 16 new_target.id = random_number_generator.get(0, number_of_targets - 1);
Maxime Dupuis 16:5e6c695468b6 17 new_target.type = random_number_generator.get(0, 1) == 0 ? TARGET_TYPE_ALLY : TARGET_TYPE_ENEMY;
Maxime Dupuis 16:5e6c695468b6 18 new_target.timeout_ms = timeout_ms;
Maxime Dupuis 16:5e6c695468b6 19
Maxime Dupuis 16:5e6c695468b6 20 target_course.push_back(new_target);
Maxime Dupuis 16:5e6c695468b6 21 }
Maxime Dupuis 16:5e6c695468b6 22
Maxime Dupuis 16:5e6c695468b6 23 return target_course;
Maxime Dupuis 16:5e6c695468b6 24 }
Maxime Dupuis 16:5e6c695468b6 25