Advertisement
Guest User

Juego tanques

a guest
Dec 21st, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 6.90 KB | None | 0 0
  1. Option Explicit Off
  2. Public Class Form1
  3.     Dim conteo As Integer = 90
  4.     Dim conteo2 As Integer = 420
  5.     Dim misil As New PictureBox
  6.     Dim fuerza As Integer = 1
  7.     Dim esfuerz As Integer = 1
  8.     Dim impulso As Integer = 1
  9.     Dim random As New Random
  10.     Dim objetivo(2) As Integer
  11.     Dim viento1 As New Random
  12.     Dim viento2 As New Random
  13.     Dim impulso2 As Integer = 1
  14.     Dim mivientorandom As New Random
  15.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  16.         If TextBox1.Text.Trim.Length = 0 Then
  17.             MessageBox.Show("Debe elegir la carga de TNT (de 1 a 200)", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Information)
  18.             Exit Sub
  19.         End If
  20.         If Val(TextBox1.Text) <= 0 Or Val(TextBox1.Text) > 200 Then
  21.             MessageBox.Show("El valor de la carga de TNT debe ser entre 1 y 200", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Information)
  22.             TextBox1.Focus()
  23.             Exit Sub
  24.         End If
  25.         Button1.Enabled = False
  26.         My.Computer.Audio.Play(My.Resources.disparo, AudioPlayMode.Background)
  27.         My.Settings.perdidas = My.Settings.perdidas + 1
  28.         My.Settings.Save()
  29.         'creo el misil
  30.         misil.Width = 20
  31.         misil.Height = 20
  32.         misil.BackColor = Color.White
  33.         misil.Image = ImageList1.Images(0)
  34.         misil.SizeMode = PictureBoxSizeMode.StretchImage
  35.         misil.Location = New Point(90, 420)
  36.         Me.Controls.Add(misil)
  37.         'disparo
  38.         Timer1.Enabled = True
  39.         fuerza = 420 - TextBox1.Text
  40.         impulso = TextBox2.Text
  41.         'selecciono y aplico el impulso
  42.         Select Case ComboBox1.Text
  43.             Case "Suave"
  44.                 impulso2 = 1
  45.             Case "Mediano"
  46.                 impulso2 = 3
  47.             Case "Fuerte"
  48.                 impulso2 = 6
  49.         End Select
  50.         Timer5.Enabled = True
  51.     End Sub
  52.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  53.         Timer1.Interval = impulso * 10
  54.         conteo = conteo + impulso2
  55.         conteo2 = conteo2 - 1
  56.         If conteo2.ToString.Contains("5") Or conteo2.ToString.Contains("2") Then
  57.             conteo = conteo + 3
  58.         End If
  59.         misil.Location = New Point(conteo, conteo2)
  60.         fuerza = 420 - TextBox1.Text
  61.         impulso = TextBox2.Text
  62.         If misil.Location.Y < fuerza Then
  63.             'desciende el misil
  64.             Timer1.Enabled = False
  65.             Timer2.Enabled = True
  66.         End If
  67.     End Sub
  68.     Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
  69.         Timer1.Interval = impulso
  70.         conteo = conteo + 1
  71.         conteo2 = conteo2 + 1
  72.         If conteo.ToString.Contains("5") Or conteo.ToString.Contains("2") Then
  73.             conteo = conteo + 8
  74.         End If
  75.         If conteo.ToString.Contains("5") Or conteo.ToString.Contains("2") Then
  76.             conteo2 = conteo2 + 7
  77.         End If
  78.         misil.Location = New Point(conteo, conteo2)      
  79.     End Sub
  80.     Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
  81.         My.Settings.Save()
  82.     End Sub
  83.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  84.         'muestro las partidas ganadas y perdidas
  85.         Label11.Text = My.Settings.ganadas
  86.         Label12.Text = My.Settings.perdidas - My.Settings.ganadas
  87.         'posiciono el enemigo
  88.         Me.SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.AllPaintingInWmPaint, True)
  89.         pos = random.Next(500, 1000)
  90.         PictureBox2.Location = New Point(pos, 387)
  91.         objetivo(0) = PictureBox2.Location.X
  92.         objetivo(1) = PictureBox2.Location.Y
  93.         'establezco la intensidad del viento
  94.         unidad = mivientorandom.Next(1, 10)
  95.         TextBox2.Text = unidad
  96.         Label5.Text = unidad.ToString
  97.         'calculo la distancia del objetivo (inicial)
  98.         inicial = PictureBox2.Location.X - 32
  99.         Label7.Text = inicial.ToString
  100.     End Sub
  101.     Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
  102.         'calculo si hizo impacto
  103.         If misil.Location.X >= PictureBox2.Location.X And misil.Location.X <= PictureBox2.Location.X + 84 + 84 And misil.Location.Y >= 387 And misil.Location.Y <= 387 + 50 Or misil.Location.X + 20 >= PictureBox2.Location.X And misil.Location.X + 20 <= PictureBox2.Location.X + 84 And misil.Location.Y >= 387 And misil.Location.Y <= 387 + 50 Then
  104.             Label3.Text = "acerto!!!"
  105.             My.Settings.ganadas = My.Settings.ganadas + 1
  106.             My.Settings.Save()
  107.             Timer1.Enabled = False
  108.             Timer2.Enabled = False
  109.             Timer4.Enabled = False
  110.             PictureBox2.Visible = False
  111.             PictureBox3.Location = New Point(PictureBox2.Location.X, PictureBox2.Location.Y - 35)
  112.             PictureBox3.Visible = True
  113.             misil.Visible = False
  114.             My.Computer.Audio.Play(My.Resources.superbomba, AudioPlayMode.Background)
  115.             Label11.Text = CInt(Label11.Text + 1).ToString
  116.             Exit Sub
  117.         End If
  118.     End Sub
  119.     Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer5.Tick
  120.         'con esto mido la distancia entre el misil y el objetivo y la muestro
  121.         mipunta = misil.Location.X + 20
  122.         mipuntaobjetivo = PictureBox2.Location.X
  123.         midistancia = mipuntaobjetivo - mipunta
  124.         Label7.Text = midistancia.ToString + " Metros"
  125.         If midistancia <= 0 Then
  126.             Label7.Text = "0 Metros"
  127.         End If
  128.         If misil.Location.Y > 465 Then
  129.             Label7.Text = "0 metros"
  130.         End If
  131.         If misil.Location.X > 1181 Then
  132.             Label7.Text = "0 metros"
  133.         End If
  134.     End Sub
  135.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  136.         'vuelvo a ejecutar el software para resetear los datos
  137.         miruta = My.Application.Info.DirectoryPath + "\juego.exe"
  138.         System.Diagnostics.Process.Start(miruta)
  139.         End
  140.     End Sub
  141.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  142.         'reseteo los contadores de las partidas ganadas y perdidas
  143.         If MessageBox.Show("Esta seguro de que desea borrar los contadores?", "Aviso", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
  144.             My.Settings.ganadas = 0
  145.             My.Settings.perdidas = 0
  146.             My.Settings.Save()
  147.             Label11.Text = "0"
  148.             Label12.Text = "0"
  149.             miruta = My.Application.Info.DirectoryPath + "\juego.exe"
  150.             System.Diagnostics.Process.Start(miruta)
  151.             End
  152.         End If
  153.     End Sub
  154. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement