Вы находитесь на странице: 1из 6

CAR RACE PROGRAM

Private Sub Form_Activate()

comCars(MyCarIndex).Gear = 0

comCars(MyCarIndex).MaxSpeed = 200

comCars(MyCarIndex).User = True

mcSPOS = comCars(MyCarIndex).CurPos

Me.Top = 0

Shape1.Width = (Cars(0).Width * 5) + 1000

Picture1.Move 100, 100, ScaleWidth - 200, ScaleHeight - 200

Shape1.Move (Picture1.Width - Shape1.Width) - Image1.Width, -100, Shape1.Width,


Picture1.Height + 200

Line1.X1 = Shape1.Left + (Shape1.Width / 2)

Line1.X2 = Line1.X1

' Label1.Left = Line1.X1 - (Label1.Width / 2)

FinishLine.Left = Shape1.Left

FinishLine.Width = Shape1.Width

Image1.Left = Shape1.Left + Shape1.Width

Image1.Top = Picture1.Height

Image2.Left = Shape1.Left - Image2.Width - 100

Image2.Top = Picture1.Height / 2

Cars(MyCarIndex).ZOrder

ShowCars

If PlayNum = 1 Then

1
vKeys.UPKey = vbKeyUp

vKeys.DownKey = vbKeyDown

vKeys.RightKey = vbKeyRight

vKeys.LeftKey = vbKeyLeft

vKeys.NitroKey = vbKeyNumpad0

Else

vKeys.UPKey = vbKeyS

vKeys.DownKey = vbKeyX

vKeys.RightKey = vbKeyC

vKeys.LeftKey = vbKeyZ

vKeys.NitroKey = vbKeySpace

End If

List1.AddItem "Get"

List1.AddItem "Ready"

If PlayNum = 1 Then

Dim i%, i2%, i3%

For i = 1 To 4

For i2 = 1 To 1000

For i3 = 1 To 100

DoEvents

Next i3

Next i2

List1.List(0) = i

2
List1.List(1) = ""

Next i

While i < 4

DoEvents

Wend

List1.List(0) = "Go"

RaceStarted = True

End If

tEvents.Enabled = True

tcomCars.Enabled = True

tRoadTimer.Enabled = True

MyCar.Picture = Cars(MyCarIndex).Picture

End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

With comCars(MyCarIndex)

Select Case KeyCode

Case vKeys.DownKey

PLKey = comCars(MyCarIndex).MaxSpeed / 50

Case vKeys.UPKey

PLKey = -(comCars(MyCarIndex).MaxSpeed / 50)

Case vKeys.LeftKey

If .LRPos > 10 Then

3
.LRPos = .LRPos - 10

End If

Case vKeys.RightKey

If .LRPos < ((Shape1.Width - Cars(MyCarIndex).Width) / 10) - 10 Then

.LRPos = .LRPos + 10

End If

Case vKeys.NitroKey

If Nitro = 0 Then

Nitro = 1

comCars(MyCarIndex).Speed = comCars(MyCarIndex).Speed * 2

stNitro = comCars(MyCarIndex).CurPos

End If

Case vbKeyEscape

If MsgBox("Are you sure want to Exit?", vbExclamation + vbYesNo, "Exit") = vbYes


Then

End

End If

End Select

End With

End SubOption Explicit

Public Type tcomCars

Gear As Integer

Speed As Integer

CurPos As Single

4
LRPos As Single

MaxSpeed As Integer

User As Boolean

RaceDone As Boolean

End Type

Public Type tpKeys

UPKey As Integer

DownKey As Integer

LeftKey As Integer

RightKey As Integer

NitroKey As Integer

End Type

Public comCars(0 To 9) As tcomCars

Dim c1 As New Form1, c2 As New Form1

Sub Main()

Dim vDouble As Boolean

'If MsgBox("Do you want to play double", vbYesNo + vbInformation, "ComCars") = vbYes
Then

' vDouble = True

'End If

If vDouble Then c2.PlayNum = 2

5
c1.PlayNum = 1

If vDouble Then c2.MyCarIndex = 6

c1.MyCarIndex = 1

If vDouble Then

c2.Left = 0

c1.Left = c2.Width + 100

End If

c1.Caption = "SuperCarRace (Player-1)"

If vDouble Then

Set c2.pl1Form = c1

c2.Caption = "SuperCarRace (Player-2)"

c2.Show

c2.Enabled = False

End If

'c1.SetFocus

c1.Show

End Sub

REFERENCES

http://pages.cpsc.ucalgary.ca/~saul/vb_examples/

http://www.vbtutor.net/VB_Sample/sample.html

http://msdn.microsoft.com/en-us/library/zye5bsh8.aspx

http://en.wikipedia.org/wiki/Visual_Basic

Вам также может понравиться