Sei sulla pagina 1di 3

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace juego_flappy
{
public partial class Form1 : Form
{
int ContadorMovimiento = 1;
bool VolarArriba = false;
int Distancia = 0;
Random posicionRandom = new Random();

public Form1()
{
InitializeComponent();
this.KeyPreview = true;
IniciarJuego();

}
public void IniciarJuego() {
Player.Location = new Point(19, 225);
Distancia = posicionRandom.Next(-160, 189);
tuboArriba.Location = new Point (270, -173 -Distancia);
TuboAbajo.Location = new Point(270, -319 - Distancia);
puntaje.Text = "0";

private void Player_Click(object sender, EventArgs e)


{

private void timer1_Tick(object sender, EventArgs e)


{
int CantidadMovimientos = 5;
if (ContadorMovimiento <= CantidadMovimientos)
{
Player.Image = Properties.Resources.mop2;
ContadorMovimiento++;
}
if ((ContadorMovimiento > CantidadMovimientos / 2) &&
(ContadorMovimiento <= CantidadMovimientos * 2))
{
Player.Image = Properties.Resources.mop2;
ContadorMovimiento++;
}
ContadorMovimiento = (ContadorMovimiento > CantidadMovimientos * 2) ? 0
: ContadorMovimiento;
int ly = Player.Location.Y;
int lx = Player.Location.X;

if (VolarArriba)
{
ly = ly - 15;
VolarArriba = false;
}
else {
ly++;

Player.Location = new Point(Player.Location.X, ly);

if ((Player.Bounds.IntersectsWith(barra.Bounds)) ||
(Player.Bounds.IntersectsWith(tuboArriba.Bounds)) ||
(Player.Bounds.IntersectsWith(TuboAbajo.Bounds)))
{
IniciarJuego();
}

puntaje.Location = new Point(Player.Location.X + 30, Player.Location.Y


- 25);
puntaje.Text = (tuboArriba.Location.X == Player.Location.X) ?
Convert.ToString ((Convert.ToInt32(puntaje.Text) + 1)).ToString() : puntaje.Text;

private void Form1_KeyPress(object sender, KeyPressEventArgs e)


{
if(e.KeyChar==Convert.ToChar(Keys.Space))
VolarArriba = true;
}

private void timer2_Tick(object sender, EventArgs e)


{
if (TuboAbajo.Location.X > -140)
{
TuboAbajo.Location = new Point ((TuboAbajo.Location.X) - 1,
TuboAbajo.Location.Y);
tuboArriba.Location = new Point ((tuboArriba.Location.X) - 1,
tuboArriba.Location.Y);

}
else{
Distancia = posicionRandom.Next(-170, 118);
TuboAbajo.Location = new Point (400, 319 + Distancia);
tuboArriba.Location = new Point (400, -173 + Distancia);
}
}

private void timer3_Tick(object sender, EventArgs e)


{
barra.Location = (barra.Location.X > -480) ? new
Point((barra.Location.X) - 1, barra.Location.Y) : barra.Location = new Point(-9,
barra.Location.Y);
}
}
}

Potrebbero piacerti anche