I am very new to DarkBasic programming. I do have some experience with VB. I purchased the Beginner's Guide to DarkBasic Game Programming to guide me along the way. I am following the book and coded the Guessing Game the way they describe it in the book. The program works great except for the fact that no matter if you got a high score or not, it still tells you that you have made a high score. I have watched numerous videos and searched the forums and I just cannot quite figure it out. Any help would be appreciated!
Rem Project: GuessingGame
Rem Created: Sunday, February 05, 2012
Rem ***** Main Source File *****
'Name Wayne Archer
'Date 02/05/2012
'CIT 458
TitleScreen()
DIM HighName$(10)
Dim HighTries(10)
Playing = 1
Sync Rate 30
Sync On
Set Text Transparent
While Playing = 1
DisplayTitle()
PlayGame()
Playing = PlayAgain()
EndWhile
End
'This function displays the introductory screen
Function TitleScreen()
Set Text Size 48
Center Text 320, 170, "Guessing Game Program"
Set Text Size 32
Center Text 320, 220, "By: Wayne Archer"
Set Text Size 20
Center Text 320, 250, "February 5th, 2012"
Set Text Size 20
Center Text 320, 265, "Ver. 1.0.0.0"
Sleep 3000
Cls
Set Text Size 12
EndFunction
'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...if you can!"
Ink White, Black
Center Text 320,400, "Press Any Key to Continue"
Sync
DisplayHighScores()
Counter = 1
While Inkey$() = ""
Counter = Counter +1
Sync
EndWhile
Randomize Counter
While Inkey$() <> ""
Sync
EndWhile
EndFunction
'This plays the main game
Function PlayGame()
MyNumber = Rnd(5)
YourNumber = -1
Tries = 0
TempString$ = ""
While YourGuess <> MyNumber
Tries = Tries + 1
Cls
Center Text 320,10,"I have picked a number between 1 and infinity, err 1000."
Center text 320,22,"You have to guess, but I will help you because of your inferior intellect."
Text 10,420,TempString$
Sync
Set Cursor 10,400
Print "What is your guess? ";
Input YourGuess
Sync
If YourGuess > MyNumber
TempString$ = "Not even close! Guess a lower number."
EndIf
If YourGuess < MyNumber
TempString$ = "Nope! Guess a higher number."
EndIf
If YourGuess = MyNumber
TempString$ = "You are correct Sherlock. I think you got lucky!"
EndIf
EndWhile
Cls
Center Text 320,10,"I have picked a number between 1 and infinity, well maybe 1000."
Center text 320,22,"You have to guess, but I will help you because of your inferior intellect."
Text 10,420,TempString$
Sync
Sync
Sleep 2000
HighScore = CheckHighScore(Name$,Tries)
If HighScore
Cls
Center Text 320,10,"Congratulations, you have made it into the high scores"
Center Text 320,25,"You guessed in " + Str$(Tries) + " tries."
Set Cursor 10,400
Sync
Input "What is your name? ",Name$
EnterHighScore(Name$,Tries)
EndIf
EndFunction
'This checks to see of the player want's to play again
Function PlayAgain()
Flag = 0
Cls
Center Text 320,240,"Do you dare challenge me 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,"Top 10 Smartest of the Dumbest"
Center Text 320,45,"Second place is first loser!"
Center Text 160,68,"Names"
Center Text 480,68,"Tries"
Center Text 160,80,"----"
Center Text 480,80,"----"
If File Exist("HighScore.dat") = 0 Then ExitFunction
Open To Read 1, "HighScore.dat"
ypos = 90
For x = 1 To 10
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$,15)
Write Long 1,Tries
For X = 2 To 10
Write String 1," "
Write Long 1,0
Next X
Close File 1
ExitFunction
EndIf
Open To Read 1,"HighScore.dat"
For X = 1 To 10
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 10
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 10
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
Make File "HighScore.dat"
Open To Read 1,"HighScore.dat"
For X = 1 To 10
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 10
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$