-
Aug 14th, 2009, 07:41 AM
#1
Thread Starter
Junior Member
How to create a HALL OF FAME (High score) system?
Yo!
Im creating a quiz game although i was wondering if any one can teach/tell me how to create a high score system.
For example when the user clicks say button1 (which is stop quiz) an input box will appear asking the user to input their name and then press okay. It then gets the current score from the text box (which is just an integer in a text box indicating how many they got right) and saves it to an Text file or something.
and when the user goes back to the main menu, he/she can select "Hall of Fame" which then brings up the highscores (in a new form) of previous users scores.
Now, i understand in order to this there will be two functions.
1 will be write
and the second will be read.
I haven't dealt with text files before (or anything for that matter) so anything simple a noob will understand will be great
Thanks
guys
-
Aug 14th, 2009, 07:52 AM
#2
Hyperactive Member
Re: How to create a HALL OF FAME (High score) system?
There is lots of stuff that explains this if u search this up on google, though i am mostly familar in VB.6 where i did the same thing.
-
Aug 14th, 2009, 07:57 AM
#3
Hyperactive Member
Re: How to create a HALL OF FAME (High score) system?
I saw something like this though i dont exactly know if it works:
The CreateText method creates a text file and returns a System.IO.StreamWriter object. With the StreamWriter object, you can then write to the file:
Code:
Code:
Dim oFile as System.IO.File
Dim oWrite as System.IO.StreamWriter
oWrite = oFile.CreateText(“C:\sample.txt”)
OpenTextThe OpenText method opens an existing text file for reading and returns a System.IO.StreamReader object. With the StreamReader object, you can then read the file:
Code:
Code:
Dim oFile as System.IO.File
Dim oRead as System.IO.StreamReader
oRead = oFile.OpenText(“C:\sample.txt”)
Writing to Textfile:
Code:
Code:
oWrite.WriteLine(“Write a line to the file”)
oWrite.WriteLine() ‘Write a blank line to the file
-
Aug 14th, 2009, 08:03 AM
#4
Thread Starter
Junior Member
Re: How to create a HALL OF FAME (High score) system?
Nope that didnt work monkz
lol
-
Aug 14th, 2009, 08:08 AM
#5
Re: How to create a HALL OF FAME (High score) system?
Use XML, just create a new structure for that...
<Hall Of Fame><User><Name>John Doe</Name><HS>1000</HS></USER>...
And then you only need to get and set the values...
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Aug 14th, 2009, 08:11 AM
#6
Hyperactive Member
Re: How to create a HALL OF FAME (High score) system?
Sorry then. I havent gotten into that yet. Im trying to learn VB.Net, but im working on a different type of project right now.
-
Aug 14th, 2009, 07:02 PM
#7
Thread Starter
Junior Member
Re: How to create a HALL OF FAME (High score) system?
-
Aug 14th, 2009, 07:09 PM
#8
Re: How to create a HALL OF FAME (High score) system?
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Aug 14th, 2009, 07:20 PM
#9
Thread Starter
Junior Member
Re: How to create a HALL OF FAME (High score) system?
well i was planning on just using a text file not so much xml
lol
-
Aug 14th, 2009, 07:35 PM
#10
Re: How to create a HALL OF FAME (High score) system?
You can just save the user line like this:
UserName;Score
Little example
VB.NET Code:
'Read the results from file
Dim strContent() As String = IO.File.ReadAllLines("PATH")
Dim dicScores As New System.Collections.Generic.Dictionary(Of String, Integer)
Dim userResult() As String
For Each strUser As String In strContent
userResult = strUser.Split(";")
dicScores.Add(userResult(0), Integer.Parse(userResult(1)))
Next
'Return the result of someone
Dim result As Integer = dicScores("UserName")
'Verify if the user exists
If dicScores.ContainsKey("UserName") Then
dicScores("UserName") = 1000 'Update the value
Else
dicScores.Add("UserName", 1000) 'Add a new one
End If
'Save the scores to the file
Dim strSave As String = String.Empty
For Each userScore As KeyValuePair(Of String, Integer) In dicScores
strSave &= userScore.Key & ";" & userScore.Value.ToString & vbNewLine
Next
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Aug 14th, 2009, 10:23 PM
#11
Member
Re: How to create a HALL OF FAME (High score) system?
Could also you an ini file which would be more practical then just a text file.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|