1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
#include <iostream>
#include <string>
using namespace std;
//----------------------------------------------------------------------------
// http://www.cplusplus.com/articles/4z18T05o/#Windows
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
void ClearScreen()
{
HANDLE hStdOut;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD count;
DWORD cellCount;
COORD homeCoords = { 0, 0 };
hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
if (hStdOut == INVALID_HANDLE_VALUE) return;
/* Get the number of cells in the current buffer */
if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
cellCount = csbi.dwSize.X *csbi.dwSize.Y;
/* Fill the entire buffer with spaces */
if (!FillConsoleOutputCharacter(
hStdOut,
(TCHAR) ' ',
cellCount,
homeCoords,
&count
)) return;
/* Fill the entire buffer with the current colors and attributes */
if (!FillConsoleOutputAttribute(
hStdOut,
csbi.wAttributes,
cellCount,
homeCoords,
&count
)) return;
/* Move the cursor home */
SetConsoleCursorPosition( hStdOut, homeCoords );
}
//----------------------------------------------------------------------------
// Pause on quit
// http://www.cplusplus.com/forum/lounge/171162/
#ifdef _WIN32
#include <iostream>
#include <string>
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
struct pause_on_quit { bool is_console_owner; pause_on_quit() {
FreeConsole(); is_console_owner = !AttachConsole( ATTACH_PARENT_PROCESS );
if (is_console_owner) AllocConsole(); } ~pause_on_quit() { if
(is_console_owner) { std::cout << "All done. Press ENTER or close the "
"window."; FlushConsoleInputBuffer( GetStdHandle( STD_INPUT_HANDLE ) );
std::string s; std::getline( std::cin, s ); } } } Z201508081318;
#endif
//----------------------------------------------------------------------------
enum MainMenuChoice { mmStartGame, mmExit };
MainMenuChoice MainMenu()
{
ClearScreen();
string s;
cout <<
"**************************************************\n"
"* Main Menu *\n"
"* *\n"
"* 1)Start Game *\n"
"* 2)Exit *\n"
"* *\n"
"**************************************************\n";
string prompt = "Choose> ";
while (true)
{
cout << prompt;
getline( cin, s );
switch (s.c_str()[0])
{
case '1': return mmStartGame;
case '2': return mmExit;
}
prompt = "Invalid. Choose again> ";
}
}
//----------------------------------------------------------------------------
void PlayGame()
{
ClearScreen();
cout << "\n\nPut gameplay here.\nPress ENTER to return to Main Menu.\n";
string s;
getline( cin, s );
}
//----------------------------------------------------------------------------
int main()
{
// Initializations go here
// Main loop
bool done = false;
while (!done)
{
switch (MainMenu())
{
case mmStartGame: PlayGame(); break;
case mmExit: done = true; break;
}
}
// Finalizations go here
cout << "Goodbye!\n";
}
|