|
Dobrý den, O téhle hře kde se má objekt vyhýbat ostatním letícím objektům jsem už zde psal. Problikávalo mi to totiž, ale nakonec jsem to vyřešil po svém. Nyní se kód trošku rozrostl. Abych to zpřehlednil tak každý protiletící objekt má kód jak má letět(je to vlastně u všech stejné). Protiletících objektů je celkem 15, kdy každý se vykresluje na jiné souřadnici. Až proletí celou hrací plochou a hráč se jim vyhne má jim cyklus přiřadit nové souřadnice a znovu je vykreslit(a tak to jde pořád dokola). Když ale takový cyklus napíšu tak mi zamrzne celý program. Cyklus jsem dával do všech možných procedur, ale pořád nejde. Vlastně to pojede pořád dokola.
Public Class Form1
'směry pohybu stíhačky
Enum SMERY
Nahoru = 1
Dolu = 2
Doleva = 3
Doprava = 4
Zadne = 5
End Enum
'souřadnice
Structure XY
Dim x As Integer
Dim y As Integer
End Structure
'informace o poli
Enum POLE
space = 1
killer = 2
End Enum
'směry stíhačky
Dim Smer As SMERY
'informace o políčku
Dim Plocha(500, 600) As POLE
'součastná pozice stíhačky
Dim Space As XY
'pozice killerů
Dim Killer, Killer2, Killer3, Killer4, Killer5, Killer6, Killer7, Killer8, Killer9, Killer01, Killer011, Killer012, Killer013, Killer014, Killer015 As XY
Private Sub Form1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Dim g As Graphics = PictureBox1.CreateGraphics
Select Case e.KeyCode
Case Keys.Up
Smer = SMERY.Nahoru
Case Keys.Down
Smer = SMERY.Dolu
Case Keys.Right
Smer = SMERY.Doprava
Case Keys.Left
Smer = SMERY.Doleva
End Select
End Sub
Private Sub Form1_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
Select Case e.KeyCode
Case Keys.Up
Smer = SMERY.Zadne
Case Keys.Down
Smer = SMERY.Zadne
Case Keys.Right
Smer = SMERY.Zadne
Case Keys.Left
Smer = SMERY.Zadne
End Select
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
Killer_01.Enabled = True
Killer_02.Enabled = True
Killer_03.Enabled = True
Killer_04.Enabled = True
Killer_05.Enabled = True
Killer_06.Enabled = True
Killer_07.Enabled = True
Killer_08.Enabled = True
Killer_09.Enabled = True
Killer_10.Enabled = True
Killer11.Enabled = True
Killer12.Enabled = True
Killer13.Enabled = True
Killer14.Enabled = True
Killer15.Enabled = True
'nastavení pozice stíhačky a killerů
Space.x = 6 * 30
Space.y = 13 * 30
Killer.x = 0 * 30 : Killer2.x = 1 * 30 : Killer3.x = 3 * 30 : Killer4.x = 5 * 30 : Killer5.x = 6 * 30
Killer.y = 0 * 30 : Killer2.y = 2 * 30 : Killer3.y = 1 * 30 : Killer4.y = 3 * 30 : Killer5.y = 4 * 30
Killer6.x = 7 * 30 : Killer7.x = 8 * 30 : Killer8.x = 10 * 30 : Killer9.x = 11 * 30 : Killer01.x = 12 * 30
Killer6.y = 3 * 30 : Killer7.y = 2 * 30 : Killer8.y = 0 * 30 : Killer9.y = 1 * 30 : Killer01.y = 2 * 30
Killer011.x = 2 * 30 : Killer012.x = 10 * 30 : Killer013.x = 8 * 30 : Killer014.x = 9 * 30 : Killer015.x = 1 * 30
Killer011.y = 0 * 30 : Killer012.y = 2 * 30 : Killer013.y = 3 * 30 : Killer014.y = 2 * 30 : Killer015.y = 1 * 30
End Sub
Private Sub PictureBox1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
'pozadí vybarvit na bílou barvu
e.Graphics.Clear(Color.Black)
'vykreslit stíhačku
e.Graphics.DrawImage(ImageList1.Images(0), 6 * 30, 13 * 30)
End Sub
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Dim g As Graphics = PictureBox1.CreateGraphics
'vykreslit černou barvu původní pozici stíhačky
g.FillRectangle(Brushes.Black, Space.x, Space.y, 30, 30)
'vyhodnotit podmínky nárazu
If Space.x < 0 Or Space.y < 0 Or Space.x > 12 * 30 Or Space.y > 15 * 30 Then GameOver()
If Plocha(Space.x, Space.y) = POLE.killer Then GameOver()
'zjistit směry
Select Case Smer
Case SMERY.Nahoru
Space.y = Space.y - 30
Case SMERY.Dolu
Space.y = Space.y + 30
Case SMERY.Doprava
Space.x = Space.x + 30
Case SMERY.Doleva
Space.x = Space.x - 30
Case SMERY.Zadne
Space.x = Space.x
Space.y = Space.y
End Select
'nakreslit novou stíhačku
g.DrawImage(ImageList1.Images(0), Space.x, Space.y)
Plocha(Space.x, Space.y) = POLE.space
End Sub
Private Sub Killer_01_Tick(sender As System.Object, e As System.EventArgs) Handles Killer_01.Tick
Dim g As Graphics = PictureBox1.CreateGraphics
'vykreslit černou barvu původní pozici killera
g.FillRectangle(Brushes.Black, Killer.x, Killer.y, 30, 30)
Plocha(Killer.x, Killer.y) = POLE.killer
Killer.x = Killer.x
Killer.y = Killer.y + 30
Plocha(Killer.x, Killer.y) = POLE.killer
'nakreslit nového killera
g.DrawImage(ImageList1.Images(1), Killer.x, Killer.y)
If Killer.y > 17 * 30 Then
Killer_01.Enabled = False
End If
End Sub
Private Sub Killer_02_Tick(sender As System.Object, e As System.EventArgs) Handles Killer_02.Tick
Dim g As Graphics = PictureBox1.CreateGraphics
'vykreslit černou barvu původní pozici killera
g.FillRectangle(Brushes.Black, Killer2.x, Killer2.y, 30, 30)
Plocha(Killer2.x, Killer2.y) = POLE.killer
Killer2.x = Killer2.x
Killer2.y = Killer2.y + 30
Plocha(Killer2.x, Killer2.y) = POLE.killer
'nakreslit nového killera
g.DrawImage(ImageList1.Images(1), Killer2.x, Killer2.y)
If Killer2.y > 17 * 30 Then
Killer_02.Enabled = False
End If
End Sub
Private Sub Killer_03_Tick(sender As System.Object, e As System.EventArgs) Handles Killer_03.Tick
Dim g As Graphics = PictureBox1.CreateGraphics
'vykreslit černou barvu původní pozici killera
g.FillRectangle(Brushes.Black, Killer3.x, Killer3.y, 30, 30)
Plocha(Killer3.x, Killer3.y) = POLE.killer
Killer3.x = Killer3.x
Killer3.y = Killer3.y + 30
Plocha(Killer3.x, Killer3.y) = POLE.killer
'nakreslit nového killera
g.DrawImage(ImageList1.Images(1), Killer3.x, Killer3.y)
If Killer3.y > 17 * 30 Then
Killer_03.Enabled = False
End If
End Sub
Private Sub Killer_04_Tick(sender As System.Object, e As System.EventArgs) Handles Killer_04.Tick
Dim g As Graphics = PictureBox1.CreateGraphics
'vykreslit černou barvu původní pozici killera
g.FillRectangle(Brushes.Black, Killer4.x, Killer4.y, 30, 30)
Plocha(Killer4.x, Killer4.y) = POLE.killer
Killer4.x = Killer4.x
Killer4.y = Killer4.y + 30
Plocha(Killer4.x, Killer4.y) = POLE.killer
'nakreslit nového killera
g.DrawImage(ImageList1.Images(1), Killer4.x, Killer4.y)
If Killer4.y > 17 * 30 Then
Killer_04.Enabled = False
End If
End Sub
Private Sub Killer_05_Tick(sender As System.Object, e As System.EventArgs) Handles Killer_05.Tick
Dim g As Graphics = PictureBox1.CreateGraphics
'vykreslit černou barvu původní pozici killera
g.FillRectangle(Brushes.Black, Killer5.x, Killer5.y, 30, 30)
Plocha(Killer5.x, Killer5.y) = POLE.killer
Killer5.x = Killer5.x
Killer5.y = Killer5.y + 30
Plocha(Killer5.x, Killer5.y) = POLE.killer
'nakreslit nového killera
g.DrawImage(ImageList1.Images(1), Killer5.x, Killer5.y)
If Killer5.y > 17 * 30 Then
Killer_05.Enabled = False
End If
End Sub
Private Sub Killer_06_Tick(sender As System.Object, e As System.EventArgs) Handles Killer_06.Tick
Dim g As Graphics = PictureBox1.CreateGraphics
'vykreslit černou barvu původní pozici killera
g.FillRectangle(Brushes.Black, Killer6.x, Killer6.y, 30, 30)
Plocha(Killer6.x, Killer6.y) = POLE.killer
Killer6.x = Killer6.x
Killer6.y = Killer6.y + 30
Plocha(Killer6.x, Killer6.y) = POLE.killer
'nakreslit nového killera
g.DrawImage(ImageList1.Images(1), Killer6.x, Killer6.y)
If Killer6.y > 17 * 30 Then
Killer_06.Enabled = False
End If
End Sub
Private Sub Killer_07_Tick(sender As System.Object, e As System.EventArgs) Handles Killer_07.Tick
Dim g As Graphics = PictureBox1.CreateGraphics
'vykreslit černou barvu původní pozici killera
g.FillRectangle(Brushes.Black, Killer7.x, Killer7.y, 30, 30)
Plocha(Killer7.x, Killer7.y) = POLE.killer
Killer7.x = Killer7.x
Killer7.y = Killer7.y + 30
Plocha(Killer7.x, Killer7.y) = POLE.killer
'nakreslit nového killera
g.DrawImage(ImageList1.Images(1), Killer7.x, Killer7.y)
If Killer7.y > 17 * 30 Then
Killer_07.Enabled = False
End If
End Sub
Private Sub Killer_08_Tick(sender As System.Object, e As System.EventArgs) Handles Killer_08.Tick
Dim g As Graphics = PictureBox1.CreateGraphics
'vykreslit černou barvu původní pozici killera
g.FillRectangle(Brushes.Black, Killer8.x, Killer8.y, 30, 30)
Plocha(Killer8.x, Killer8.y) = POLE.killer
Killer8.x = Killer8.x
Killer8.y = Killer8.y + 30
Plocha(Killer8.x, Killer8.y) = POLE.killer
'nakreslit nového killera
g.DrawImage(ImageList1.Images(1), Killer8.x, Killer8.y)
If Killer8.y > 17 * 30 Then
Killer_08.Enabled = False
End If
End Sub
Private Sub Killer_09_Tick(sender As System.Object, e As System.EventArgs) Handles Killer_09.Tick
Dim g As Graphics = PictureBox1.CreateGraphics
'vykreslit černou barvu původní pozici killera
g.FillRectangle(Brushes.Black, Killer9.x, Killer9.y, 30, 30)
Plocha(Killer9.x, Killer9.y) = POLE.killer
Killer9.x = Killer9.x
Killer9.y = Killer9.y + 30
Plocha(Killer9.x, Killer9.y) = POLE.killer
'nakreslit nového killera
g.DrawImage(ImageList1.Images(1), Killer9.x, Killer9.y)
If Killer9.y > 17 * 30 Then
Killer_09.Enabled = False
End If
End Sub
Private Sub Killer_10_Tick(sender As System.Object, e As System.EventArgs) Handles Killer_10.Tick
Dim g As Graphics = PictureBox1.CreateGraphics
'vykreslit černou barvu původní pozici killera
g.FillRectangle(Brushes.Black, Killer01.x, Killer01.y, 30, 30)
Plocha(Killer01.x, Killer01.y) = POLE.killer
Killer01.x = Killer01.x
Killer01.y = Killer01.y + 30
Plocha(Killer01.x, Killer01.y) = POLE.killer
'nakreslit nového killera
g.DrawImage(ImageList1.Images(1), Killer01.x, Killer01.y)
If Killer01.y > 17 * 30 Then
Killer_10.Enabled = False
End If
End Sub
Private Sub Killer11_Tick(sender As System.Object, e As System.EventArgs) Handles Killer11.Tick
Dim g As Graphics = PictureBox1.CreateGraphics
'vykreslit černou barvu původní pozici killera
g.FillRectangle(Brushes.Black, Killer011.x, Killer011.y, 30, 30)
Plocha(Killer011.x, Killer011.y) = POLE.killer
Killer011.x = Killer011.x
Killer011.y = Killer011.y + 30
Plocha(Killer011.x, Killer011.y) = POLE.killer
'nakreslit nového killera
g.DrawImage(ImageList1.Images(1), Killer011.x, Killer011.y)
If Killer011.y > 17 * 30 Then
Killer11.Enabled = False
End If
End Sub
Private Sub Killer12_Tick(sender As System.Object, e As System.EventArgs) Handles Killer12.Tick
Dim g As Graphics = PictureBox1.CreateGraphics
'vykreslit černou barvu původní pozici killera
g.FillRectangle(Brushes.Black, Killer012.x, Killer012.y, 30, 30)
Plocha(Killer012.x, Killer012.y) = POLE.killer
Killer012.x = Killer012.x
Killer012.y = Killer012.y + 30
Plocha(Killer012.x, Killer012.y) = POLE.killer
'nakreslit nového killera
g.DrawImage(ImageList1.Images(1), Killer012.x, Killer012.y)
If Killer012.y > 17 * 30 Then
Killer12.Enabled = False
End If
End Sub
Private Sub Killer13_Tick(sender As System.Object, e As System.EventArgs) Handles Killer13.Tick
Dim g As Graphics = PictureBox1.CreateGraphics
'vykreslit černou barvu původní pozici killera
g.FillRectangle(Brushes.Black, Killer013.x, Killer013.y, 30, 30)
Plocha(Killer013.x, Killer013.y) = POLE.killer
Killer013.x = Killer013.x
Killer013.y = Killer013.y + 30
Plocha(Killer013.x, Killer013.y) = POLE.killer
'nakreslit nového killera
g.DrawImage(ImageList1.Images(1), Killer013.x, Killer013.y)
If Killer013.y > 17 * 30 Then
Killer13.Enabled = False
End If
End Sub
Private Sub Killer14_Tick(sender As System.Object, e As System.EventArgs) Handles Killer14.Tick
Dim g As Graphics = PictureBox1.CreateGraphics
'vykreslit černou barvu původní pozici killera
g.FillRectangle(Brushes.Black, Killer014.x, Killer014.y, 30, 30)
Plocha(Killer014.x, Killer014.y) = POLE.killer
Killer014.x = Killer014.x
Killer014.y = Killer014.y + 30
Plocha(Killer014.x, Killer014.y) = POLE.killer
'nakreslit nového killera
g.DrawImage(ImageList1.Images(1), Killer014.x, Killer014.y)
If Killer014.y > 17 * 30 Then
Killer14.Enabled = False
End If
End Sub
Private Sub Killer15_Tick(sender As System.Object, e As System.EventArgs) Handles Killer15.Tick
Dim g As Graphics = PictureBox1.CreateGraphics
'vykreslit černou barvu původní pozici killera
g.FillRectangle(Brushes.Black, Killer015.x, Killer015.y, 30, 30)
Plocha(Killer015.x, Killer015.y) = POLE.killer
Killer015.x = Killer015.x
Killer015.y = Killer015.y + 30
Plocha(Killer015.x, Killer015.y) = POLE.killer
'nakreslit nového killera
g.DrawImage(ImageList1.Images(1), Killer015.x, Killer015.y)
If Killer015.y > 17 * 30 Then
Killer15.Enabled = False
End If
End Sub
Public Sub GameOver()
Dim g As Graphics = PictureBox1.CreateGraphics
'konec hry
Timer1.Enabled = False
Killer_01.Enabled = False
Killer_02.Enabled = False
Killer_03.Enabled = False
Killer_04.Enabled = False
Killer_05.Enabled = False
Killer_06.Enabled = False
Killer_07.Enabled = False
Killer_08.Enabled = False
Killer_09.Enabled = False
Killer_10.Enabled = False
Killer11.Enabled = False
Killer12.Enabled = False
Killer13.Enabled = False
Killer14.Enabled = False
Killer15.Enabled = False
'přebarvit pole poloprůhledně
g.FillRectangle(New SolidBrush(Color.FromArgb(128, Color.LightBlue)), 0, 0, 450, 510)
'napsat text
Dim f As New Font(System.Drawing.FontFamily.GenericSansSerif, 40, FontStyle.Underline)
g.DrawString("KONEC HRY", f, Brushes.Black, 35, 190)
End Sub
'zde je cyklus
Public Sub kontrola()
While Killer_01.Enabled = False And Killer_02.Enabled = False And Killer_03.Enabled = False And Killer_04.Enabled = False And Killer_05.Enabled = False And Killer_06.Enabled = False And Killer_07.Enabled = False And Killer_08.Enabled = False And Killer_08.Enabled = False And Killer_09.Enabled = False And Killer_10.Enabled = False And Killer11.Enabled = False And Killer12.Enabled = False And Killer13.Enabled = False And Killer14.Enabled = False And Killer15.Enabled = False
Killer.x = 0 * 30 : Killer2.x = 1 * 30 : Killer3.x = 3 * 30 : Killer4.x = 5 * 30 : Killer5.x = 6 * 30
Killer.y = 0 * 30 : Killer2.y = 2 * 30 : Killer3.y = 1 * 30 : Killer4.y = 3 * 30 : Killer5.y = 4 * 30
Killer6.x = 7 * 30 : Killer7.x = 8 * 30 : Killer8.x = 10 * 30 : Killer9.x = 11 * 30 : Killer01.x = 12 * 30
Killer6.y = 3 * 30 : Killer7.y = 2 * 30 : Killer8.y = 0 * 30 : Killer9.y = 1 * 30 : Killer01.y = 2 * 30
Killer011.x = 2 * 30 : Killer012.x = 10 * 30 : Killer013.x = 8 * 30 : Killer014.x = 9 * 30 : Killer015.x = 1 * 30
Killer011.y = 0 * 30 : Killer012.y = 2 * 30 : Killer013.y = 3 * 30 : Killer014.y = 2 * 30 : Killer015.y = 1 * 30
End While
End Sub
End Class
|