Thank you for the input. My main reason for not attempting to code other features in the game yet is because my primary concern is getting down the basic code structure through this menu branching system. Basically, at this point, I've intended to actually get a working version of the game that's coded properly. Perhaps the sooner I make it open source and readable for collaboration, the better.
Although, perhaps you're suggesting that taking on other programming challenges in the project will help me better grasp my other coding problems. And honestly though, I've been getting so frustrated over this menu system and data-driven approach that I wouldn't mind focusing on another part of the project.
I agree that adding more walls of text won't help, that's why I've been offering to solve these problems on the "bare bones", or framework version of the game that I posted in the flowchart.
All in all, I can't deny that it's been rather dissatisfying that I've been working on this for several months now and still can't solve a basic problem for the program. I still have plenty of content and algorithms to add to the game but since I'm lacking a working, fleshed out version of the game that I can run, I feel that grasping the interconnectivity of its systems is becoming more difficult, which is crucial since it will help me understand where to correct or how to append new content to the game.
I figured I'd take a break from trying to improve the menu code and focus on the code for some of the game's other features such as the inspect command and player attributes. In the meantime though I'll post my currently used format based off the framework version of the game that I illustrated in the flowchart. This code essentially contains my current level of coding abilities.
I can't deny, It's not all that beautiful, considering it's just a bunch of nested for loops (and consequently, goto's). It's probably a huge eyesore to professional programmers but believe it or not, I'm having no trouble navigating this style of code, and my version of the game is currently over 700 lines long. If I'm slow to find a label or interface, I use Ctrl+F, and I've yet to forget or get mixed up with the menus' logic flow.
I tried for jlb's advice and seperated the interfaces from the game logic, leaving only some of the 1 and 2-liner display text. I also created the functions to do as little as possible. Also notice that the function declarations and definitions are indented, to represent their place in the game's logic flow.
If I'm keeping the interface functions, I'm considering moving them to a seperate file. If there are any pressing changes I should make to the format of this code, please let me know. Hopefully this will be a lot easier to review than my previous code submissions.
#include <cstdlib>
#include <iostream>
#include <string>
//Output Format Notes:
//* There is a manually-added word-wrap that follows a limit of 64 chars per line
//* Spaces are added after every line in case copy-paste formatting ignores line breaks
//* Line breaks are added before every output that immediately follows an input EXCEPT input error messages
//* Line breaks are added before every "goto startMenu;" expression
//Interfaces:
void
invalidInputResponse(std::string input),
startMenu(),
//actionPrompt:
gameMenu();
int main()
{
std::string input;
startMenu:
startMenu();
for(;;)
{
getline (std::cin, input);
// 1 = New Game (Action Prompt)
// 0 = Quit Game
if (input == "1")
{
actionPrompt:
for(;;)
{
std::cout << "\n"
<< "Enter a command: ";
getline (std::cin, input);
if (input == "gm")
{
gameMenu:
gameMenu();
for(;;)
{
getline (std::cin, input);
// 1 = Return to Game (Action Prompt)
// 0 = Quit to Start Menu
if (input == "1")
goto actionPrompt;
elseif (input == "0")
{
std::cout << "\n"
<< "Are you sure you want to quit? All progress will be lost. \n"
<< "Enter q to quit or c to cancel back to the game menu: ";
for(;;)
{
getline (std::cin, input);
// q = Start Menu
// c = Game Menu
if (input == "q")
{
std::cout << "\n";
goto startMenu;
}
elseif (input == "c")
goto gameMenu;
else
{
invalidInputResponse(input);
std::cout
<< "Please enter either q to quit to the \n"
<< "start menu or c to cancel back to the game menu: ";
continue;
}
}
}
}
}
else
{
invalidInputResponse(input);
std::cout << "Please enter \"gm\" to open the game menu: ";
continue;
}
}
}
elseif (input == "0")
{
std::cout << "\n";
return 0;
}
else
{
invalidInputResponse(input);
std::cout << "Please enter either 1 or 0: ";
continue;
}
}
}
void invalidInputResponse(std::string input)
{ //Output Format Note: For the 64-char word wrap, add 26 to the total char's when calling this function
std::cout << "\"" << input << "\" is not a valid input. ";
}
void startMenu()
{
std::cout
<< "Welcome to [insert game title]! \n"
<< "1) New Game \n"
<< "0) Quit Game \n"
<< "Enter a number: ";
}
//actionPrompt:
void gameMenu()
{
std::cout << "\n"
<< "Game Menu: \n"
<< "1) Return to Game \n"
<< "0) Quit to Start Menu \n"
<< "Enter a number: ";
}