NerfUS game coordinator for the Nerf gun firing range
Dependencies: HardwareInterface mbed-rtos mbed
Fork of NerfUS by
PlayableGame.hpp
00001 #pragma once 00002 00003 #include <vector> 00004 #include "Target.hpp" 00005 #include "RandomNumberGenerator.hpp" 00006 #include "rtos.h" 00007 00008 struct GameStats 00009 { 00010 int timeTaken; //ms 00011 int numberOfHits; 00012 int numberOfMiss; 00013 int accuracy; //4 digits percentage to avoid a float 00014 int averageTimePerTarget; //ms 00015 }; 00016 00017 //Abstract class, must be implemented as a GameMode 00018 class PlayableGame 00019 { 00020 public: 00021 PlayableGame(std::vector<TargetInfo> *targets, RandomNumberGenerator& random_number_generator); 00022 ~PlayableGame(); 00023 00024 virtual bool IsWeaponValid(int weaponId); //Default to any Weapons 00025 virtual int GetPoints(); 00026 virtual GameStats GetStats(); 00027 virtual TargetInfo* GetNextTarget() = 0; 00028 00029 void Start(); //Create a thread that will call GetNextTarget at set speed 00030 void Stop(); //Stop the thread 00031 int getTargetSpeed = 10; //ms 00032 00033 protected: 00034 int points; 00035 GameStats stats; 00036 TargetInfo *GetRandomTarget(int timeout_ms); 00037 std::vector<TargetInfo>* targets; 00038 00039 virtual void OnTargetHit(int timeTaken) = 0; 00040 virtual void OnTargetMiss() = 0; 00041 00042 private: 00043 RandomNumberGenerator& random_number_generator; 00044 RtosTimer iteration_timer(TimerDoIteration); 00045 void TimerDoIteration(); 00046 };
Generated on Thu Jul 14 2022 07:10:37 by 1.7.2