Qbasicnews.com
February 22, 2020, 08:39:50 PM
 Welcome, Guest. Please login or register. 1 Hour 1 Day 1 Week 1 Month Forever Login with username, password and session length
 Home Help Search Login Register
 Pages: [1] 2 3
 Author Topic: Creating Main Menu - Problem  (Read 6500 times)
drjulio2003
New Member

Posts: 9

 « on: December 17, 2003, 05:19:47 PM »

I can't quite finish this program that only creates a main menu.

Code:

DECLARE SUB CenterText (t\$, y)
DECLARE SUB Keyboard (cube(), dark(), x, y, et)
DIM cube(1 TO 377)
DIM dark(1 TO 377)

CLS : SCREEN 13
CenterText "Word Guessing", 0
CenterText " ", 7
CenterText "Start Program", 1
CenterText "Get Help", 1
CenterText "Quit", 1
LINE (90, 79)-(99, 87), 0, BF
GET (90, 79)-(99, 87), dark
LINE (90, 79)-(99, 87), , B
GET (90, 79)-(99, 87), cube
x = 90: y = 79: et = 1
Keyboard cube(), dark(), x, y, et
END

SUB CenterText (t\$, y)
FOR i = 1 TO y
PRINT
NEXT i
x = (20 - INT(LEN(t\$) / 2))
PRINT TAB(x); t\$
END SUB

SUB Keyboard (cube(), dark(), x, y, et)

DO
k\$ = INKEY\$
IF k\$ = CHR\$(0) + CHR\$(72) THEN
xold = x: yold = y
x = x - 15: y = y - 16
et = et - 1
PUT (xold, yold), cube, PSET
IF x <= 85 THEN
x = xold: y = yold
END IF
IF et <= 0 THEN
et = 1
END IF
END IF
IF k\$ = CHR\$(0) + CHR\$(80) THEN
et = et + 1
xold = x: yold = y
x = x + 15: y = y + 16
PUT (x, y), cube, PSET
PUT (xold, yold), dark, PSET
IF x >= 120 THEN
x = xold: y = yold
END IF
IF et >= 3 THEN
et = 2
END IF
END IF
LOOP

END SUB

Well, I know what the problem is, which is that the square block doesn't want to clear out the block when you press the up key, but how can I do this?  Thank you  for your help!  [/code]
Code:
Code:
 Logged
HPLilSnowHP
Member

Posts: 76

 « Reply #1 on: December 17, 2003, 05:52:39 PM »

Im not sure what it would be..But..What is your program designed to do
 Logged
drjulio2003
New Member

Posts: 9

 « Reply #2 on: December 17, 2003, 06:17:15 PM »

I'm trying to create a Navigation Menu for my programs.

|_| Start Program
Get Help
Quit

down key press

Start Program
|_|  Get Help
Quit
etc...
Code:
 Logged
HPLilSnowHP
Member

Posts: 76

 « Reply #3 on: December 17, 2003, 06:51:29 PM »

Oh..Thats kool..Id like to see what it looks like when u get finsihed if u dont mind....
 Logged
Meg
Ancient QBer

Posts: 483

 « Reply #4 on: December 17, 2003, 07:46:45 PM »

Create a variable called "CurrentSelection%" and have it set intially to 1.  Then make your keyboard routine do this (note.. this is pseudo-code):

Code:
DO
DO
k\$ = INKEY\$
LOOP UNTIL k\$ = (up arrow, down arrow, or enter key)

Select Case k\$
case (up arrow)
if CurrentSelection% > 1 then
CurrentSelection% = CurrentSelection% - 1
(Erase Box @ coordinates based off of CurrentSelection%)
(Draw New Box @ coordinates based off of CurrentSelection%)
end if

case (down arrow)
if CurrentSelection% < 3 then
CurrentSelection% = CurrentSelection% + 1
(Erase Box @ coordinates based off of CurrentSelection%)
(Draw New Box @ coordinates based off of CurrentSelection%)
end if

case (enter key)
EXIT SUB
end select
LOOP

*peace*

Meg.
 Logged
TheBigBasicQ
*/-\*

Posts: 4550

 « Reply #5 on: December 18, 2003, 01:02:46 PM »

Ah better yet. Here i could get it working. See the difference. You had forgotten to add the put(xold, yold), dark, pset command to the if block where you moved that square thingy up.

Code:
DECLARE SUB CenterText (t\$, y)
DECLARE SUB Keyboard (cube(), dark(), x, y, et)
DIM cube(1 TO 377)
DIM dark(1 TO 377)

CLS : SCREEN 13
CenterText "Word Guessing", 0
CenterText " ", 7
CenterText "Start Program", 1
CenterText "Get Help", 1
CenterText "Quit", 1
LINE (90, 79)-(99, 87), 0, BF
GET (90, 79)-(99, 87), dark
LINE (90, 79)-(99, 87), , B
GET (90, 79)-(99, 87), cube
x = 90: y = 79: et = 1
Keyboard cube(), dark(), x, y, et
END

SUB CenterText (t\$, y)
FOR i = 1 TO y
PRINT
NEXT i
x = (20 - INT(LEN(t\$) / 2))
PRINT TAB(x); t\$
END SUB

SUB Keyboard (cube(), dark(), x, y, et)
STATIC xold AS INTEGER
STATIC yold AS INTEGER
xold = x
yold = y

DO
K\$ = INKEY\$
IF K\$ = CHR\$(0) + CHR\$(72) THEN
'IF x <= 85 THEN
'   x = xold: y = yold
'END IF
IF et > 1 THEN
x = x - 15: y = y - 16
et = et - 1
PUT (x, y), cube, PSET
PUT (xold, yold), dark, PSET
xold = x: yold = y
END IF
END IF
IF K\$ = CHR\$(0) + CHR\$(80) THEN
'IF x >= 120 THEN
'   x = xold: y = yold
'END IF
IF et < 3 THEN
et = et + 1
x = x + 15: y = y + 16
PUT (x, y), cube, PSET
PUT (xold, yold), dark, PSET
xold = x: yold = y
END IF
END IF
LOOP UNTIL K\$ = CHR\$(27)

END SUB
 Logged
drjulio2003
New Member

Posts: 9

 « Reply #6 on: December 18, 2003, 02:53:57 PM »

Code:
DECLARE SUB PrintMenu ()
DECLARE SUB Quit ()
DECLARE SUB StartProgram ()
DECLARE SUB GetHelp ()
DECLARE SUB CenterText (t\$, y)
DECLARE SUB keyboard (cube(), dark(), x, y, et)
DIM cube(1 TO 377)
DIM dark(1 TO 377)

CLS : SCREEN 13
DO
LINE (90, 79)-(99, 87), 0, BF
GET (90, 79)-(99, 87), dark
LINE (90, 79)-(99, 87), , B
GET (90, 79)-(99, 87), cube
x = 90: y = 79: et = 1
keyboard cube(), dark(), x, y, et
LOOP
END

SUB CenterText (t\$, y)
FOR i = 1 TO y
PRINT
NEXT i
x = (20 - INT(LEN(t\$) / 2))
PRINT TAB(x); t\$
END SUB

SUB GetHelp
CLS : SCREEN 13
CenterText "Word Guessing", 2
CenterText "The game is very simple:", 1
CenterText "guess the word. The game will give", 1
CenterText "you a clud, by having a significately ", 1
CenterText "number of lines represented by how many ", 1
CenterText "letters their are in the word. You'll", 1
CenterText "have 9 tries, after that is game over. ", 1
CenterText "Use the keyboard to guess the word.", 1
CenterText "Press any key to continue", 5
DO
LOOP UNTIL INKEY\$ <> ""
END SUB

SUB keyboard (cube(), dark(), x, y, et)
DO
k\$ = INKEY\$
IF k\$ = CHR\$(0) + CHR\$(72) THEN
xold = x: yold = y
PUT (j, k), dark, PSET
x = x - 15: y = y - 16
j = j - 15: k = k - 16
et = et - 1
PUT (xold, yold), cube, PSET
IF x <= 85 THEN
x = xold: y = yold
END IF
IF et <= 0 THEN
et = 1
END IF
END IF
IF k\$ = CHR\$(13) THEN
GOTO 1
END IF
IF k\$ = CHR\$(0) + CHR\$(80) THEN
et = et + 1
xold = x: yold = y
x = x + 15: y = y + 16
PUT (x, y), cube, PSET
PUT (xold, yold), dark, PSET
j = 120: k = 111
IF x >= 120 THEN
x = xold: y = yold
END IF
IF et > 3 THEN
et = 3
END IF
END IF
LOOP
1 IF et = 1 THEN CALL StartProgram
IF et = 2 THEN CALL GetHelp
IF et = 3 THEN Quit
END SUB

CLS : SCREEN 13
CenterText "Word Guessing", 0
CenterText " ", 7
CenterText "Start Program", 1
CenterText "Get Help", 1
CenterText "Quit", 1
EXIT SUB
END SUB

SUB Quit
CLS : SCREEN 0
CenterText "Thank You for playing!", 0
CenterText "Word Guessing", 0
CenterText "Ver. 0.1", 1
CenterText "Programmer: Julio Cruz", 0
CenterText "P.S: Coming soon: Ver. 1.0", 0
END
END SUB

SUB StartProgram
CLS : SCREEN 13
FOR i = 1 TO 19
PRINT " ";
NEXT i
tries = 9: PRINT "Tries: "; tries
t\$ = "QBasic": y = LEN(t\$)
CenterText " ", 10
FOR i = 1 TO y
PRINT "_ ";
NEXT i
k\$ = INKEY\$
FOR i = 1 TO LEN(t\$)
IF k\$ = CHR\$(ASC(MID\$(t\$, i, 1))) THEN
PRINT CHR\$(ASC(MID\$(t\$, i, 1)))
c = c + 1
END IF
IF k\$ <> CHR\$(ASC(MID\$(t\$, i, 1))) THEN
tries = tries - 1
PRINT k\$
END IF
NEXT i
DO
LOOP UNTIL INKEY\$ <> ""
END SUB

 Logged
drjulio2003
New Member

Posts: 9

 « Reply #7 on: December 18, 2003, 02:54:44 PM »

Code:
DECLARE SUB PrintMenu ()
DECLARE SUB Quit ()
DECLARE SUB StartProgram ()
DECLARE SUB GetHelp ()
DECLARE SUB CenterText (t\$, y)
DECLARE SUB keyboard (cube(), dark(), x, y, et)
DIM cube(1 TO 377)
DIM dark(1 TO 377)

CLS : SCREEN 13
DO
LINE (90, 79)-(99, 87), 0, BF
GET (90, 79)-(99, 87), dark
LINE (90, 79)-(99, 87), , B
GET (90, 79)-(99, 87), cube
x = 90: y = 79: et = 1
keyboard cube(), dark(), x, y, et
LOOP
END

SUB CenterText (t\$, y)
FOR i = 1 TO y
PRINT
NEXT i
x = (20 - INT(LEN(t\$) / 2))
PRINT TAB(x); t\$
END SUB

SUB GetHelp
CLS : SCREEN 13
CenterText "Word Guessing", 2
CenterText "The game is very simple:", 1
CenterText "guess the word. The game will give", 1
CenterText "you a clud, by having a significately ", 1
CenterText "number of lines represented by how many ", 1
CenterText "letters their are in the word. You'll", 1
CenterText "have 9 tries, after that is game over. ", 1
CenterText "Use the keyboard to guess the word.", 1
CenterText "Press any key to continue", 5
DO
LOOP UNTIL INKEY\$ <> ""
END SUB

SUB keyboard (cube(), dark(), x, y, et)
DO
k\$ = INKEY\$
IF k\$ = CHR\$(0) + CHR\$(72) THEN
xold = x: yold = y
PUT (j, k), dark, PSET
x = x - 15: y = y - 16
j = j - 15: k = k - 16
et = et - 1
PUT (xold, yold), cube, PSET
IF x <= 85 THEN
x = xold: y = yold
END IF
IF et <= 0 THEN
et = 1
END IF
END IF
IF k\$ = CHR\$(13) THEN
GOTO 1
END IF
IF k\$ = CHR\$(0) + CHR\$(80) THEN
et = et + 1
xold = x: yold = y
x = x + 15: y = y + 16
PUT (x, y), cube, PSET
PUT (xold, yold), dark, PSET
j = 120: k = 111
IF x >= 120 THEN
x = xold: y = yold
END IF
IF et > 3 THEN
et = 3
END IF
END IF
LOOP
1 IF et = 1 THEN CALL StartProgram
IF et = 2 THEN CALL GetHelp
IF et = 3 THEN Quit
END SUB

CLS : SCREEN 13
CenterText "Word Guessing", 0
CenterText " ", 7
CenterText "Start Program", 1
CenterText "Get Help", 1
CenterText "Quit", 1
EXIT SUB
END SUB

SUB Quit
CLS : SCREEN 0
CenterText "Thank You for playing!", 0
CenterText "Word Guessing", 0
CenterText "Ver. 0.1", 1
CenterText "Programmer: Julio Cruz", 0
CenterText "P.S: Coming soon: Ver. 1.0", 0
END
END SUB

SUB StartProgram
CLS : SCREEN 13
FOR i = 1 TO 19
PRINT " ";
NEXT i
tries = 9: PRINT "Tries: "; tries
t\$ = "QBasic": y = LEN(t\$)
CenterText " ", 10
FOR i = 1 TO y
PRINT "_ ";
NEXT i
k\$ = INKEY\$
FOR i = 1 TO LEN(t\$)
IF k\$ = CHR\$(ASC(MID\$(t\$, i, 1))) THEN
PRINT CHR\$(ASC(MID\$(t\$, i, 1)))
c = c + 1
END IF
IF k\$ <> CHR\$(ASC(MID\$(t\$, i, 1))) THEN
tries = tries - 1
PRINT k\$
END IF
NEXT i
DO
LOOP UNTIL INKEY\$ <> ""
END SUB

 Logged
drjulio2003
New Member

Posts: 9

 « Reply #8 on: December 18, 2003, 05:46:49 PM »

Code:
[img]
http://www.gamespy.com/e32002/pc/carmack/carmack-s.jpg
DECLARE SUB PrintMenu ()
DECLARE SUB Quit ()
DECLARE SUB StartProgram ()
DECLARE SUB GetHelp ()
DECLARE SUB CenterText (t\$, y)
DECLARE SUB keyboard (cube(), dark(), x, y, et)
DIM cube(1 TO 377)
DIM dark(1 TO 377)

CLS : SCREEN 13
DO
LINE (90, 79)-(99, 87), 0, BF
GET (90, 79)-(99, 87), dark
LINE (90, 79)-(99, 87), , B
GET (90, 79)-(99, 87), cube
x = 90: y = 79: et = 1
keyboard cube(), dark(), x, y, et
LOOP
END

SUB CenterText (t\$, y)
FOR i = 1 TO y
PRINT
NEXT i
x = (20 - INT(LEN(t\$) / 2))
PRINT TAB(x); t\$
END SUB

SUB GetHelp
CLS : SCREEN 13
CenterText "Word Guessing", 2
CenterText "The game is very simple:", 1
CenterText "guess the word. The game will give", 1
CenterText "you a clud, by having a significately ", 1
CenterText "number of lines represented by how many ", 1
CenterText "letters their are in the word. You'll", 1
CenterText "have 9 tries, after that is game over. ", 1
CenterText "Use the keyboard to guess the word.", 1
CenterText "Press any key to continue", 5
DO
LOOP UNTIL INKEY\$ <> ""
END SUB

SUB keyboard (cube(), dark(), x, y, et)
xold = x
yold = y
DO
k\$ = INKEY\$
IF k\$ = CHR\$(0) + CHR\$(72) THEN
IF x <= 85 THEN
x = xold: y = yold
END IF
IF et > 1 THEN
x = x - 15: y = y - 16
et = et - 1
PUT (x, y), cube, PSET
PUT (xold, yold), dark, PSET
xold = x: yold = y
END IF
END IF
IF k\$ = CHR\$(0) + CHR\$(80) THEN
IF x >= 120 THEN
x = xold: y = yold
END IF
IF et < 3 THEN
et = et + 1
x = x + 15: y = y + 16
PUT (x, y), cube, PSET
PUT (xold, yold), dark, PSET
xold = x: yold = y
END IF
END IF
LOOP UNTIL k\$ = CHR\$(13)

1 IF et = 1 THEN CALL StartProgram
IF et = 2 THEN CALL GetHelp
IF et = 3 THEN Quit
END SUB

CLS : SCREEN 13
CenterText "Word Guessing", 0
CenterText " ", 7
CenterText "Start Program", 1
CenterText "Get Help", 1
CenterText "Quit", 1
EXIT SUB
END SUB

SUB Quit
CLS : SCREEN 0
CenterText "Thank You for playing!", 0
CenterText "Word Guessing", 0
CenterText "Ver. 0.1", 1
CenterText "Programmer: DrJulio2003", 0
CenterText "Credit To: TheBigBasicQ", 0
CenterText "P.S: Coming soon: Ver. 1.0", 0
END
END SUB

SUB StartProgram
CLS : SCREEN 13
FOR i = 1 TO 19
PRINT " ";
NEXT i

tries = 9: PRINT "Tries: "; tries

t\$ = "QBasic": y = LEN(t\$)

CenterText " ", 10

FOR i = 1 TO y
PRINT "_ ";
NEXT i

DO
k\$ = INKEY\$
IF k\$ = CHR\$(0) + CHR\$(80) THEN
t = ASC(MID\$(t\$, i, 1))
PRINT t, CHR\$(t)
END IF
LOOP UNTIL k\$ = CHR\$(13)
END SUB
[/img]
 Logged
drjulio2003
New Member

Posts: 9

 « Reply #9 on: January 04, 2004, 09:10:15 PM »

Man, can you believe that I can't finish this simple program, but we did complete our objective which that is create a simple main menu that the user can use with there keyboard:

Code:
DECLARE SUB PrintMenu ()
DECLARE SUB Quit ()
DECLARE SUB StartProgram (tries, y, letters\$())
DECLARE SUB GetHelp ()
DECLARE SUB CenterText (t\$, y)
DECLARE SUB keyboard (cube(), dark(), x, y, et, letters\$())
DIM cube(1 TO 377)
DIM dark(1 TO 377)
DIM letters\$(1 TO 50)

CLS : SCREEN 13
DO
LINE (90, 79)-(99, 87), 0, BF
GET (90, 79)-(99, 87), dark
LINE (90, 79)-(99, 87), , B
GET (90, 79)-(99, 87), cube
x = 90: y = 79: et = 1
keyboard cube(), dark(), x, y, et, letters\$()
LOOP
END

SUB CenterText (t\$, y)
FOR I = 1 TO y
PRINT
NEXT I
x = (20 - INT(LEN(t\$) / 2))
PRINT TAB(x); t\$
END SUB

SUB GetHelp
CLS : SCREEN 13
CenterText "Word Guessing", 2
CenterText "The game is very simple:", 1
CenterText "guess the word. The game will give", 1
CenterText "you a clud, by having a significately ", 1
CenterText "number of lines represented by how many ", 1
CenterText "letters their are in the word. You'll", 1
CenterText "have 9 tries, after that is game over. ", 1
CenterText "Use the keyboard to guess the word.", 1
CenterText "Press any key to continue", 5
DO
LOOP UNTIL INKEY\$ <> ""
END SUB

SUB keyboard (cube(), dark(), x, y, et, letters\$())
xold = x
yold = y
tries = 9
DO
k\$ = INKEY\$
IF k\$ = CHR\$(0) + CHR\$(72) THEN
IF x <= 85 THEN
x = xold: y = yold
END IF
IF et > 1 THEN
x = x - 15: y = y - 16
et = et - 1
PUT (x, y), cube, PSET
PUT (xold, yold), dark, PSET
xold = x: yold = y
END IF
END IF
IF k\$ = CHR\$(0) + CHR\$(80) THEN
IF x >= 120 THEN
x = xold: y = yold
END IF
IF et < 3 THEN
et = et + 1
x = x + 15: y = y + 16
PUT (x, y), cube, PSET
PUT (xold, yold), dark, PSET
xold = x: yold = y
END IF
END IF
LOOP UNTIL k\$ = CHR\$(13)

1 IF et = 1 THEN CALL StartProgram(tries, y, letters\$())
IF et = 2 THEN CALL GetHelp
IF et = 3 THEN Quit
END SUB

CLS : SCREEN 13
CenterText "Word Guessing", 0
CenterText " ", 7
CenterText "Start Program", 1
CenterText "Get Help", 1
CenterText "Quit", 1
EXIT SUB
END SUB

SUB Quit
CLS : SCREEN 0
CenterText "Thank You for playing!", 0
CenterText "Word Guessing", 0
CenterText "Ver. 0.1", 1
CenterText "Programmer: DrJulio2003", 0
CenterText "Credit To: TheBigBasicQ", 0
CenterText "P.S: Coming soon: Ver. 1.0", 0
END
END SUB

SUB StartProgram (tries, y, letter\$())
RANDOMIZE TIMER
DIM wlenth(1 TO 50)
DIM word\$(1 TO 10)

CLS : SCREEN 13
word\$(1) = "board"
word\$(2) = "globe"
word\$(3) = "touch"
word\$(4) = "building"
word\$(5) = "eleminate"
word\$(6) = "elevator"
word\$(7) = "investigator"
word\$(8) = "alagator"
word\$(9) = "eagle"
word\$(10) = "bird"

FOR I = 1 TO 30
PRINT " ";
NEXT I
PRINT "Tries:"; tries
high = 10
low = 1
t = INT(RND * (high - low + 1) + low)
PRINT t
n = LEN(word\$(t))
FOR I = 1 TO n
PRINT "_ ";
NEXT I
CenterText " ", 11
END SUB

 Logged
TheBigBasicQ
*/-\*

Posts: 4550

 « Reply #10 on: January 05, 2004, 03:52:16 PM »

Why do you keep posting the code?
 Logged
KiZ
__/--\__

Posts: 2879

 « Reply #11 on: January 05, 2004, 04:00:30 PM »

Yea, would you mind maybe hosting the updated files elsewhere, then linking to them next time please. Large Code posts like that take up room on the server.
 Logged
TheBigBasicQ
*/-\*

Posts: 4550

 « Reply #12 on: January 05, 2004, 04:02:53 PM »

Server space isnt much of a concern. It is very annoying to read a tiny post with such a huge amount of code attached to it  ::
 Logged
KiZ
__/--\__

Posts: 2879

 « Reply #13 on: January 05, 2004, 04:16:04 PM »

Fair enough, but it would be a lot easier than scrolling down through 10s of pages of code, yes? =D
 Logged
TheBigBasicQ
*/-\*

Posts: 4550

 « Reply #14 on: January 05, 2004, 04:19:11 PM »

You're picking up my style =D
 Logged
 Pages: [1] 2 3