Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with a horse race program, please
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Robotnik




PostPosted: Mon May 08, 2006 1:43 pm   Post subject: 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.
Sponsor
Sponsor
Sponsor
sponsor
pavol




PostPosted: Mon May 08, 2006 3:09 pm   Post subject: (No subject)

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. Very Happy
Darkmantis




PostPosted: Tue May 09, 2006 10:43 am   Post subject: (No subject)

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



The Extension 'exe' was deactivated by an board admin, therefore this Attachment is not displayed.

Robotnik




PostPosted: Wed May 10, 2006 10:12 am   Post subject: Freeze?

freeze.Enabled = True

What does freeze do? I keeps saying that the "freeze" variable isn't declared.
Darkmantis




PostPosted: Wed May 10, 2006 11:01 am   Post subject: (No subject)

freeze is one of my timers
Robotnik




PostPosted: Wed May 10, 2006 1:01 pm   Post subject: 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




PostPosted: Wed May 10, 2006 3:07 pm   Post subject: (No subject)

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 Smile
righ click on form1 and click add and then module Smile
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Robotnik




PostPosted: Thu May 11, 2006 12:58 pm   Post subject: 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?
Sponsor
Sponsor
Sponsor
sponsor
Darkmantis




PostPosted: Thu May 11, 2006 1:06 pm   Post subject: (No subject)

I don't think so why?
Robotnik




PostPosted: Thu May 11, 2006 1:18 pm   Post subject: (No subject)

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




PostPosted: Thu May 11, 2006 2:45 pm   Post subject: (No subject)

u can but then the variables will be private. if u want to do it like that then say public
Darkmantis




PostPosted: Thu May 11, 2006 5:04 pm   Post subject: (No subject)

wow Ive never seen such code before *twich* must write down for further inspection *twich*
Robotnik




PostPosted: Fri May 12, 2006 1:10 pm   Post subject: 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




PostPosted: Fri May 12, 2006 2:40 pm   Post subject: (No subject)

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 Smile
Robotnik




PostPosted: Mon May 15, 2006 11:28 am   Post subject: (No subject)

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.
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 19 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: