have to create a C++ game that is 500 lines of code. I was wondering how do you create a basic menu that would allow the user to push either 1 to play game, and 2 for help which would give the rules of the game? Would it be using if/else statements or a switch statement or functions? Can anyone point me in the right direction? I have the main code of the game working that just goes straight into the game when executed but how do I get a menu to show up first?
C++ game help. How to create a menu on a console game of 500 lines of code.?
You can use pretty simple input and output commands for that: cin and cout:
Here are some examples:
http://xoax.net/comp/cpp/console/Lesson2...
Reply:From your description I'm assuming the game is console-based. In this case you can simply
cout %26lt;%26lt; "enter the choice (1 for play, 2 for help): ";
and then:
int c;
cin %26gt;%26gt; c;
if(c==1) play();
else help();
How does that sound? In case you want to do some error checking as well... then I would read a string and extract any numerical data from it.
Reply:Lines of code is a pathetic way to measure the size of a program.
std::cout %26lt;%26lt; "1. Play Game" %26lt;%26lt; std::endl %26lt;%26lt; "2. Help" %26lt;%26lt; std::endl; while(1){ char a = std::cin.getch(); if( a == '1') playgame(); elseif( a== '2') showhelp(); elseif( a == 'q') break;}
All on one line.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment