Finally finished it...Hangman V.01by unseenmachine (no login)This is only v.01 so no bells and whistles yet... you will need a list of words in a file ina folder to run c:\qbtest\dictlist.lst the list needs to be single words all in uppercase i.e CAT EARTH PHONE COMPUTER etc.. you can have as many or as few words in the list as you like. Any feedback is much appreciated...i love making things better. code is >>>>>>>>>>>>>>>>>> REM hangman - v.01 SCREEN 12 CLS RANDOMIZE TIMER REM get username LOCATE 3, 5: INPUT "Enter your name : ", usrname$ REM draw letter grid CLS DIM lives AS INTEGER DIM usrscore AS INTEGER: usrscore = 0 DIM cnt AS INTEGER: cnt = 0 DIM tx AS INTEGER, ty AS INTEGER, ltrx AS INTEGER, ltry AS INTEGER tx = 20: ty = 450: ltrx = 28: ltry = 3 tile$ = "l9 h2 u18 e2 r18 f2 d18 g2 l9" DO PSET (tx, ty): DRAW tile$ LOCATE ltrx, ltry: PRINT CHR$(65 + cnt) tx = tx + 24: ltry = ltry + 3: cnt = cnt + 1 LOOP UNTIL cnt = 26 REM draw hangman box PSET (460, 400): DRAW "L110 h3 u360 e3 r220 f3 d360 g3 l110" REM draw word box, scores box, usrname box PSET (190, 73): DRAW "l100 h2 u30 e2 r200 f2 d30 g2 l100" LOCATE 4, 13: PRINT "Player : "; LEFT$(usrname$, 12) PSET (160, 120): DRAW "l70 h2 u30 e2 r140 f2 d30 g2 l70" PSET (190, 400): DRAW "l100 h2 u30 e2 r240 f2 d30 g2 l140" REM paint screen a nice green OUT &H3C8, 2: OUT &H3C9, 2: OUT &H3C9, 50: OUT &H3C9, 15 PAINT (1, 1), 2, 15 REM open dictionary and count entries DIM wrdcnt AS LONG OPEN "C:\qbtest\dictlist.lst" FOR INPUT AS #1 DO LINE INPUT #1, word$ wrdcnt = wrdcnt + 1 LOOP UNTIL EOF(1) CLOSE #1 REM master loop starts here DIM tcnt AS INTEGER DIM wrdcnt2 AS LONG, ltrcnt AS INTEGER, rndltr AS LONG DIM ltrflag(26) AS INTEGER DIM truecnt AS INTEGER, clry AS INTEGER DO REM paint all letters black cnt = 0: clry = 20 DO PAINT (clry, 447), 0, 15 clry = clry + 24 cnt = cnt + 1 LOOP UNTIL cnt = 26 LOCATE 7, 13: PRINT "Score : "; usrscore lives = 12: ltrcnt = 0: wrdcnt2 = 0: truecnt = 0 REM get a word from the dictionary DO rndltr = INT(RND * wrdcnt) + 1 CLOSE #1 OPEN "C:\qbtest\dictlist.lst" FOR INPUT AS #1 DO LINE INPUT #1, word$ wrdcnt2 = wrdcnt2 + 1 LOOP UNTIL wrdcnt2 = rndltr LOOP UNTIL LEN(word$) < 15 wordlen% = LEN(word$) REDIM wrdltr(wordlen%) AS STRING * 1 REM print spaces ltry = 13 DO wrdltr(ltrcnt) = "_" LOCATE 25, ltry: PRINT wrdltr(ltrcnt) ltry = ltry + 2: ltrcnt = ltrcnt + 1 LOOP UNTIL ltrcnt = wordlen% DO 'user input loop REM get user input DO kb$ = UCASE$(INKEY$) IF kb$ >= "A" AND kb$ <= "Z" THEN EXIT DO IF kb$ = CHR$(27) THEN SYSTEM LOOP REM figure out what letter was input tcnt = ASC(kb$) - 65 REM check if letter has allready been used or not IF ltrflag(tcnt) = 0 THEN REM PAINT LETTER RED FOR USED STATUS clry = 20 + (tcnt * 24) PAINT (clry, 447), 4, 15 REM compare letter against letters in word cnt = 0 oldtruecnt = truecnt DO IF MID$(word$, cnt + 1, 1) = kb$ THEN wrdltr(cnt) = kb$: truecnt = truecnt + 1 END IF cnt = cnt + 1 LOOP UNTIL cnt = LEN(word$) IF truecnt = oldtruecnt THEN lives = lives - 1 ltrflag(tcnt) = 1 END IF REM if you lost a life draw the next thing IF lives = 10 THEN LINE (360, 360)-(560, 370), 7, BF IF lives = 9 THEN LINE (360, 360)-(365, 100), 7, BF IF lives = 8 THEN LINE (360, 100)-(470, 105), 7, BF IF lives = 7 THEN LINE (360, 120)-(400, 100), 7 LINE (360, 130)-(410, 100), 7 PAINT (367, 125), 7, 7 END IF IF lives = 6 THEN LINE (470, 100)-(475, 130), 7, BF IF lives = 5 THEN CIRCLE (475, 150), 20, 15 IF lives = 4 THEN LINE (475, 170)-(475, 220), 15 IF lives = 3 THEN LINE (455, 185)-(495, 185), 15 IF lives = 2 THEN LINE (475, 220)-(485, 250), 15 IF lives = 1 THEN LINE (475, 220)-(465, 250), 15 IF lives = 0 THEN LINE (360, 398)-(560, 100), 0, BF cnt = 0 DO ltrflag(cnt) = 0 cnt = cnt + 1 LOOP UNTIL cnt = 26 truecnt = 0 EXIT DO END IF REM display new letters in missing word ltrcnt = 0: ltry = 13 DO LOCATE 25, ltry: PRINT wrdltr(ltrcnt) ltry = ltry + 2: ltrcnt = ltrcnt + 1 LOOP UNTIL ltrcnt = wordlen% REM check if all letters have been found IF truecnt = LEN(word$) THEN LINE (360, 398)-(560, 100), 0, BF cnt = 0 DO ltrflag(cnt) = 0 cnt = cnt + 1 LOOP UNTIL cnt = 26 truecnt = 0 SLEEP 4 usrscore = usrscore + (lives * wordlen%) EXIT DO END IF LOOP LOCATE 25, 13: PRINT SPACE$(28) LOOP 'master loop end |
| Response Title | Author and Date |
| Not bad -- couple of pointers... | on Feb 24 |
| *Posts about pointers and Makefiles should be in the C/C++ forum ;) | on Feb 24 |
| *lol -- I'll remember that for next time. | on Feb 24 |