using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PracticaAplicadaI
{
public partial class PinPon : Form
{
public PinPon()
{
InitializeComponent();
}
private void PinPon_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
timer2.Enabled = true;
Random r = new Random();
pictureBox1.Location = new Point(0, r.Next(this.Height));
}
bool movDer, movArrib;
private void timer1_Tick(object sender, EventArgs e)
{
if (movDer == true)
{
if (pictureBox1.Left <= this.ClientRectangle.Width -
pictureBox1.Width)
pictureBox1.Left += 2;
else
movDer = false;
}
else
{
if (pictureBox1.Left >= 0)
pictureBox1.Left -= 2;
else
movDer = true;
}
if (movArrib == true)
{
if (pictureBox1.Top >= 0)
pictureBox1.Top -= 2;
else
movArrib = false;
}
else
pictureBox1.Top += 2;
//rebote de la pelota
if (movArrib == true)
{
if (pictureBox1.Top >= 0)
pictureBox1.Top -= 2;
else
movArrib = false;
}
if (pictureBox1.Top + pictureBox1.Height >= panel1.Top &&
pictureBox1.Top + pictureBox1.Height <= panel1.Top + panel1.Height
&&
pictureBox1.Left + pictureBox1.Width >= panel1.Left &&
pictureBox1.Left + pictureBox1.Width <= panel1.Left + panel1.Width)
{
movArrib = true;
}
}
//Cronometro del juego
int i = 0;
private void timer2_Tick(object sender, EventArgs e)
{
i++;
if (i > 0 && i <= 9)
label1.Text = "Tiempo: " + "0" + i.ToString();
else
label1.Text = "Tiempo: " + i.ToString();
if (i >= 30)
{
timer1.Enabled = false;
timer2.Stop();
MessageBox.Show("Ganaste!!!");
}
}
//Movimiento del panel hacia la izquierda y derecha
private void PinPon_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Left && panel1.Left > 0)
panel1.Left -= 7;
else if (e.KeyCode == Keys.Right && panel1.Left <
this.ClientRectangle.Width - panel1.Width)
panel1.Left += 7;
}
}
}