Results 1 to 10 of 10

Thread: Please help! What's an easy way to make a High Score section for my game?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    Seattle.
    Posts
    176

    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

    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!

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    Seattle.
    Posts
    176

    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

  3. #3
    Hyperactive Member Quasar6's Avatar
    Join Date
    Mar 2008
    Location
    Sol 3
    Posts
    325

    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).

    Gimme a sec, I'm typing... there's about three things to respond to in your post...
    "Why do all my attempts at science end with me getting punched by batman?" xkcd.

    |Pong||
    Sorry for not posting more often.

  4. #4
    Hyperactive Member Quasar6's Avatar
    Join Date
    Mar 2008
    Location
    Sol 3
    Posts
    325

    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:
    Code:
    (See below)
    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:
    Code:
    Imports System.IO
    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.
    Code:
    sW.Close()
    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:
    Code:
    sR.Close()
    Hope that helps,
    Qu.
    Last edited by Quasar6; May 8th, 2008 at 12:55 AM.
    "Why do all my attempts at science end with me getting punched by batman?" xkcd.

    |Pong||
    Sorry for not posting more often.

  5. #5
    Hyperactive Member Quasar6's Avatar
    Join Date
    Mar 2008
    Location
    Sol 3
    Posts
    325

    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...

    AAAAAARRRGGHHH!!!!
    "Why do all my attempts at science end with me getting punched by batman?" xkcd.

    |Pong||
    Sorry for not posting more often.

  6. #6
    Member RockStarEnergy's Avatar
    Join Date
    Jan 2007
    Location
    Nebraska
    Posts
    54

    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
    i <3

  7. #7
    Hyperactive Member Quasar6's Avatar
    Join Date
    Mar 2008
    Location
    Sol 3
    Posts
    325

    Re: Please help! What's an easy way to make a High Score section for my game?

    oops. I'll fix that...
    "Why do all my attempts at science end with me getting punched by batman?" xkcd.

    |Pong||
    Sorry for not posting more often.

  8. #8
    New Member
    Join Date
    Jul 2008
    Posts
    4

    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...

  9. #9
    Hyperactive Member Quasar6's Avatar
    Join Date
    Mar 2008
    Location
    Sol 3
    Posts
    325

    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
    "Why do all my attempts at science end with me getting punched by batman?" xkcd.

    |Pong||
    Sorry for not posting more often.

  10. #10
    New Member
    Join Date
    Jul 2008
    Posts
    4

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width