I’m kinda going above and beyond here. I’ve been tasked with creating a pseudo Minesweeper game for my C++ class. All the root coding is done, and all I want to do now is create a cool menu for it. At the moment all I have is this:
#include <iostream>
#include <cstdlib>
using namespace std;
bool menu ()
{
int inpt;
bool exitVar;
system("cls");
cout << " _ _ _ _ _ _ _ _ " << endl
<< " |_|_ _|_| |_| |_|_ |_| |_|_|_| " << endl
<< " |_|_|_|_|_| |_| |_|_|_ |_| |_|_ " << endl
<< " |_| |_| |_| |_| |_| |_|_|_| |_|_| " << endl
<< " |_| |_| |_| |_| |_|_| |_|_ _ " << endl
<< " |_| |_| |_| |_| |_| |_|_|_| " << endl
<< " _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ " << endl
<< " _|_|_| |_| |_| |_|_|_| |_|_|_| |_|_|_ |_|_|_| |_|_|_ " << endl
<< " |_|_ |_| _ |_| |_|_ |_|_ |_|_|_| |_|_ |_|_|_| " << endl
<< " |_|_ |_|_|_|_|_| |_|_| |_|_| |_|_| |_|_| |_|_|_ " << endl
<< " _ _|_| |_|_| |_|_| |_|_ _ |_|_ _ |_| |_|_ _ |_| |_|_ " << endl
<< " |_|_| |_| |_| |_|_|_| |_|_|_| |_| |_|_|_| |_| |_| " << endl;
cout << "\n Welcome to Psuedo Mine Sweeper!!\n\n\n\n";
cout << "Please choose from one of the following options:\n";
cout << "1 - Play Psuedo Mine Sweeper!\n";
cout << "2 - Exit Program :(\n\n";
cout << "(1 or 2):";
cin >> inpt;
while (inpt < 1 || inpt > 2 || cin.fail())
{
cin.clear();
cin.ignore();
cout << "Please enter a valid menu choice : ";
cin >> inpt;
}
if (inpt = 1)
exitVar = true;
else
exitVar = false;
return exitVar;
}
Pretty simple. What I want to do is create a screen where the user can use the UP and DOWN keyboard keys to select either START or EXIT, and press ENTER to confirm their selection. I think that this would be done with an event in Java or something like that. But in C++ I have no idea how to do it. All I need is just some help getting started. My intro C++ book doesn’t cover anything like this.
Again, I’m looking to create a simple splash screen similar to what you’d find in like an old Nintendo game or something. I’ll be doing some playing around myself, but I thought this would be a good place to ask to get going in the right direction.
Thanks for the help in advance!
The way you accomplish this is platform dependent. If you’re just using the console you’ll probably want to use a library of some sort to help style the text (such as inverting the characters and background for a selected menu item). I’m not intimately familiar with any of these, but try searching for the curses library as an example of where to start.
This isn’t as easy as it sounds. Depending on how the library works, you’ll need to redraw the splash screen whenever a user sends input, store which menu item index is currently selected, and selectively recolor that menu item depending on if it’s selected or not.
Getting input is also going to depend on the platform, and getting arrow key input in particular is tricky for the console. Using numbers is much easier, since you can just read a character in and use that as the menu index (i.e. if the user hits the 1 key, choose the first menu index).