summaryrefslogtreecommitdiff
path: root/Menu.cpp
diff options
context:
space:
mode:
authorXaviDCR92 <xavi.dcr@gmail.com>2018-07-09 19:26:13 +0200
committerXaviDCR92 <xavi.dcr@gmail.com>2018-07-09 19:26:13 +0200
commitf0b654b9bf3bc2a93c1f89d4cc3edcf77b948555 (patch)
tree91b7404dca0b6eb136cb7f9b144435419144b777 /Menu.cpp
parentd85464781580796bbcc744ae732e56d1920e3b0f (diff)
Game has been restructured in favor of OOP
Diffstat (limited to 'Menu.cpp')
-rw-r--r--Menu.cpp117
1 files changed, 82 insertions, 35 deletions
diff --git a/Menu.cpp b/Menu.cpp
index 85c36ae..a8c0115 100644
--- a/Menu.cpp
+++ b/Menu.cpp
@@ -1,56 +1,103 @@
/* **************************************
- * Includes *
+ * Includes *
* **************************************/
#include "Menu.h"
-#include "Player.h"
-#include "Gameplay.h"
+#include "HumanPlayer.h"
+#include "Game.h"
+#include "System.h"
+#include <Gamebuino.h>
+#include <Arduino.h>
/* **************************************
- * Defines *
+ * Defines *
* **************************************/
+#define GAME_NAME "Pocket Empires"
+
/* **************************************
- * Local variables *
+ * Structs and enums *
* **************************************/
-static const char MainMenuOption_0[] PROGMEM = "Single player game";
-static const char MainMenuOption_1[] PROGMEM = "Multiplayer game";
-static const char MainMenuOption_2[] PROGMEM = "Options";
-static const char MainMenuOption_3[] PROGMEM = "Quit";
-
-static const char* const MainMenuOptions[] PROGMEM = { MainMenuOption_0,
- MainMenuOption_1,
- MainMenuOption_2,
- MainMenuOption_3 };
+/* **************************************
+ * Local variables *
+ * **************************************/
-void MenuGetPlayerName(Player * ptrPlayer)
-{
- memset(ptrPlayer->getName(), 0, PLAYER_NAME_LENGTH);
- gb.getDefaultName(ptrPlayer->getName());
-}
+/* **************************************
+ * Functions definition *
+ * **************************************/
+/*****************************************************************//**
+ *
+ * \brief Video game entry point. Main menu is shown, allowing
+ * the user to choose an option.
+ *
+ *********************************************************************/
void MainMenu(void)
{
- //int8_t menu(const char* const* items, uint8_t length);
+ enum
+ {
+ CHOICE_SINGLE_PLAYER_GAME,
+ CHOICE_MULTI_PLAYER_GAME,
+ CHOICE_OPTIONS,
+
+ MAX_CHOICES
+ };
+
+ static const char strMainMenuOptions_0[] PROGMEM = "Single player game";
+ static const char strMainMenuOptions_1[] PROGMEM = "Multiplayer game";
+ static const char strMainMenuOptions_2[] PROGMEM = "Options";
+
+ static const char* const astrMainMenuOptions[MAX_CHOICES] PROGMEM =
+ {
+ [CHOICE_SINGLE_PLAYER_GAME] = strMainMenuOptions_0,
+ [CHOICE_MULTI_PLAYER_GAME] = strMainMenuOptions_1,
+ [CHOICE_OPTIONS] = strMainMenuOptions_2
+ };
+
+ /* Show video game name on
+ * Gamebuino default title screen. */
+ gb.titleScreen(F(GAME_NAME));
+
+ /* Choose which module should be
+ * executed depending on user input. */
+ switch (gb.menu(astrMainMenuOptions, MAX_CHOICES))
+ {
+ case CHOICE_SINGLE_PLAYER_GAME:
+ {
+ enum
+ {
+ /* Maximum number of characters for
+ * player name, as specified on
+ * Gamebuino documentation. */
+ GAMEBUINO_MAX_PLAYER_NAME = 10
+ };
+
+ char strName[GAMEBUINO_MAX_PLAYER_NAME] = {0};
- uint8_t choice = gb.menu(MainMenuOptions, 3);
+ /* Fill strName with default user name. */
+ gb.getDefaultName(strName);
- switch(choice)
- {
- case 0:
- MenuGetPlayerName(&GamePlayers[0]);
- GameInit();
- break;
- case 1:
- break;
- break;
- case 2:
+ /* Declare 1 human player instance. */
+ HumanPlayer h(strName);
- break;
+ const struct tGameConfig c =
+ {
+ .pHumanPlayerData = &h,
+ .u8NHumanPlayers = 1
+ };
- default:
- break;
- }
+ /* Initialize game with defined configuration. */
+ Game(c);
+ }
+ break;
+ case CHOICE_MULTI_PLAYER_GAME:
+ /* Not implemented yet. Fall through. */
+ case CHOICE_OPTIONS:
+ /* Not implemented yet. Fall through. */
+ default:
+ /* Undefined choice. Exit. */
+ break;
+ }
}