Hello again fellow gamers.
Well I finished another program and I seem to have typed it in correctly without any spelling errors, however when I finish the game and the program goes to record the high score (# of attempts at guessing number), it doesn't create the HIGHSCORE.DAT file and thus causes the program to exit prematurely. If someone can tell me why the file isn't being written, that would be great.
Rem Project: GuessingGame Progject
Rem Created: Thursday, March 29, 2012
Rem Designer: Andrew D. South
Rem ***** Main Source File *****
DIM highname$(20)
DIM hightries(20)
playing = 1
SYNC RATE 30
SYNC ON
SET TEXT TRANSPARENT
WHILE playing = 1
DISPLAYTITLE()
PLAYGAME()
playing = PLAYAGAIN()
ENDWHILE
END
`This function displays the title page for the game
FUNCTION DISPLAYTITLE()
red = rgb(255,0,0)
white = rgb(255,255,255)
black = rgb(0,0,0)
INK white, red
CENTER TEXT 320,10, "Guess My Number"
INK white, black
CENTER TEXT 320,400, "Press Any Key to Continue"
SYNC
DISPLAYHIGHSCORES()
counter = 1
WHILE INKEY$() = ""
SYNC
ENDWHILE
ENDFUNCTION
`This plays main game
FUNCTION PLAYGAME()
mynumber = RND(1000)
yournumber = -1
tries = 0
tempstring$ = ""
WHILE yournumber <> mynumber
tries = tries + 1
CLS
CENTER TEXT 320,10,"I have picked a number between 1 and 1000"
CENTER TEXT 320,22,"You have to guess. I will help you!"
TEXT 10,420,tempstring$
SYNC
SET CURSOR 10,400
PRINT "What is your Number? ";
INPUT yournumber
SYNC
IF yournumber > mynumber
tempstring$ = "My Number is less then that number! (Lower)"
ENDIF
IF yournumber < mynumber
tempstring$ = "My Number is greater then that number! (Higher)"
ENDIF
IF yournumber = mynumber
tempstring$ = "You are correct. Way to go"
ENDIF
IF tries = 5 THEN WRITE TO CLIPBOARD STR$(mynumber)
ENDWHILE
CLS
CENTER TEXT 320,10, "I have picked a number between 1 and 1000"
CENTER TEXT 320,22, "You have to guess. I will help you!"
TEXT 10,420, tempstring$
SYNC
SYNC
SLEEP 1000
highscore = CHECKHIGHSCORE(name$,tires)
IF highscore
CLS
CENTER TEXT 320,10, "Congratulations, you have made it into the high scores"
SET CURSOR 10,400
SYNC
INPUT "What is your name? ",name$
ENTERHIGHSCORE(name$,tries)
ENDIF
ENDFUNCTION
`This checks to see if the player
`want's to play again
FUNCTION PLAYAGAIN()
flag = 0
CLS
CENTER TEXT 320,240,"Would you like to play again? Y\N"
SYNC
answer$ = askyesno$()
IF answer$ = "YES" THEN flag = 1
CLS
SYNC
ENDFUNCTION flag
`This function displays the highscores
FUNCTION DISPLAYHIGHSCORES()
CENTER TEXT 320,30,"High Scores"
CENTER TEXT 160,50,"Names"
CENTER TEXT 480,50,"Tries"
CENTER TEXT 160,68,"____"
CENTER TEXT 480,68,"____"
IF FILE EXIST("HIGHSCORE.DAT") = 0 THEN EXITFUNCTION
OPEN TO READ 1, "HIGHSCORE.DAT"
ypos = 80
FOR x = 1 TO 20
READ STRING 1, name$
READ LONG 1, tries
IF tries <> 0
CENTER TEXT 160,ypos,name$
CENTER TEXT 480,ypos,STR$(tries)
ENDIF
ypos = ypos + 12
NEXT X
CLOSE FILE 1
ENDFUNCTION
`This function records a new highscore
FUNCTION ENTERHIGHSCORE(name$,tries)
IF FILE EXIST("HIGHSCORE.DAT") = 0
OPEN TO WRITE 1,"HIGHSCORE.DAT"
WRITE STRING 1, LEFT$(name$,20)
WRITE LONG 1,tries
FOR X = 2 TO 20
WRITE STRING 1," "
WRITE LONG 1,0
NEXT X
CLOSE FILE 1
EXITFUNCTION
ENDIF
OPEN TO READ 1,"HIGHSCORE.DAT"
FOR X = 1 TO 20
READ STRING 1,a$
highname$(X) = a$
READ LONG 1, a
hightries(X) = a
NEXT X
CLOSE FILE 1
strtoplace$ = name$
numtoplace = tries
FOR X = 1 TO 20
IF hightries(X) >= numtoplace OR hightries(X) = 0
tempstr$ = highname$(X)
tempnum = hightries(X)
highname$(X) = strtoplace$
hightries(X) = numtoplace
strtoplace$ = tempstr$
numtoplace = tempnum
ENDIF
NEXT X
DELETE FILE "HIGHSCORE.DAT"
OPEN TO WRITE 1, "HIGHSCORE.DAT"
FOR X = 1 TO 20
WRITE STRING 1, highname$(X)
WRITE LONG 1, hightries(X)
NEXT X
CLOSE FILE 1
ENDFUNCTION
`This function checks to see if a highscore
`qualifies.
FUNCTION CHECKHIGHSCORE(name$,tries)
IF FILE EXIST("HIGHSCORE.DAT") = 1
EXITFUNCTION 1
ENDIF
OPEN TO READ 1,"HIGHSCORE.DAT"
FOR X = 1 TO 20
READ STRING 1,a$
highname$(X) = a$
READ LONG 1, a
hightries(X) = a
NEXT X
CLOSE FILE 1
flag = 0
FOR X = 1 TO 20
IF hightries(X) >= tries OR hightries(x) = 0
flag = 1
ENDIF
NEXT X
ENDFUNCTION flag
`This waits for a Y/N key
FUNCTION ASKYESNO$
ch$ = UPPER$(INKEY$())
WHILE ch$ <> "Y" AND ch$ <> "N"
ch$ = UPPER$(INKEY$())
SYNC
ENDWHILE
IF ch$ = "Y" then Ret$ = "YES"
IF ch$ = "N" then Ret$ = "NO"
WHILE ch$ = "Y" OR ch$ = "N"
ch$ = UPPER$(INKEY$())
SYNC
ENDWHILE
ENDFUNCTION Ret$
When we all lend our power together, there is nothing we
can't do!
Please Lend me your STRENGTH!