From dd942f1eb8779dc441cde9c96c2c2031472b6637 Mon Sep 17 00:00:00 2001 From: Joshua Saxby <Joshua2.Saxby@live.uwe.ac.uk> Date: Sat, 8 Feb 2020 22:48:35 +0000 Subject: [PATCH] Created skeleton Game class within which the game logic shall be --- source/main.cpp | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index d61165f..42d8caa 100755 --- a/source/main.cpp +++ b/source/main.cpp @@ -17,16 +17,41 @@ #include "MicroBit.h" -MicroBit uBit; -int main() -{ +class Game { +public: + Game(MicroBit& micro_bit); + + void run(); + +private: + MicroBit& micro_bit; +}; + +Game::Game(MicroBit& micro_bit) + : micro_bit(micro_bit) + {} + +void Game::run() { + this->micro_bit.display.scroll("NEW GAME"); +} + +MicroBit micro_bit; + +int main(void) { // Initialise the micro:bit runtime. - uBit.init(); + micro_bit.init(); + + // startup message displays the name of the game + micro_bit.display.scroll("BLOCKS!"); - // Insert your code here! - uBit.display.scroll("HELLO WORLD! :)"); + // infinitely start new games + while (true) { + Game game(micro_bit); + game.run(); + } + // TODO: potentially remove this call, if clarified that it is not required. // If main exits, there may still be other fibers running or registered event handlers etc. // Simply release this fiber, which will mean we enter the scheduler. Worse case, we then // sit in the idle task forever, in a power efficient sleep. -- GitLab