CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Join Date
    Mar 2010
    Posts
    46

    [RESOLVED] Dance Mat Game Scoring

    Hello everyone,

    i've created a dance mat game similar to Dance Dance Revolution. It has 4 arrows and when no step is taken it's a binary value 1111. When the up arrow is stepped on the binary value is 1110. I'm having problems with my scoring guide. I'm using streamwriter and streamreader to record the time stamp and the binary value of each step taken and once the game is done I have the file display the timestamps and the binary values. For right now I just want it to add one point for whenever it registers a step taken. This is the code I have that records the timestamp and the binary value. lblBitValue is the value that changes from a 1 to 0 binary.


    Private Sub tmrReadInputs_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles tmrReadInputs.Tick
    Dim I As Short
    Dim ULStat As MccDaq.ErrorInfo
    Dim DataValue As UInt16

    tmrReadInputs.Stop()
    ' read FirstPortA digital input and display

    ' Parameters:
    ' PortNum :the input port
    ' DataValue :the value read from the port

    ULStat = DaqBoard.DIn(PortNum, DataValue)
    If ULStat.Value <> MccDaq.ErrorInfo.ErrorCode.NoErrors Then Stop

    ' display the value collected from the port

    lblPortRead.Text = DataValue.ToString("0")

    ' parse DataValue into bit values to indicate on/off status

    For I = 0 To 3
    If (Convert.ToInt32(DataValue) And CInt((2 ^ I))) <> 0 Then
    lblBitVal(I).Text = "1" 'NO STEP TAKEN
    Else
    lblBitVal(I).Text = "0" 'STEP TAKEN

    TextBox1.Text = Trim(Format(Now, "hh:mm:ss tt "))

    Dim GameFile As New System.IO.StreamWriter("C:\SavedGame.txt", OnGoingGame)
    GameFile.WriteLine(TextBox1.Text & DataValue)
    GameFile.Close()

    OnGoingGame = True


    End If
    Next I

    tmrReadInputs.Start()

    End Sub



    For the Scoring form I have the following:

    Public Class Score
    Public lblBitVal As System.Windows.Forms.Label()
    Const PortNum As MccDaq.DigitalPortType = MccDaq.DigitalPortType.FirstPortA ' set port to use
    Private DaqBoard As MccDaq.MccBoard = New MccDaq.MccBoard(0)l
    Dim I As Short


    Private Sub Score_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim ScoreValue As Decimal = 0
    'ULStat = DaqBoard.DIn(PortNum, DataValue)
    Dim GameScore As String = "C:\SavedGame.txt"
    If System.IO.File.Exists(GameScore) = True Then
    Dim objReader As New System.IO.StreamReader(GameScore)
    ValueBox.Text = objReader.ReadToEnd
    objReader.Close()
    If lblBitVal(I).Text = "0" Then
    ScoreValue += 1
    Else
    ScoreValue -= 0.5
    End If
    TextBox1.Text = ScoreValue
    End Sub


    It won't register lblBitVal in this form. It says "Object reference not set to an instance of an object." Also, this only adds 1 if there is a file opened. I need to it read the file and at least add a point for each time stamp that is recorded.

    Let me know if you guys know how I can go about this since my game is almost complete . THANKS AGAIN!

  2. #2
    Join Date
    Mar 2010
    Posts
    46

    Re: Dance Mat Game Scoring

    I need the following code:
    Dim intLines As Integer = ValueBox.Lines.Length
    TextBox1.Text = intLines

    which counts the number of lines in the text file, but is there a way to compare this file to another text file?

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Dance Mat Game Scoring

    Of course.

    For example you could read both files in thier entirety or one line at a time and compare some or all,

    What is it you are looking to do?
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Dance Mat Game Scoring

    You need to use code tags so your code can be read on the forum, very hard to follow as posted.

    Looks like you are trying to access lblBitVal from a different class where it is not known.
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Mar 2010
    Posts
    46

    Re: Dance Mat Game Scoring

    I would like to read the files line by line and compare if the timestamps are the same but before I do that I want to subtract the start time of my game to the time when the user steps on the dance mat. I have 3 text boxes showing the time when the start button was pressed, the second text box shows the time when the user steps on the dance and for the third text box I want it to show elapsed time. I have the following code under my start button:

    start_time =Trim(Format(Now, "hh:mm:ss tt "))


    In the main vb.net code:

    Static current_time As DateTime
    Static start_time As DateTime
    Dim elapsed_time As TimeSpan

    current_time = Trim(Format(Now, "hh:mm:ss tt "))
    CurrentTimeBox.Text = current_time

    elapsed_time = current_time.Subtract(start_time)

    TextBox1.Text = elapsed_time


    Sorry, I don't know where the code tags are? I'm trying to add less code

    But I get an error for last line with elapsed_time saying system.timespan cannot be converted to string. Would it be better to subtract or is this an elapsed time function in vb.net? Thanks for your time and help guys!!

  6. #6
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Dance Mat Game Scoring

    To add code tags you can simply type

    [ code ] Your code here [ /code ] without the spaces

    Timespan has additional properties type a period after elapsed_time and you will see some of them.

    There is also the DateDiff() function in VB that is still supported.
    Always use [code][/code] tags when posting code.

  7. #7
    Join Date
    Mar 2010
    Posts
    46

    Re: Dance Mat Game Scoring

    Thanks Again DataMiser for your help! I added this:
    TextBox1.Text = elapsed_time.Duration.Seconds

    but when start time is 5:12:44
    current time is : 5:12:45

    it gives the elapsed time as 57

    I want it to show 0:00:01 for the elapsed time... I'm not sure why it gives me 57

  8. #8
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Dance Mat Game Scoring

    Show your code that you are using now.
    Always use [code][/code] tags when posting code.

  9. #9
    Join Date
    Mar 2010
    Posts
    46

    Re: Dance Mat Game Scoring

    Code:
      Static current_time As Date = Date.Now
            Static start_time As Date = Date.Now
            Dim elapsed_time As TimeSpan
            For I = 0 To 3
                If (Convert.ToInt32(DataValue) And CInt((2 ^ I))) <> 0 Then
                    lblBitVal(I).Text = "1"
                Else
                    lblBitVal(I).Text = "0"
    
                    
                    Dim GameFile As New System.IO.StreamWriter("C:\SavedGame.txt", OnGoingGame)
                    GameFile.WriteLine(StartTimeBox.Text & DataValue)
                    GameFile.Close()
    
                    OnGoingGame = True
                    'CurrentTimeBox.Text = Trim(Format(Now, "hh:mm:ss tt "))
                    current_time = Trim(Format(Now, "hh:mm:ss tt "))
                    CurrentTimeBox.Text = current_time
                    elapsed_time = current_time.Subtract(start_time)
    
                    TextBox1.Text = elapsed_time.Duration.Seconds
                End If

  10. #10
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Dance Mat Game Scoring

    I think it is in your property usage.

    Have a look at this.

    Code:
    Public Class Form1
        Private StartTime As DateTime
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            StartTime = Now()
        End Sub
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim EndTime As DateTime = Now()
            Dim Elapsed_time As TimeSpan = EndTime.Subtract(StartTime)
    
            Label1.Text = Elapsed_time.Seconds
        End Sub
    End Class
    The starttime is set when button one is pressed.
    The second button causes the number of elapsed seconds to display in a label on the form
    Always use [code][/code] tags when posting code.

  11. #11
    Join Date
    Mar 2010
    Posts
    46

    Re: Dance Mat Game Scoring

    Ah Thank you again! Is there anyway to only show the time in "hh:mm:ss tt" ?? Sorry only reason I'm asking is that I'm saving just the time stamps and binary value in a text file using StreamWriter and then using StreamReader to display the timestamps with the binary value. So when i compare the two files, the dates will not be in the other file.

  12. #12
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Dance Mat Game Scoring

    Look up String.Format()
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  13. #13
    Join Date
    Mar 2010
    Posts
    46

    Re: Dance Mat Game Scoring

    Great thanks dglienna! I used Trim(Format(Now, "hh:mm:ss tt"))

  14. #14
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Dance Mat Game Scoring

    Pull down Thread Tools from the top, and MARK AS RESOLVED!
    Last edited by dglienna; April 30th, 2010 at 06:30 PM.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  15. #15
    Join Date
    Mar 2010
    Posts
    46

    Re: [RESOLVED] Dance Mat Game Scoring

    It is really odd but now the scoring doesn't work.

    When I step on the dance mat the start time textbox writes: 1:14:24am
    Then when I step on my dance mat the end time text box writes: 1:14:28am
    The elapsed time box writes: 4

    Then when I view the text file it saved in, it says 28 instead of 4. It is somehow reading the seconds time from the end time text box. I tried changing the elapsed time to read total seconds but that did not work.

    Code:
                    Dim endTime As DateTime = Trim(Format(Now, "hh:mm:ss tt"))
                    Dim elapsedTime As TimeSpan = endTime.Subtract(startTime)
                    EndTimeBox.Text = endTime
                    ElapsedTimeBox.Text = elapsedTime.Seconds     'display the elapsed time
    
    
                    Dim GameFile As New System.IO.StreamWriter("C:\SavedSurvive.txt", OnGoingGame)
                    GameFile.WriteLine(ElapsedTimeBox.Text & " : " & DataValue)
                    GameFile.Close()
    
                    OnGoingGame = True
    
                End If

Page 1 of 2 12 LastLast

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

Featured