Please help! What's an easy way to make a High Score section for my game?
How can I use a new form I made (form3) to display the high scores for Red and Blue team in their respective listboxes?
When the user pushes the spacebar or clicks on the menu "High Scores"m I need the code to be something like:
Select Case...
Case keys.Spacebar
ScoreRed.text += RedListBox.line1
ScoreBlue.Text += BlueListBox.line1
Or something :confused:
The teacher gave me this confusing mess of code to use, in which I make a notepad file with an odd file extension and save the scores there, but I don't like that way. Well it would be nice if there was an ultra easy way to do this! Please help!
Re: Please help! What's an easy way to make a High Score section for my game?
No one helps me anymore:( I don't have a contagious disease. Well except noobatosis for VB:O
Re: Please help! What's an easy way to make a High Score section for my game?
We still help you. Have a little patience: You posted those two within 20 minutes of each other, and some of us only visit once a day (if that). :o
Gimme a sec, I'm typing... there's about three things to respond to in your post...
Re: Please help! What's an easy way to make a High Score section for my game?
Making High Scores:
I don't know how you're going to manage the high scores, but I'm assuming you'll keep only the top 3...
Make an Array with 3 spaces:
Code:
Dim highScores As Integer(3)
Fill this array from a text file:
Now, when a player finishes the game, get their score and compare it to all three existing high scores:
Code:
For i=0 To highScores.Length 'go through each array element
If highScores(i)<currentScore Then 'If the current score is larger than any of them
highScores(i)=currentScore 'put the high score in
Exit For
End If
Next i
And then save your array to the text file:
Code:
(See below again) :)
Displaying Form3:
Assuming you've already built form3, displaying it isn't that hard:
Code:
Dim highScoreForm As Form3
highScoreForm.ShowDialog()
Saving stuff into a textFile:
It's probably best you do save this stuff into a text file, partly because it isn't hard but mainly because you'll definately need to save other stuff into text files later on. I do it all the time.
Put this at the top with your imports statements:
Now, create a StreamWriter (a streamwriter feeds stuff into a stream, which the text file picks up on the other end)...
Code:
Dim sW As StreamWriter = new StreamWriter(*insert your filepath here*)
And write your array to the stream (which in turn writes it to the text file).
Code:
Dim i As Integer
For i=0 To highScores.Length 'go through each array element
sW.WriteLine(highScores(i).ToString()) 'write array element to a new line
Next i
Finally, close the stream.
Filling Array from text file:
Using a StreamReader, which is a StreamWriter in reverse, you can get your stuff out of the saved text file.
First create a streamReader. It works the same as a StreamWriter, but it gets the stuff off of the steam coming in from the text file.
Code:
Dim sR As StreamReader = new StreamReader(*insert your filepath here*)
Now write each line to a new array element:
Code:
For i=0 To highScores.Length 'go through each array element
highScores(i) = int.Parse(sR.ReadLine()) 'write line to a new element
Next i
And once again, close the stream:
Hope that helps,
Qu.
Re: Please help! What's an easy way to make a High Score section for my game?
One other thing... Noobatosis for VB is contagious?
Oh God, no...
:eek: AAAAAARRRGGHHH!!!! :eek:
Re: Please help! What's an easy way to make a High Score section for my game?
Don't forget to dim sW as new Streamwriter.
otherwise it gives u a null ref error
Re: Please help! What's an easy way to make a High Score section for my game?
Re: Please help! What's an easy way to make a High Score section for my game?
Hi, for the Streamreader code:
Code:
For i=0 To highScores.Length 'go through each array element
highScores(i) = int.Parse(sR.ReadLine()) 'write line to a new element
Next i
"Int" gives the error "Overload resolution failed because no accessible 'int' accepts this number of arguments"
Its really annoying.
I think I have noobatosis...
Re: Please help! What's an easy way to make a High Score section for my game?
Ah, I must have been still in C# mode when I wrote that. It should read:
Code:
For i=0 To highScores.Length 'go through each array element
highScores(i) = Integer.Parse(sR.ReadLine()) 'write line to a new element
Next i
:)
Re: Please help! What's an easy way to make a High Score section for my game?
Hmm, now I have the error when it is run, that reads "InvalidOperationException was unhandled" "an error occured creating the form. The error is: The process cannot access the file 'c:\test.txt' because it is being used by another process"
What other process could be using it?
Thanks so much for your help.