Qbasicnews.com
September 20, 2020, 08:02:29 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: re-assign arrays  (Read 2758 times)
captain_squirrely
New Member

Posts: 18


« on: July 31, 2004, 05:58:23 PM »

I'm making a cheasy hang man game and i wanted to clean up the code...I've made arrays for the word and the blank word  the size of the array depends on the length of the word...do i have to have the use input the word BEFORE i can dim the array...or can I dim the array at 0  have them input the word then redim it in a Sub? I know that was an incredibly long run-on sentence but i don't care :bounce:
Logged
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #1 on: July 31, 2004, 06:02:12 PM »

can we see some code please? =D
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
captain_squirrely
New Member

Posts: 18


« Reply #2 on: July 31, 2004, 06:06:57 PM »

this is the current code that i tries to use the redim statement work


DECLARE SUB playhangman ()
DECLARE SUB checktries ()
DECLARE SUB showtries ()
DECLARE SUB capturekeymainloop ()
DECLARE SUB enablecountdown ()
DECLARE SUB letterhelp ()
DECLARE SUB checkalphabet ()
DECLARE SUB showalphabet ()
DECLARE SUB createalphabetarray ()
DECLARE SUB timermove ()
DECLARE SUB initiatetimer ()
DECLARE SUB checkletter ()
DECLARE SUB checkwordsolved ()
DECLARE SUB createcopywordarray ()
DECLARE SUB showsolved ()
DECLARE SUB errorcheck ()
DECLARE SUB createwordarray ()

DIM SHARED alphabet$(0)
DIM SHARED wrd$(0)
DIM SHARED subwrd$(0)


COMMON SHARED starttime!, word$, letter$, alpha$, tries, enabled, wordlength, lcheck, timerbar, timerspeed, cheat

CLS

SCREEN 13

tries = 6
enabled = -1

enablecountdown

playhangman

CLS

PRINT "THE WORD WAS "; UCASE$(word$)

IF cheat = 1 THEN
        PRINT "CHEATER"
END IF

DATA a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,-,-,z,-,-

REM $STATIC
SUB capturekeymainloop

DO

currenttime! = TIMER

LOCATE 2, 1: PRINT "LETTER"

LOCATE 3, 1: PRINT "SECONDS"; INT(currenttime! - starttime!)

letter$ = INKEY$

IF letter$ = "1" THEN
        letterhelp
END IF

IF letter$ = "0" THEN
        letterhelp
        cheat = 0
END IF

IF enabled = 0 THEN
        timermove
END IF

WAIT &H3DA, 12

LOOP UNTIL letter$ <> "" OR timerbar = timerspeed


END SUB

SUB checkalphabet

FOR x = 0 TO 29
        IF alphabet$(x) = letter$ THEN
                alphabet$(x) = "-"
        END IF

NEXT x

END SUB

SUB checkletter

r = 0

FOR x = 0 TO LEN(word$) - 1
        IF letter$ = wrd$(r) THEN
                subwrd$(r) = wrd$(r)
                lcheck = 1
        END IF
        r = r + 1
NEXT x


END SUB

SUB checktimerou
END SUB

SUB checktries

IF lcheck = 0 OR cheat = 1 THEN
        tries = tries - 1
END IF


END SUB

SUB checkwordsolved

wordlength = 0

FOR z = 0 TO LEN(word$) - 1
        IF wrd$(y) = subwrd$(y) THEN
                wordlength = wordlength + 1
        END IF
        y = y + 1
NEXT z

END SUB

SUB createalphabetarray

x = 0

FOR i = 0 TO 29
        READ alpha$
        alphabet$(x) = alpha$
        x = x + 1
NEXT i

END SUB

DEFSNG A-Z
SUB createcopywordarray

x = 0
y = 0

FOR x = 0 TO LEN(word$) - 1
        subwrd$(y) = "-"
        y = y + 1
NEXT x

END SUB

SUB createwordarray

ltr$ = ""
x = 1
y = 0

FOR i = 0 TO LEN(word$) - 1
        ltr$ = MID$(word$, x, 1)
        x = x + 1
        wrd$(y) = ltr$
        y = y + 1
NEXT i

END SUB

DEFINT A-Z
SUB enablecountdown

DO

LOCATE 1, 1: PRINT "WOULD YOU LIKE INDIVIDUAL LETTER COUNT"
LOCATE 2, 1: PRINT "DOWN ENABLED?"

press$ = INKEY$

IF press$ = "n" THEN
        enabled = -1
ELSEIF press$ = "y" THEN
        enabled = 0
END IF

LOOP UNTIL press$ = "n" OR press$ = "y"


END SUB

SUB initiatetimer

timerbar = 20

LINE (20, 100)-(timerspeed, 105), 4, BF

END SUB

SUB letterhelp
RANDOMIZE TIMER

x = 0

DO
        randomletter = INT(RND * LEN(word$))
        IF subwrd$(randomletter) = "-" THEN
                letter$ = wrd$(randomletter)
                cheat = 1
                x = 1
        END IF
LOOP UNTIL x = 1
END SUB

SUB playhangman

DO

CLS

INPUT "WORD:", word$

LOOP UNTIL LEN(word$) > 0

word$ = LCASE$(word$)

ERASE alphabet$
DIM alphabet$(0 TO 29)
REDIM wrd$(0 TO LEN(word$) - 1)
REDIM subwrd$(0 TO LEN(word$) - 1)

createwordarray
createcopywordarray
createalphabetarray
cheat = 0

starttime! = TIMER

CLS

DO

lcheck = 0

showsolved
showalphabet
showtries


inputl:

timerspeed = 150

IF enabled = 0 THEN
        initiatetimer
END IF

capturekeymainloop

IF timebar = 190 THEN
        tries = tries - 1
        GOTO inputl
END IF

checkletter
checkalphabet
checktries

checkwordsolved

LOOP UNTIL (tries = 0 OR wordlength = LEN(word$))


END SUB

SUB showalphabet

z = 0
q = 6
n = 0

FOR x = 0 TO 5
        FOR y = 0 TO 4
                LOCATE (q), (n + 2): PRINT alphabet$(z)
                z = z + 1
                n = n + 2
        NEXT y
        q = q + 1
        n = 0
NEXT x

END SUB

DEFSNG A-Z
SUB showsolved

FOR x = 0 TO LEN(word$) - 1
        LOCATE 1, x + 1: PRINT UCASE$(subwrd$(y));
        y = y + 1
NEXT x

END SUB

DEFINT A-Z
SUB showtries

LOCATE 4, 1: PRINT "TRIES"; tries

END SUB

SUB timermove

LINE (20, 100)-(timerbar, 105), 5, BF

timerbar = timerbar + 1

END SUB
Logged
HQSneaker
Wandering Guru
***
Posts: 394



WWW
« Reply #3 on: July 31, 2004, 10:21:34 PM »

[syntax="qbasic"]DECLARE SUB playhangman ()
DECLARE SUB checktries ()
DECLARE SUB showtries ()
DECLARE SUB capturekeymainloop ()
DECLARE SUB enablecountdown ()
DECLARE SUB letterhelp ()
DECLARE SUB checkalphabet ()
DECLARE SUB showalphabet ()
DECLARE SUB createalphabetarray ()
DECLARE SUB timermove ()
DECLARE SUB initiatetimer ()
DECLARE SUB checkletter ()
DECLARE SUB checkwordsolved ()
DECLARE SUB createcopywordarray ()
DECLARE SUB showsolved ()
DECLARE SUB errorcheck ()
DECLARE SUB createwordarray ()

DIM SHARED alphabet$(0)
DIM SHARED wrd$(0)
DIM SHARED subwrd$(0)


COMMON SHARED starttime!, word$, letter$, alpha$, tries, enabled, wordlength, lcheck, timerbar, timerspeed, cheat

CLS

SCREEN 13

tries = 6
enabled = -1

enablecountdown

playhangman

CLS

PRINT "THE WORD WAS "; UCASE$(word$)

IF cheat = 1 THEN
PRINT "CHEATER"
END IF

DATA a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,-,-,z,-,-

REM $STATIC
SUB capturekeymainloop

DO

currenttime! = TIMER

LOCATE 2, 1: PRINT "LETTER"

LOCATE 3, 1: PRINT "SECONDS"; INT(currenttime! - starttime!)

letter$ = INKEY$

IF letter$ = "1" THEN
letterhelp
END IF

IF letter$ = "0" THEN
letterhelp
cheat = 0
END IF

IF enabled = 0 THEN
timermove
END IF

WAIT &H3DA, 12

LOOP UNTIL letter$ <> "" OR timerbar = timerspeed


END SUB

SUB checkalphabet

FOR x = 0 TO 29
IF alphabet$(x) = letter$ THEN
alphabet$(x) = "-"
END IF

NEXT x

END SUB

SUB checkletter

r = 0

FOR x = 0 TO LEN(word$) - 1
IF letter$ = wrd$(r) THEN
subwrd$(r) = wrd$(r)
lcheck = 1
END IF
r = r + 1
NEXT x


END SUB

SUB checktimerou
END SUB

SUB checktries

IF lcheck = 0 OR cheat = 1 THEN
tries = tries - 1
END IF


END SUB

SUB checkwordsolved

wordlength = 0

FOR z = 0 TO LEN(word$) - 1
IF wrd$(y) = subwrd$(y) THEN
wordlength = wordlength + 1
END IF
y = y + 1
NEXT z

END SUB

SUB createalphabetarray

x = 0

FOR i = 0 TO 29
READ alpha$
alphabet$(x) = alpha$
x = x + 1
NEXT i

END SUB

DEFSNG A-Z
SUB createcopywordarray

x = 0
y = 0

FOR x = 0 TO LEN(word$) - 1
subwrd$(y) = "-"
y = y + 1
NEXT x

END SUB

SUB createwordarray

ltr$ = ""
x = 1
y = 0

FOR i = 0 TO LEN(word$) - 1
ltr$ = MID$(word$, x, 1)
x = x + 1
wrd$(y) = ltr$
y = y + 1
NEXT i

END SUB

DEFINT A-Z
SUB enablecountdown

DO

LOCATE 1, 1: PRINT "WOULD YOU LIKE INDIVIDUAL LETTER COUNT"
LOCATE 2, 1: PRINT "DOWN ENABLED?"

press$ = INKEY$

IF press$ = "n" THEN
enabled = -1
ELSEIF press$ = "y" THEN
enabled = 0
END IF

LOOP UNTIL press$ = "n" OR press$ = "y"


END SUB

SUB initiatetimer

timerbar = 20

LINE (20, 100)-(timerspeed, 105), 4, BF

END SUB

SUB letterhelp
RANDOMIZE TIMER

x = 0

DO
randomletter = INT(RND * LEN(word$))
IF subwrd$(randomletter) = "-" THEN
letter$ = wrd$(randomletter)
cheat = 1
x = 1
END IF
LOOP UNTIL x = 1
END SUB

SUB playhangman

DO

CLS

INPUT "WORD:", word$

LOOP UNTIL LEN(word$) > 0

word$ = LCASE$(word$)

ERASE alphabet$
DIM alphabet$(0 TO 29)
REDIM wrd$(0 TO LEN(word$) - 1)
REDIM subwrd$(0 TO LEN(word$) - 1)

createwordarray
createcopywordarray
createalphabetarray
cheat = 0

starttime! = TIMER

CLS

DO

lcheck = 0

showsolved
showalphabet
showtries


inputl:

timerspeed = 150

IF enabled = 0 THEN
initiatetimer
END IF

capturekeymainloop

IF timebar = 190 THEN
tries = tries - 1
GOTO inputl
END IF

checkletter
checkalphabet
checktries

checkwordsolved

LOOP UNTIL (tries = 0 OR wordlength = LEN(word$))


END SUB

SUB showalphabet

z = 0
q = 6
n = 0

FOR x = 0 TO 5
FOR y = 0 TO 4
LOCATE (q), (n + 2): PRINT alphabet$(z)
z = z + 1
n = n + 2
NEXT y
q = q + 1
n = 0
NEXT x

END SUB

DEFSNG A-Z
SUB showsolved

FOR x = 0 TO LEN(word$) - 1
LOCATE 1, x + 1: PRINT UCASE$(subwrd$(y));
y = y + 1
NEXT x

END SUB

DEFINT A-Z
SUB showtries

LOCATE 4, 1: PRINT "TRIES"; tries

END SUB

SUB timermove

LINE (20, 100)-(timerbar, 105), 5, BF

timerbar = timerbar + 1

END SUB
[/syntax]
Logged
captain_squirrely
New Member

Posts: 18


« Reply #4 on: July 31, 2004, 10:50:50 PM »

Ohh...sorry. Well anyway I found the problem I didn't include

'$dynamic

I have no idea what it means or does...but whatever.

But I do have another question...does anybody have an idea how to include some graphics...not the line(x,y)-(x,y) stuff but the real background, foreground animated stuff. Thanx much!
Logged
Dr_Davenstein
Na_th_an
*****
Posts: 2052


« Reply #5 on: August 01, 2004, 01:14:43 AM »

You can use an array to store an image with GET,
Then you can display it using PUT.

Both of 'em are in QB help and there are all kinds of examples laying around on the 'net. Wink

Here's a link to one tutorial...
http://www.qbasicnews.com/tutorials.php?action=view&id=6
Logged
captain_squirrely
New Member

Posts: 18


« Reply #6 on: August 01, 2004, 10:03:51 PM »

What about a tutorial about loading graphics from an external file?
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!