saucholoi
Mr & Ms Pac-Man
- 21/2/06
- 239
- 1
Em có một đoạn code VB ai có thể giúp em dịch sang C hoặc java cũng được,hoặc nếu không được thì comment bên cạnh các dòng lệnh các tác dụng của từng cậu lệnh tương ứng cũng được.
Public Class ctrlXe
Inherits ctrlQuanCo
Public Sub New(ByVal ViTri As Point, ByVal mau As String)
SetViTri(ViTri)
If mau = "do" Then
SetTenQuanCo("xe")
SetHinh("xedo.bmp")
SetMau(mau)
Else
SetHinh("xeden.bmp")
SetTenQuanCo("xe")
SetMau(mau)
End If
End Sub
Public Overrides Function TimVitri() As ArrayList
Dim A As ArrayList = Me.GetA
Dim B As ArrayList = Me.GetB
Dim mang As ArrayList = New ArrayList
Dim left As Integer = 5
Dim right As Integer = 389
Dim top As Integer = 3
Dim bottom As Integer = 453
Dim pos As Point = Me.GetViTri()
Dim flag As Boolean = True
If (Me.GetMau() = "do") Then
'====================================
While ((pos.X - 48) >= left) 'giam cot
'khi toi quan co cua minh thi dung
For i As Integer = 0 To A.Count - 1
Dim quanco As ctrlQuanCo = A(i)
If Not (quanco Is Nothing) Then
If (pos.X - 48) = quanco.GetViTri().X And (pos.Y = quanco.GetViTri().Y) Then
flag = False
Exit For
End If
End If
Next
'khi toi quan co cua dich lan 1 thi them vao, roi dung
For i As Integer = 0 To B.Count - 1
Dim quanco As ctrlQuanCo = B(i)
If Not (quanco Is Nothing) Then
If (pos.X - 48) = quanco.GetViTri().X And (pos.Y = quanco.GetViTri().Y) Then
mang.Add(New Point(pos.X - 48, pos.Y))
Exit While
End If
End If
Next
pos.X -= 48
If flag <> False Then
mang.Add(New Point(pos.X, pos.Y))
End If
End While
'====================================
pos = Me.GetViTri()
flag = True
While ((pos.X + 48) <= right) 'tang cot
For i As Integer = 0 To A.Count - 1
Dim quanco As ctrlQuanCo = A(i)
If Not (quanco Is Nothing) Then
If (pos.X + 48) = quanco.GetViTri().X And (pos.Y = quanco.GetViTri().Y) Then
flag = False
Exit For
End If
End If
Next
'khi toi quan co cua dich lan 1 thi them vao, roi dung
For i As Integer = 0 To B.Count - 1
Dim quanco As ctrlQuanCo = B(i)
If Not (quanco Is Nothing) Then
If (pos.X + 48) = quanco.GetViTri().X And (pos.Y = quanco.GetViTri().Y) Then
mang.Add(New Point(pos.X + 48, pos.Y))
Exit While
End If
End If
Next
pos.X += 48
If flag <> False Then
mang.Add(New Point(pos.X, pos.Y))
End If
End While
'====================================
flag = True
pos = Me.GetViTri()
While ((pos.Y - 50) >= top) 'giam dong
For i As Integer = 0 To A.Count - 1
Dim quanco As ctrlQuanCo = A(i)
If Not (quanco Is Nothing) Then
If (pos.Y - 50) = quanco.GetViTri().Y And (pos.X = quanco.GetViTri().X) Then
flag = False
Exit For
End If
End If
Next
'khi toi quan co cua dich lan 1 thi them vao, roi dung
For i As Integer = 0 To B.Count - 1
Dim quanco As ctrlQuanCo = B(i)
If Not (quanco Is Nothing) Then
If (pos.Y - 50) = quanco.GetViTri().Y And (pos.X = quanco.GetViTri().X) Then
mang.Add(New Point(pos.X, pos.Y - 50))
Exit While
End If
End If
Next
pos.Y -= 50
If flag <> False Then
mang.Add(New Point(pos.X, pos.Y))
End If
End While
'=========================
pos = Me.GetViTri()
flag = True
While ((pos.Y + 50) <= bottom) 'tang dong
For i As Integer = 0 To A.Count - 1
Dim quanco As ctrlQuanCo = A(i)
If Not (quanco Is Nothing) Then
If (pos.Y + 50) = quanco.GetViTri().Y And (pos.X = quanco.GetViTri().X) Then
flag = False
Exit For
End If
End If
Next
'khi toi quan co cua dich lan 1 thi them vao, roi dung
For i As Integer = 0 To B.Count - 1
Dim quanco As ctrlQuanCo = B(i)
If Not (quanco Is Nothing) Then
If (pos.Y + 50) = quanco.GetViTri().Y And (pos.X = quanco.GetViTri().X) Then
mang.Add(New Point(pos.X, pos.Y + 50))
Exit While
End If
End If
Next
pos.Y += 50
If flag <> False Then
mang.Add(New Point(pos.X, pos.Y))
End If
End While
'===============xet quan co Den===============
Else 'den
pos = Me.GetViTri()
flag = True
While ((pos.X - 48) >= left) 'giam cot
For i As Integer = 0 To B.Count - 1
Dim quanco As ctrlQuanCo = B(i)
If Not (quanco Is Nothing) Then
If ((pos.X - 48) = quanco.GetViTri().X) And (pos.Y = quanco.GetViTri().Y) Then
flag = False
Exit For
End If
End If
Next
'khi toi quan co cua dich lan 1 thi them vao, roi dung
For i As Integer = 0 To A.Count - 1
Dim quanco As ctrlQuanCo = A(i)
If Not (quanco Is Nothing) Then
If (pos.X - 48) = quanco.GetViTri().X And (pos.Y = quanco.GetViTri().Y) Then
mang.Add(New Point(pos.X - 48, pos.Y))
Exit While
End If
End If
Next
pos.X -= 48
'If flag = False Then
' Exit While
'End If
If flag <> False Then
mang.Add(New Point(pos.X, pos.Y))
End If
End While
'====================================
pos = Me.GetViTri()
flag = True
While ((pos.X + 48) <= right) 'tang cot
For i As Integer = 0 To B.Count - 1
Dim quanco As ctrlQuanCo = B(i)
If Not (quanco Is Nothing) Then
If (pos.X + 48) = quanco.GetViTri().X And (pos.Y = quanco.GetViTri().Y) Then
flag = False
Exit For
End If
End If
Next
'khi toi quan co cua dich lan 1 thi them vao, roi dung
For i As Integer = 0 To A.Count - 1
Dim quanco As ctrlQuanCo = A(i)
If Not (quanco Is Nothing) Then
If (pos.X + 48) = quanco.GetViTri().X And (pos.Y = quanco.GetViTri().Y) Then
mang.Add(New Point(pos.X + 48, pos.Y))
Exit While
End If
End If
Next
pos.X += 48
'If flag = False Then
' Exit While
'End If
If flag <> False Then
mang.Add(New Point(pos.X, pos.Y))
End If
End While
'====================================
pos = Me.GetViTri()
flag = True
While ((pos.Y - 50) >= top) 'giam dong
For i As Integer = 0 To B.Count - 1
Dim quanco As ctrlQuanCo = B(i)
If Not (quanco Is Nothing) Then
If (pos.Y - 50) = quanco.GetViTri().Y And (pos.X = quanco.GetViTri().X) Then
flag = False
Exit For
End If
End If
Next
'khi toi quan co cua dich lan 1 thi them vao, roi dung
For i As Integer = 0 To A.Count - 1
Dim quanco As ctrlQuanCo = A(i)
If Not (quanco Is Nothing) Then
If (pos.Y - 50) = quanco.GetViTri().Y And (pos.X = quanco.GetViTri().X) Then
mang.Add(New Point(pos.X, pos.Y - 50))
Exit While
End If
End If
Next
pos.Y -= 50
If flag <> False Then
mang.Add(New Point(pos.X, pos.Y))
End If
End While
'====================================
pos = Me.GetViTri()
flag = True
While ((pos.Y + 50) <= bottom) 'tang dong
If pos.Y = 303 Then
Dim thu As Boolean = True
End If
For i As Integer = 0 To B.Count - 1
Dim quanco As ctrlQuanCo = B(i)
If Not (quanco Is Nothing) Then
If (pos.Y + 50) = quanco.GetViTri().Y And (pos.X = quanco.GetViTri().X) Then
flag = False
Exit For
End If
End If
Next
'khi toi quan co cua dich lan 1 thi them vao, roi dung
For i As Integer = 0 To A.Count - 1
Dim quanco As ctrlQuanCo = A(i)
If Not (quanco Is Nothing) Then
If (pos.Y + 50) = quanco.GetViTri().Y And (pos.X = quanco.GetViTri().X) Then
mang.Add(New Point(pos.X, pos.Y + 50))
Exit While
End If
End If
Next
pos.Y += 50
If flag <> False Then
mang.Add(New Point(pos.X, pos.Y))
End If
End While
End If
Return mang
End Function
End Class
Public Class ctrlXe
Inherits ctrlQuanCo
Public Sub New(ByVal ViTri As Point, ByVal mau As String)
SetViTri(ViTri)
If mau = "do" Then
SetTenQuanCo("xe")
SetHinh("xedo.bmp")
SetMau(mau)
Else
SetHinh("xeden.bmp")
SetTenQuanCo("xe")
SetMau(mau)
End If
End Sub
Public Overrides Function TimVitri() As ArrayList
Dim A As ArrayList = Me.GetA
Dim B As ArrayList = Me.GetB
Dim mang As ArrayList = New ArrayList
Dim left As Integer = 5
Dim right As Integer = 389
Dim top As Integer = 3
Dim bottom As Integer = 453
Dim pos As Point = Me.GetViTri()
Dim flag As Boolean = True
If (Me.GetMau() = "do") Then
'====================================
While ((pos.X - 48) >= left) 'giam cot
'khi toi quan co cua minh thi dung
For i As Integer = 0 To A.Count - 1
Dim quanco As ctrlQuanCo = A(i)
If Not (quanco Is Nothing) Then
If (pos.X - 48) = quanco.GetViTri().X And (pos.Y = quanco.GetViTri().Y) Then
flag = False
Exit For
End If
End If
Next
'khi toi quan co cua dich lan 1 thi them vao, roi dung
For i As Integer = 0 To B.Count - 1
Dim quanco As ctrlQuanCo = B(i)
If Not (quanco Is Nothing) Then
If (pos.X - 48) = quanco.GetViTri().X And (pos.Y = quanco.GetViTri().Y) Then
mang.Add(New Point(pos.X - 48, pos.Y))
Exit While
End If
End If
Next
pos.X -= 48
If flag <> False Then
mang.Add(New Point(pos.X, pos.Y))
End If
End While
'====================================
pos = Me.GetViTri()
flag = True
While ((pos.X + 48) <= right) 'tang cot
For i As Integer = 0 To A.Count - 1
Dim quanco As ctrlQuanCo = A(i)
If Not (quanco Is Nothing) Then
If (pos.X + 48) = quanco.GetViTri().X And (pos.Y = quanco.GetViTri().Y) Then
flag = False
Exit For
End If
End If
Next
'khi toi quan co cua dich lan 1 thi them vao, roi dung
For i As Integer = 0 To B.Count - 1
Dim quanco As ctrlQuanCo = B(i)
If Not (quanco Is Nothing) Then
If (pos.X + 48) = quanco.GetViTri().X And (pos.Y = quanco.GetViTri().Y) Then
mang.Add(New Point(pos.X + 48, pos.Y))
Exit While
End If
End If
Next
pos.X += 48
If flag <> False Then
mang.Add(New Point(pos.X, pos.Y))
End If
End While
'====================================
flag = True
pos = Me.GetViTri()
While ((pos.Y - 50) >= top) 'giam dong
For i As Integer = 0 To A.Count - 1
Dim quanco As ctrlQuanCo = A(i)
If Not (quanco Is Nothing) Then
If (pos.Y - 50) = quanco.GetViTri().Y And (pos.X = quanco.GetViTri().X) Then
flag = False
Exit For
End If
End If
Next
'khi toi quan co cua dich lan 1 thi them vao, roi dung
For i As Integer = 0 To B.Count - 1
Dim quanco As ctrlQuanCo = B(i)
If Not (quanco Is Nothing) Then
If (pos.Y - 50) = quanco.GetViTri().Y And (pos.X = quanco.GetViTri().X) Then
mang.Add(New Point(pos.X, pos.Y - 50))
Exit While
End If
End If
Next
pos.Y -= 50
If flag <> False Then
mang.Add(New Point(pos.X, pos.Y))
End If
End While
'=========================
pos = Me.GetViTri()
flag = True
While ((pos.Y + 50) <= bottom) 'tang dong
For i As Integer = 0 To A.Count - 1
Dim quanco As ctrlQuanCo = A(i)
If Not (quanco Is Nothing) Then
If (pos.Y + 50) = quanco.GetViTri().Y And (pos.X = quanco.GetViTri().X) Then
flag = False
Exit For
End If
End If
Next
'khi toi quan co cua dich lan 1 thi them vao, roi dung
For i As Integer = 0 To B.Count - 1
Dim quanco As ctrlQuanCo = B(i)
If Not (quanco Is Nothing) Then
If (pos.Y + 50) = quanco.GetViTri().Y And (pos.X = quanco.GetViTri().X) Then
mang.Add(New Point(pos.X, pos.Y + 50))
Exit While
End If
End If
Next
pos.Y += 50
If flag <> False Then
mang.Add(New Point(pos.X, pos.Y))
End If
End While
'===============xet quan co Den===============
Else 'den
pos = Me.GetViTri()
flag = True
While ((pos.X - 48) >= left) 'giam cot
For i As Integer = 0 To B.Count - 1
Dim quanco As ctrlQuanCo = B(i)
If Not (quanco Is Nothing) Then
If ((pos.X - 48) = quanco.GetViTri().X) And (pos.Y = quanco.GetViTri().Y) Then
flag = False
Exit For
End If
End If
Next
'khi toi quan co cua dich lan 1 thi them vao, roi dung
For i As Integer = 0 To A.Count - 1
Dim quanco As ctrlQuanCo = A(i)
If Not (quanco Is Nothing) Then
If (pos.X - 48) = quanco.GetViTri().X And (pos.Y = quanco.GetViTri().Y) Then
mang.Add(New Point(pos.X - 48, pos.Y))
Exit While
End If
End If
Next
pos.X -= 48
'If flag = False Then
' Exit While
'End If
If flag <> False Then
mang.Add(New Point(pos.X, pos.Y))
End If
End While
'====================================
pos = Me.GetViTri()
flag = True
While ((pos.X + 48) <= right) 'tang cot
For i As Integer = 0 To B.Count - 1
Dim quanco As ctrlQuanCo = B(i)
If Not (quanco Is Nothing) Then
If (pos.X + 48) = quanco.GetViTri().X And (pos.Y = quanco.GetViTri().Y) Then
flag = False
Exit For
End If
End If
Next
'khi toi quan co cua dich lan 1 thi them vao, roi dung
For i As Integer = 0 To A.Count - 1
Dim quanco As ctrlQuanCo = A(i)
If Not (quanco Is Nothing) Then
If (pos.X + 48) = quanco.GetViTri().X And (pos.Y = quanco.GetViTri().Y) Then
mang.Add(New Point(pos.X + 48, pos.Y))
Exit While
End If
End If
Next
pos.X += 48
'If flag = False Then
' Exit While
'End If
If flag <> False Then
mang.Add(New Point(pos.X, pos.Y))
End If
End While
'====================================
pos = Me.GetViTri()
flag = True
While ((pos.Y - 50) >= top) 'giam dong
For i As Integer = 0 To B.Count - 1
Dim quanco As ctrlQuanCo = B(i)
If Not (quanco Is Nothing) Then
If (pos.Y - 50) = quanco.GetViTri().Y And (pos.X = quanco.GetViTri().X) Then
flag = False
Exit For
End If
End If
Next
'khi toi quan co cua dich lan 1 thi them vao, roi dung
For i As Integer = 0 To A.Count - 1
Dim quanco As ctrlQuanCo = A(i)
If Not (quanco Is Nothing) Then
If (pos.Y - 50) = quanco.GetViTri().Y And (pos.X = quanco.GetViTri().X) Then
mang.Add(New Point(pos.X, pos.Y - 50))
Exit While
End If
End If
Next
pos.Y -= 50
If flag <> False Then
mang.Add(New Point(pos.X, pos.Y))
End If
End While
'====================================
pos = Me.GetViTri()
flag = True
While ((pos.Y + 50) <= bottom) 'tang dong
If pos.Y = 303 Then
Dim thu As Boolean = True
End If
For i As Integer = 0 To B.Count - 1
Dim quanco As ctrlQuanCo = B(i)
If Not (quanco Is Nothing) Then
If (pos.Y + 50) = quanco.GetViTri().Y And (pos.X = quanco.GetViTri().X) Then
flag = False
Exit For
End If
End If
Next
'khi toi quan co cua dich lan 1 thi them vao, roi dung
For i As Integer = 0 To A.Count - 1
Dim quanco As ctrlQuanCo = A(i)
If Not (quanco Is Nothing) Then
If (pos.Y + 50) = quanco.GetViTri().Y And (pos.X = quanco.GetViTri().X) Then
mang.Add(New Point(pos.X, pos.Y + 50))
Exit While
End If
End If
Next
pos.Y += 50
If flag <> False Then
mang.Add(New Point(pos.X, pos.Y))
End If
End While
End If
Return mang
End Function
End Class