Qbasicnews.com

Full Version: Some more help with Hangman
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Alright, I'm having more trouble with my hangman project. First, run this program:

Quote:'Hangman File Creator
'Creates "states.txt", "prog.txt", and "foods.txt"

CLS

OPEN "p4\states.txt" FOR OUTPUT AS #1

FOR x = 1 TO 10

READ s$

WRITE #1, s$

PRINT s$

NEXT x

CLOSE #1

OPEN "p4\prog.txt" FOR OUTPUT AS #1

FOR x = 1 TO 10

READ s$

WRITE #1, s$

PRINT s$

NEXT x

CLOSE #1

OPEN "p4\foods.txt" FOR OUTPUT AS #1

FOR x = 1 TO 10

READ s$

WRITE #1, s$

PRINT s$

NEXT x

CLOSE #1

OPEN "p4\categor.txt" FOR OUTPUT AS #1

FOR x = 1 TO 3

READ s$

WRITE #1, s$

NEXT x

CLOSE #1

DATA states, Washington, Oregon, Maine, Maryland, Delaware, Vermont, Virginia, Florida, Pennsylvania
DATA prog, Sub, Function, Input, Print, Do, Loop, For, Next, End
DATA foods, Cereal, Pizza, Burger, Fries, Fruits, Vegetables, Bread, Cheese, Fish
DATA states, prog, foods

That was just to create my data files (which you'll need to run my game). Here's my actual game:

Quote:DECLARE SUB dead ()
DECLARE SUB legs ()
DECLARE SUB bottom ()
DECLARE SUB pole ()
DECLARE SUB top ()
DECLARE SUB noose ()
DECLARE SUB head ()
DECLARE SUB torso ()
DECLARE SUB arms ()
DECLARE SUB eyes ()
DECLARE SUB statescategory ()
DECLARE SUB progcategory ()
DECLARE SUB foodscategory ()
DECLARE SUB game ()
DECLARE SUB choose ()
DECLARE SUB create ()
DECLARE SUB edit ()
DECLARE SUB menu ()

COMMON SHARED nc
DIM SHARED category AS STRING
DIM SHARED wordlist(10) AS STRING 'creates wordlist (string) without boundary, all subs recognize it
DIM SHARED guess AS STRING 'creates guess (string) without boundary, all subs recognize it
DIM SHARED letter(26) 'dims entire alphabet, all subs recognize it
DIM SHARED tries AS INTEGER 'creates tries (number) without boundary, all subs recognize it
DIM SHARED found AS INTEGER 'creates found (number) without boundary, all subs recognize it
CLS
menu
DO
a$ = INPUT$(1)
SELECT CASE a$
CASE "1"

choose

CASE "2"

create

CASE "3"



CASE "4"

CLS
PRINT "Goodbye"


END SELECT
LOOP UNTIL a$ = "4"

SUB arms

'Creates arms
FOR x = 42 TO 47
LOCATE 25, x
PRINT CHR$(219)
NEXT x

FOR x = 47 TO 52
LOCATE 25, x
PRINT CHR$(219)
NEXT x

END SUB

SUB bottom

'Creates bottom of gallows
FOR x = 45 TO 78
LOCATE 42, x
PRINT CHR$(219)
NEXT x

END SUB

SUB choose

CLS

LOCATE 10, 28: PRINT "Select one of the categories:"

LOCATE 12, 25
PRINT "================================"

LOCATE 14, 25
PRINT "1) Category 1"

LOCATE 16, 25
PRINT "2) Category 2"

LOCATE 18, 25
PRINT "3) Category 3"

LOCATE 20, 25
PRINT "4) Return to Main Menu"

LOCATE 22, 25
PRINT "================================"


a$ = INPUT$(1)
SELECT CASE a$

CASE "1"

OPEN "p4\categor.txt" FOR INPUT AS #1
DO WHILE NOT EOF(1)
x = 1
INPUT #1, wordlist(x)
LOOP
CLOSE #1

OPEN "p4\" + wordlist(x) + ".txt" FOR INPUT AS #1
DO WHILE NOT EOF(1)
x = x + 1
INPUT #1, wordlist(x)
LOOP
nc = x
CLOSE #1

game

CASE "2"

OPEN "p4\categor.txt" FOR INPUT AS #1
DO WHILE NOT EOF(1)
x = 2
INPUT #1, wordlist(x)
LOOP
CLOSE #1

OPEN "p4\" + wordlist(x) + ".txt" FOR INPUT AS #1
DO WHILE NOT EOF(1)
x = x + 1
INPUT #1, wordlist(x)
LOOP
nc = x
CLOSE #1

game


CASE "3"

OPEN "p4\categor.txt" FOR INPUT AS #1
DO WHILE NOT EOF(1)
x = 3
INPUT #1, wordlist(x)
LOOP
CLOSE #1

OPEN "p4\" + wordlist(x) + ".txt" FOR INPUT AS #1
DO WHILE NOT EOF(1)
x = x + 1
INPUT #1, wordlist(x)
LOOP
nc = x
CLOSE #1

game


CASE "4"
CLS
menu

END SELECT




END SUB

SUB create

CLS

OPEN "p4\categor.txt" FOR APPEND AS #1

INPUT "Please enter the name of the new category"; new.cat$
new.cat$ = UCASE$(new.cat$)
WRITE #1, new.cat$
CLOSE #1


OPEN "p4\" + new.cat$ + ".txt" FOR OUTPUT AS #1
DO
INPUT "Enter a word (only words, no spaces)"; b$
WRITE #1, b$
INPUT "Enter again? (y/n)"; an$

LOOP UNTIL an$ = "n" OR an$ = "N"
CLOSE #1

OPEN "p4\" + new.cat$ + ".txt" FOR INPUT AS #1
DO WHILE NOT EOF(1)
x = x + 1
INPUT #1, wordlist(x)
LOOP

nc = x
CLOSE #1

CLS
game

END SUB

SUB dead

'Creates eyes
LOCATE 19, 46: PRINT "X"
LOCATE 19, 48: PRINT "X"

END SUB

SUB eyes

'Creates eyes
LOCATE 19, 46: PRINT CHR$(248)
LOCATE 19, 48: PRINT CHR$(248)

END SUB

SUB foodscategory

OPEN "p4\foods.txt" FOR INPUT AS #1
DO WHILE NOT EOF(1)
x = x + 1
INPUT #1, wordlist(x)
LOOP
nc = x
CLOSE #1

END SUB

SUB game

CLS

f = 0
t = -1
row = 26
column = 10

DO
RANDOMIZE TIMER
guess = wordlist(INT(RND * nc) + 1)
tries = 0
FOR x = 1 TO 26
letter(x) = 0
NEXT x
CLS
LOCATE 3, 10: PRINT "Find the missing word."
LOCATE 6, 10
FOR x = 1 TO LEN(guess)
PRINT "-";
NEXT x
LOCATE 15, 10: PRINT "You have 10 chances."
c = 0
LOCATE 25, 10
PRINT "Used letters:"
DO
found = f
DO
a$ = INKEY$
LOOP UNTIL a$ <> ""
a$ = UCASE$(a$)

SELECT CASE a$
CASE "A" TO "Z"
IF letter(ASC(a$) - 64) = 0 THEN
FOR x = 1 TO LEN(guess)
LOCATE 5, 9 + x
IF UCASE$(MID$(guess, x, 1)) = a$ THEN
PRINT MID$(guess, x, 1)
c = c + 1
found = t
END IF
NEXT x
IF found = f THEN
LOCATE row, column
PRINT LCASE$(a$)
row = row + 1
tries = tries + 1
LOCATE 15, 10
PRINT "You have only"; (10 - tries); "chances."

IF tries = 1 THEN
bottom
ELSEIF tries = 2 THEN
pole
ELSEIF tries = 3 THEN
top
ELSEIF tries = 4 THEN
noose
ELSEIF tries = 5 THEN
head
ELSEIF tries = 6 THEN
torso
ELSEIF tries = 7 THEN
arms
ELSEIF tries = 8 THEN
legs
ELSEIF tries = 9 THEN
eyes
ELSEIF tries = 10 THEN
dead
END IF

END IF
letter(ASC(a$) - 64) = -1
END IF
END SELECT

LOOP UNTIL c = LEN(guess) OR tries = 10
IF c = LEN(guess) THEN
LOCATE 8, 10
PRINT "You won."
ELSE
LOCATE 8, 10
PRINT "You lost."
END IF
LOCATE 9, 10
PRINT "Do you want to play again? (y/n)";
DO
a$ = INKEY$
LOOP UNTIL a$ = "y" OR a$ = "n"
row = 26
column = 10
LOOP UNTIL a$ = "n"
IF a$ = "n" THEN
CLS
menu
END IF

END SUB

SUB head

'Creates left side of head
FOR x = 17 TO 22
LOCATE x, 44
PRINT CHR$(219)
NEXT x

'Creates right side of head
FOR x = 17 TO 22
LOCATE x, 50
PRINT CHR$(219)
NEXT x

'Creates top of head
FOR x = 44 TO 50
LOCATE 17, x
PRINT CHR$(219)
NEXT x

'Creates bottom of head
FOR x = 44 TO 50
LOCATE 22, x
PRINT CHR$(219)
NEXT x

END SUB

SUB legs

'Creates waist
FOR x = 43 TO 51
LOCATE 30, x
PRINT CHR$(219)
NEXT x

'Creates left leg
FOR x = 30 TO 34
LOCATE x, 43
PRINT CHR$(219)
NEXT x

'Creates right leg
FOR x = 30 TO 34
LOCATE x, 51
PRINT CHR$(219)
NEXT x

END SUB

SUB menu

LOCATE 10, 28: PRINT "Welcome to Hangman!"

LOCATE 12, 25
PRINT "================================"

LOCATE 14, 25
PRINT "1) Choose Category"

LOCATE 16, 25
PRINT "2) Create New Category"

LOCATE 18, 25
PRINT "3) Append Existing Category"

LOCATE 20, 25
PRINT "4) Quit"

LOCATE 22, 25
PRINT "================================"


END SUB

SUB noose

'Creates noose of gallows
FOR x = 10 TO 16
LOCATE x, 47
PRINT CHR$(219)
NEXT x

END SUB

SUB pole

'Creates "pole" of gallows
FOR x = 10 TO 41
LOCATE x, 65
PRINT CHR$(219)
NEXT x

END SUB

SUB progcategory

OPEN "p4\prog.txt" FOR INPUT AS #1
DO WHILE NOT EOF(1)
x = x + 1
INPUT #1, wordlist(x)
LOOP
nc = x
CLOSE #1

END SUB

SUB statescategory

OPEN "p4\states.txt" FOR INPUT AS #1
DO WHILE NOT EOF(1)
x = x + 1
INPUT #1, wordlist(x)
LOOP
nc = x
CLOSE #1

END SUB

SUB top

'Creates top of gallows
FOR x = 47 TO 64
LOCATE 10, x
PRINT CHR$(219)
NEXT x

END SUB

SUB torso

'Creates torso
FOR x = 23 TO 30
LOCATE x, 47
PRINT CHR$(219)
NEXT x

END SUB

Alright, now here's my problem. Whenever I run choice 1 (which selects a category from the p4 folder, and then uses the words for my hangman game) my game only gets one word: foods. No matter which category you pick, and no matter how many times you play, my game only reads the word "foods." And I don't know why. I mean, the coding looks right. I don't know what I should be fixing.

Can anyone help me, please?
So can somebody please help me?