NerfUS game coordinator for the Nerf gun firing range

Dependencies:   HardwareInterface mbed-rtos mbed

Fork of NerfUS by NerfUS

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?

UserRevisionLine numberNew contents of line
Ismael Balafrej 17:48474266a361 1 #pragma once
Ismael Balafrej 17:48474266a361 2
Ismael Balafrej 17:48474266a361 3 #include <vector>
Ismael Balafrej 17:48474266a361 4 #include "Target.hpp"
Ismael Balafrej 17:48474266a361 5 #include "RandomNumberGenerator.hpp"
Ismael Balafrej 17:48474266a361 6
Ismael Balafrej 17:48474266a361 7 struct GameStats
Ismael Balafrej 17:48474266a361 8 {
Ismael Balafrej 17:48474266a361 9 int timeTaken; //ms
Ismael Balafrej 17:48474266a361 10 int numberOfHits;
Ismael Balafrej 17:48474266a361 11 int numberOfMiss;
Ismael Balafrej 17:48474266a361 12 int accuracy; //4 digits percentage to avoid a float
Ismael Balafrej 17:48474266a361 13 int averageTimePerTarget; //ms
Ismael Balafrej 17:48474266a361 14 };
Ismael Balafrej 17:48474266a361 15
Ismael Balafrej 17:48474266a361 16 //Abstract class, must be implemented as a GameMode
Ismael Balafrej 17:48474266a361 17 class PlayableGame
Ismael Balafrej 17:48474266a361 18 {
Ismael Balafrej 17:48474266a361 19 public:
Ismael Balafrej 17:48474266a361 20 PlayableGame(std::vector<TargetInfo> *targets, RandomNumberGenerator& random_number_generator);
Ismael Balafrej 17:48474266a361 21 ~PlayableGame();
Ismael Balafrej 17:48474266a361 22
Ismael Balafrej 17:48474266a361 23 virtual bool IsWeaponValid(int weaponId); //Default to any Weapons
Ismael Balafrej 17:48474266a361 24 virtual int GetPoints();
Ismael Balafrej 17:48474266a361 25 virtual GameStats GetStats();
Ismael Balafrej 17:48474266a361 26
Ismael Balafrej 18:469c8b2a9af9 27 virtual TargetInfo* GetNextTarget() = 0;
Ismael Balafrej 17:48474266a361 28 void Start(); //Create a thread that will call GetNextTarget at set speed
Ismael Balafrej 17:48474266a361 29 void Stop(); //Stop the thread
Ismael Balafrej 17:48474266a361 30
Ismael Balafrej 17:48474266a361 31 protected:
Ismael Balafrej 17:48474266a361 32 int points;
Ismael Balafrej 17:48474266a361 33 GameStats stats;
Ismael Balafrej 18:469c8b2a9af9 34 TargetInfo *GetRandomTarget(int timeout_ms );
Ismael Balafrej 18:469c8b2a9af9 35 std::vector<TargetInfo>* targets;
Ismael Balafrej 17:48474266a361 36
Ismael Balafrej 17:48474266a361 37 virtual void OnTargetHit(int timeTaken) = 0;
Ismael Balafrej 17:48474266a361 38 virtual void OnTargetMiss() = 0;
Ismael Balafrej 17:48474266a361 39
Ismael Balafrej 17:48474266a361 40 private:
Ismael Balafrej 17:48474266a361 41 RandomNumberGenerator& random_number_generator;
Ismael Balafrej 17:48474266a361 42 };