I a newbie and I am working through the usual Pong game for a start. However, I would like to implement the high score feature in the game i.e. if the user presses the ESC key the high score list appears and asks for player's name in order to update the high score list if player's score is higher than the lowest value in the list and on a second press of the key the program ends. The problem is that I have used p_score for the player's score and there is the computer's score denoted by o_score that has to be overlooked if player is winning. Could anyone provide some detailed help as how to implement this feature? Code would be most welcome.
High Score for a Pong Game
Blitz3D Forums/Blitz3D Beginners Area/High Score for a Pong Game Maybe something like this?
*EDIT* saving and loading are left for you to implement yourself
*EDIT* saving and loading are left for you to implement yourself
Graphics 800,600,16,2 SetBuffer BackBuffer() Type HighScores ;Create a Type with two arrays to store the high scores Field Name$[9] Field Score%[9] End Type Type Player ;Create a player type to hold the player's details Field Name$ Field Score% Field ScorePosition% End Type Global CurrentPlayer.Player = New Player ;Create an instance of the Player type CurrentPlayer\Name$ = "" CurrentPlayer\Score% = 0 CurrentPlayer\ScorePosition% = -1 ; initialize it to a number lower than the table allows Global HighScoreTable.HighScores = New HighScores ;Create an instance of the highscore type LoadHighScores() CurrentPlayer\Score% = 50000 ;for test purposes, set to highest score ;BEGIN MAIN LOOP While Not KeyDown(1) ;Play the game Text 10,10,"game is running Wow! isn't it fun?!?! - press escape to quit" Flip Cls Wend ;END MAIN LOOP CurrentPlayer\ScorePosition%= GetScorePosition(CurrentPlayer\Score%) If CurrentPlayer\ScorePosition% > -1 Then ;if the score has a position on the board CurrentPlayer\Name$ = Input$("Congratulations! Enter Your Name: ") AddScore(CurrentPlayer\Score%, CurrentPlayer\Name$, CurrentPlayer\ScorePosition%) EndIf SaveHighScores() While Not KeyDown(1) ;Display the score table For t = 0 To 9 If t = CurrentPlayer\ScorePosition% Then Color 255,0,0 Else Color 255,255,255 EndIf Text 50, 50 + (t*16), HighScoreTable\Name$[t] Text 150, 50 + (t*16), ""+HighScoreTable\Score%[t] Next Flip Cls Wend End ;END OF PROGRAM Function LoadHighScores() ;Load the high scores from file ;create a default high score table for demonstration purposes ;0 is the bottom of the table, 9 is the top For t = 0 To 9 HighScoreTable\Name$[t] = "Player " + t HighScoreTable\Score%[t] = (t*1000) + 1000 Next End Function Function SaveHighScores() ;save the highscores to file End Function Function AddScore(Score%, Name$, Position%) For t = 0 To Position-1 If t = Position Then HighScoreTable\Score%[t] = HighScoreTable\Score[t+1] HighScoreTable\Name$[t] = HighScoreTable\Name$[t+1] EndIf Next HighScoreTable\Score%[Position] = Score% HighScoreTable\Name$[Position] = Name$ End Function Function GetScorePosition%(Score%) Local Position% For t = 0 To 9 If Score > HighScoreTable\Score[t] Then Position = t Next Return Position End Function
.
Did I beat you to it? :)
No, I was rude and condescending and decided to do a recall on it. ;)
That's very unlike you :)
There is a simpler version of highscore on my website:
www.blitzbasic.no
www.blitzbasic.no
Not that it's a big deal for a simple pong game, but if you plan to have a highscore table in a product you want to release, it would be a good idea to obfuscate the high scores (i.e. don't save it as a simple text file with name\score values) since it will be easily editable (there are people that do such things).
That's very unlike you :)
Stuffing a sock in your mouth, your head in the toilet.
;)