NerfUS game coordinator for the Nerf gun firing range
Dependencies: HardwareInterface mbed-rtos mbed
Fork of NerfUS by
Revision 19:33e8cd56630f, committed 2017-03-30
- Comitter:
- Ismael Balafrej
- Date:
- Thu Mar 30 13:40:36 2017 -0400
- Branch:
- PlayableGame
- Parent:
- 18:469c8b2a9af9
- Commit message:
- W/e
Changed in this revision
--- a/include/GameModes/PrecisionMode.hpp Mon Mar 27 11:15:50 2017 -0400
+++ b/include/GameModes/PrecisionMode.hpp Thu Mar 30 13:40:36 2017 -0400
@@ -3,15 +3,17 @@
#include "Target.hpp"
#include <cstddef>
-class PrecisionMode : PlayableGame
+class PrecisionMode : public PlayableGame
{
public:
+ using PlayableGame::PlayableGame;
~PrecisionMode();
TargetInfo * GetNextTarget();
void OnTargetHit(int timeTaken);
void OnTargetMiss();
GameStats GetStats();
+ int getTargetSpeed = 1500;
private:
int currentTarget = 0;
--- a/include/PlayableGame.hpp Mon Mar 27 11:15:50 2017 -0400
+++ b/include/PlayableGame.hpp Thu Mar 30 13:40:36 2017 -0400
@@ -3,6 +3,7 @@
#include <vector>
#include "Target.hpp"
#include "RandomNumberGenerator.hpp"
+#include "rtos.h"
struct GameStats
{
@@ -23,15 +24,16 @@
virtual bool IsWeaponValid(int weaponId); //Default to any Weapons
virtual int GetPoints();
virtual GameStats GetStats();
+ virtual TargetInfo* GetNextTarget() = 0;
- virtual TargetInfo* GetNextTarget() = 0;
void Start(); //Create a thread that will call GetNextTarget at set speed
void Stop(); //Stop the thread
+ int getTargetSpeed = 10; //ms
protected:
int points;
GameStats stats;
- TargetInfo *GetRandomTarget(int timeout_ms );
+ TargetInfo *GetRandomTarget(int timeout_ms);
std::vector<TargetInfo>* targets;
virtual void OnTargetHit(int timeTaken) = 0;
@@ -39,4 +41,6 @@
private:
RandomNumberGenerator& random_number_generator;
+ RtosTimer iteration_timer(TimerDoIteration);
+ void TimerDoIteration();
};
\ No newline at end of file
--- a/source/GameCoordinator.cpp Mon Mar 27 11:15:50 2017 -0400
+++ b/source/GameCoordinator.cpp Thu Mar 30 13:40:36 2017 -0400
@@ -2,8 +2,8 @@
GameCoordinator::GameCoordinator(RandomNumberGenerator &random_number_generator) : random_number_generator(random_number_generator)
{
- //TODO Initialize gamemodes
- //this->gameModes[0] = PrecisionMode(&(this->targets), random_number_generator);
+ PrecisionMode precisionMode(&(this->targets), random_number_generator);
+ this->gameModes[0] = &precisionMode;
}
std::vector<TargetInfo> GameCoordinator::generate_random_target_course(const int number_of_targets, const int timeout_ms)
--- a/source/PlayableGame.cpp Mon Mar 27 11:15:50 2017 -0400
+++ b/source/PlayableGame.cpp Thu Mar 30 13:40:36 2017 -0400
@@ -26,6 +26,22 @@
return points;
}
+void PlayableGame::Start()
+{
+ iteration_timer.start(getTargetSpeed);
+}
+
+void PlayableGame::Stop()
+{
+ iteration_timer.stop();
+}
+
+void PlayableGame::TimerDoIteration()
+{
+ TargetInfo * nextTarget = GetNextTarget();
+ nextTarget->riseTarget();
+}
+
GameStats PlayableGame::GetStats()
{
stats.accuracy = stats.numberOfHits * 10000 / (stats.numberOfHits + stats.numberOfMiss);
