
-----------------------------------
Robotnik
Mon May 08, 2006 1:43 pm

Help with a horse race program, please
-----------------------------------
First off, if you dont have anything helpful or relevant to post, then dont post at all please.

I am making a game for my grade 11 class in which I must have a horse race. The user puts in thier bet and chooses a horse to place it on and then the horses do a little race animation that differs each time. I just need some help or tidbits of code to start with, kind of a noob.

-----------------------------------
pavol
Mon May 08, 2006 3:09 pm


-----------------------------------
well you can start off by declaring a variable for each of the horse speeds, an array would be the most efficient. then randomize a number for each of the horses which will act as the horse's speed. afterwards, it's easy, just have them move accross the screen at that randomized value, check who crosses the finish line first (or who's speed is the greatest), and compare to the user's guess. to make it more interesting though, you could have the horses' speeds change every so often. :D

-----------------------------------
Darkmantis
Tue May 09, 2006 10:43 am


-----------------------------------
here is a race program Ive been working on. This is only the .exe file because Im at school and I cant rightclick to zip suff so..ya. Ill also post the code.

[u][b]form1 :[/b][/u]

Private Sub car1_Timer()
Pic1.Left = Pic1.Left + Int(Rnd * 30) + 5
If Pic1.Left + Pic1.Width >= 9240 Then
Pic1.Left = 0
Pic2.Left = 0
Pic3.Left = 0
Pic4.Left = 0
freeze.Enabled = True
scoreb = scoreb + 1
score1 = scoreb

If list1 = "Blue" Then
wins = "Player 1 scores a Point"
Points1 = Points1 + 1
ElseIf list2 = "Blue" Then
wins = "Player 2 scores a point!"
Points2 = Points2 + 1
End If
End If
End Sub

Private Sub car2_Timer()
Pic2.Left = Pic2.Left + Int(Rnd * 30) + 5
If Pic2.Left + Pic2.Width >= 9240 Then
Pic1.Left = 0
Pic2.Left = 0
Pic3.Left = 0
Pic4.Left = 0
freeze.Enabled = True
scorey = scorey + 1
score2.Caption = scorey

If list1 = "Yellow" Then
wins = "Player 1 scores a Point"
Points1 = Points1 + 1
ElseIf list2 = "Yellow" Then
wins = "Player 2 scores a point!"
Points2 = Points2 + 1
End If
End If
End Sub

Private Sub car3_Timer()
Pic3.Left = Pic3.Left + Int(Rnd * 30) + 5
If Pic3.Left + Pic3.Width >= 9240 Then
Pic1.Left = 0
Pic2.Left = 0
Pic3.Left = 0
Pic4.Left = 0
freeze.Enabled = True
scoreg = scoreg + 1
score3.Caption = scoreg

If list1 = "Green" Then
wins = "Player 1 scores a Point"
Points1 = Points1 + 1
ElseIf list2 = "Green" Then
wins = "Player 2 scores a point!"
Points2 = Points2 + 1
End If
End If

End Sub

Private Sub car4_Timer()
Pic4.Left = Pic4.Left + Int(Rnd * 30) + 5
If Pic4.Left + Pic4.Width >= 9240 Then
Pic1.Left = 0
Pic2.Left = 0
Pic3.Left = 0
Pic4.Left = 0
freeze.Enabled = True
scorer = scorer + 1
score4.Caption = scorer

If list1 = "Red" Then
wins = "Player 1 scores a Point"
Points1 = Points1 + 1
ElseIf list2 = "Red" Then
wins = "Player 2 scores a point!"
Points2 = Points2 + 1
End If
End If
End Sub

Private Sub Command1_Click()
wins = ""
freeze.Enabled = False
End Sub

Private Sub Form_Load()
scoreb = 0
scorey = 0
scoerg = 0
scorer = 0
Points1 = 0
Points2 = 0
nme1 = Form2.txtnme1
nme2 = Form2.txtnme2
freeze.Enabled = True
End Sub

Private Sub freeze_Timer()
Pic1.Left = 0
Pic2.Left = 0
Pic3.Left = 0
Pic4.Left = 0
End Sub

Private Sub New_Click()
Load frmSplash
Form1.Hide
Form1.Cls
frmSplash.Show
Pic1.Left = 0
Pic2.Left = 0
Pic3.Left = 0
Pic4.Left = 0
End Sub

Private Sub Quit_Click()
End
End Sub


[u][b]Module [/b][/u]

Global scoreb, scorey, scoreg, scorer, wins, Points1, Points2


-----------------------------------
Robotnik
Wed May 10, 2006 10:12 am

Freeze?
-----------------------------------
freeze.Enabled = True

What does freeze do? I keeps saying that the "freeze" variable isn't declared.

-----------------------------------
Darkmantis
Wed May 10, 2006 11:01 am


-----------------------------------
freeze is one of my timers

-----------------------------------
Robotnik
Wed May 10, 2006 1:01 pm

Question
-----------------------------------
form1 :

Module 

Global scoreb, scorey, scoreg, scorer, wins, Points1, Points2


Dont understand any of this stuff, it just shows up red and gives me errors. Sorry for all the questions I'm a real noob.

-----------------------------------
Darkmantis
Wed May 10, 2006 3:07 pm


-----------------------------------
no its ok ill give U a bit of a tutorial, well for modules I use a global variable to declare that the variables I include in the code are able to be used in dfferent forms in the program and I use them a lot.

this show you where you can add a module to your project/program :)
righ click on form1 and click add and then module :)
http://www.geocities.com/darkmantis2004/scet4.jpg

-----------------------------------
Robotnik
Thu May 11, 2006 12:58 pm

Mo questions.
-----------------------------------
So I put all of my declarations in the module? And did you do anything else besides picture boxes for the cars and track?

-----------------------------------
Darkmantis
Thu May 11, 2006 1:06 pm


-----------------------------------
I don't think so why?

-----------------------------------
Robotnik
Thu May 11, 2006 1:18 pm


-----------------------------------
Just checking to see if the positions or size of the pic boxes had anything to do with it. Instead of putting something like "Global scoreb, scorey, scoreg, scorer, wins, Points1, Points2 " could I just do something like:

Option Explicit

Private scoreb As Integer
Private scorey As Integer
Private scoreg As Integer
Private scorer As Integer
Private wins As Integer
Private points1 As Integer
Private points2 As Integer

to declare the variables?

-----------------------------------
cool dude
Thu May 11, 2006 2:45 pm


-----------------------------------
u can but then the variables will be private. if u want to do it like that then say public

-----------------------------------
Darkmantis
Thu May 11, 2006 5:04 pm


-----------------------------------
wow Ive never seen such code before *twich* must write down for further inspection  *twich*

-----------------------------------
Robotnik
Fri May 12, 2006 1:10 pm

Declarations
-----------------------------------
Are all of your declarations inside the module itself? Or better yet, what do you have in the madule? I'm just a bit confused I havent used modules yet.

-----------------------------------
Darkmantis
Fri May 12, 2006 2:40 pm


-----------------------------------
Basically Points1 and Points2 is the number of points the person has and all the score things is just what I use to keep track of how many wins each car has. Scorer is the score for red, scorey is the score for yellow and so on.. and the wins variable is just declaring a text box so I can transfer text to it to show who won that round :)

-----------------------------------
Robotnik
Mon May 15, 2006 11:28 am


-----------------------------------
If its not too much trouble, or if its not against the rules, could you post your VB files so I can take a look at them. I'm not going to use them word for word or anything, theres just a few more things I need to figure out before I can finish and it would be easier to look rather than going back and forth. Thanks for all the help so far by the way it has really benefited me.

-----------------------------------
Darkmantis
Mon May 15, 2006 11:53 am


-----------------------------------
no problem, Ill post the program but it'll take some time because im at school and the school computer dont have winzip :(, so Ill do it as soon as I get home :D Im not really sure what the rules are but Ill give you the files anyway lol :D

-----------------------------------
Darkmantis
Mon May 15, 2006 12:23 pm


-----------------------------------
I didnt want to wait so I found a online storage to put the files on hers the link: http://www.box.net

and the login info is as follows:

user : darkmantis3000@hotmail.com
password : goodandy

go into the storage and click all the items you need to download
dont worry about anything its just a account I threw together just for this occasion :D

-----------------------------------
Robotnik
Wed May 17, 2006 12:05 pm


-----------------------------------
Doesn't work, says 'Retained' is an invalid key when I try to load the Carace.vbp.

-----------------------------------
Brightguy
Wed May 24, 2006 3:27 pm

Re: Help with a horse race program, please
-----------------------------------
The 'Retained' key is used in VB6...  However, VB5, rather than ignoring keys it doesn't recognise, refuses to load the project.

Open the file in a text editor, remove the "Retained=0" line, and the project will open fine.
