1 Replies - 238 Views - Last Post: 31 January 2012 - 01:03 AM Rate Topic: -----

Topic Sponsor:

#1 chrisreaper  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 25
  • Joined: 27-September 11

Racing Project

Posted 30 January 2012 - 06:26 PM

We have this project and I can get the Top Object to win and the bottom object can never win with my syntax and I cannot figure out why. My tie statements also work, but I just cannot figure out why my bottom image can't win. Could you take a look for me please? It is attached in a .zip file.




Public Class Racers
    Dim intTopPonyWins As Integer
    Dim intBtmPonyWins As Integer
    Dim intTies As Integer


    Private Sub btnRace_Click(sender As System.Object, e As System.EventArgs) Handles btnRace.Click
        Dim intTopPony As Integer
        Dim intBtmPony As Integer
        Dim rand As New Random
        Dim rand2 As New Random

        Do Until picTopPony.Location.X >= 767 Or picBtmPony.Location.X >= 767

            intTopPony = rand.Next(5)

            intBtmPony = rand2.Next(5)

            picBtmPony.Left += intBtmPony

            picTopPony.Left += intTopPony



        Loop

        If picTopPony.Location.X = picFinishLine.Location.X And picBtmPony.Location.X = picFinishLine.Location.X Then

            MessageBox.Show("It's a Tie!")
            intTies += 1


        ElseIf picTopPony.Left >= picFinishLine.Left Then

            MessageBox.Show("The White Pony Wins!")
            intTopPonyWins += 1


        ElseIf picBtmPony.Left >= picFinishLine.Left Then

            MessageBox.Show("The Pink Pony Wins!")
            intBtmPonyWins += 1

        End If
    End Sub


    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles btnReset.Click
        picBtmPony.Left = 0
        picTopPony.Left = 0


    End Sub

    Private Sub btnShowResults_Click(sender As System.Object, e As System.EventArgs) Handles btnShowResults.Click
        MessageBox.Show("White Pony Wins: " & intTopPonyWins & vbCrLf & "Pink Pony Wins: " & intBtmPonyWins & vbCrLf & "Ties: " & intTies, "Results")
    End Sub
End Class




Is This A Good Question/Topic? 0
  • +

Replies To: Racing Project

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 211
  • View blog
  • Posts: 1,249
  • Joined: 26-March 09

Re: Racing Project

Posted 31 January 2012 - 01:03 AM

Couple of things.

1. This is VB.Net code, so you'd be better asking for it to be moved to the correct forum.

2. You're using the Random function. In VB6, using the random number generator always starts with the same seed (Same random number generated each time), unless you call Randomize first. It would be worth checking whether it's the same in VB.Net. You can also check this by writing the Random number values to a text box and check the outputs.

Hopefully that gives you a starting point.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1