Copy Link
Add to Bookmark
Report

Making Menus

Part of "The QB Times issue 4 and 5"

eZine's profile picture
Published in 
The QB Times
 · 1 year ago
Making Menus
Pin it

Introduction

Hi, and welcome to this article for beginning QBasic programmers about menus. I will cover some basic menus and move on to more advanced menus. In this article I'll cover: simple 'press a key menus', menu's with a 'highlight selection bar', graphical menus and even mouse driven menus. I'll discuss each type of menu with the pros & cons, an example how to make one. As a last thing I want to state that this article is especially written for newbies. I found that there were not enough articles in the QB magazines (including The QB Times) that were for newbies so I thought why don't we make some? Well let's get started now!

'Press a key menus'

What I mean with 'Press a key menus' is the following: you get a menu on your screen looking like this:

(N)ew Game 
(L)oad Game
(S)ave Game
(I)nstructions
(Q)uit


And you press N for New Game, L for Load Game etc. This menu is fairly easy to make and I've seen it used in a lot of games. It's not very nice to see but it gets the job done. I'll list the Pros & Cons in a nice little table now:

ProsCons
Easy to make
Takes almost no coding space
Doesn't look nice


So now you know the Pros & Cons of this menu let's get started on the coding. We'll use the example menu for this coding example:

PRINT "(N)ew Game" 
PRINT "(L)oad Game"
PRINT "(S)ave Game"
PRINT "(I)nstructions"
PRINT "(Q)uit"

DO
a$ = INKEY$
SELECT CASE UCASE$(a$)
CASE "N"
PRINT "You selected New Game!"
CASE "L"
PRINT "You selected Load Game!"
CASE "S"
PRINT "You selected Save Game!"
CASE "I"
PRINT "You selected Instructions!"
CASE "Q"
PRINT "You selected Quit!"
PRINT "Have a nice day!"
SYSTEM
END SELECT
LOOP


This code will create an example menu and if you press one of the menu's keys the program will show which option you have chosen and if you selected Quit it'll print a greeting and then exit the program I'll discuss the program in blocks of a few lines of code now. We'll use the example menu for this coding example:

PRINT "(N)ew Game" 
PRINT "(L)oad Game"
PRINT "(S)ave Game"
PRINT "(I)nstructions"
PRINT "(Q)uit"


This just prints out the basic menu.

DO 
a$ = INKEY$
SELECT CASE UCASE$(a$)


This starts a DO...LOOP, give a$ the value of INKEY$ (the string that holds which key is pressed) and starts a SELECT CASE with the value of a$ in capital (UCASE$(a$).Of course, this code is for example purposes only and could be optimized a lot. For example you can create a function were you add the keys that can be pressed as a parameter list and let the function return 1, 2, 3, 4 or 5 according to the keys pressed. This is just an example and there can be many more optimizations.

My conclusion for this menu is that I would not use this menu in my game. Although it's very easy to create it really doesn't look nice. There many other nice looking and easy to create menus, like the highlight selection menu.

'Highlight selection' menu

Highlight selection menus are the kind of menus were you have a bar and you can move the bar and when the bar is at your selection you press enter to select it. It looks something like this: (Instructions should have a blue background but if you use Netscape it won't show up)

New Game 
Load Game
Instructions
Quit Game


My Cons & Pros are listed in the table below:

ProsCons
Easy to make
Takes very little code Looks good in text games
Doesn't look good in other games


Now then, let's go to the code of the menu:

Click here to download the example menu.

I'll discuss the code now:


My conclusion for this menu is that if you're making a text game you can very well use this menu. But if you're making a graphical game you can make the same kind of menu with graphics and that's much nicer!

Well, you now know how to do some menus. In the next issue I'll continue this article and we'll get into making graphical and mouse driven menus. I hope you like this article.. Don't hesitate to tell me :-)

← previous
next →
loading
sending ...
New to Neperos ? Sign Up for free
download Neperos App from Google Play
install Neperos as PWA

Let's discover also

Recent Articles

Recent Comments

Neperos cookies
This website uses cookies to store your preferences and improve the service. Cookies authorization will allow me and / or my partners to process personal data such as browsing behaviour.

By pressing OK you agree to the Terms of Service and acknowledge the Privacy Policy

By pressing REJECT you will be able to continue to use Neperos (like read articles or write comments) but some important cookies will not be set. This may affect certain features and functions of the platform.
OK
REJECT