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