Visual CSharp .NET - Ayuda en juego de ping pong

 
Vista:
sin imagen de perfil

Ayuda en juego de ping pong

Publicado por Edvin Enrique (3 intervenciones) el 01/06/2014 23:32:35
Saludos.
Quisiera saber si me podrian ayudar con respecto a un codigo en c#. es un windows form
Es juego de ping pong y e tomado la idea de varios que e visto, tratando de unirlos ya que en alguno no tienen lo que quisiera.
Les estaria muy agradecido si me pudieran ayudar.

Aqui esta mas o menos como esta el aplicativo.


este es el codigo.

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 Ping_Pong
{
public partial class MainForm1 : Form
{
// 1 -> Derecha -1 -> Izquierda
// 1 -> Abajo -1 -> Arriba
private int dx = -1, dy = 1;

// Variables q contiene la ultima tecla pulsada por cierta pala
// para q el rebote se efectue en una o otra direcion
// 'u' (up) -> arriba 'd' (down) -> abajo
private char d1, d2;
public MainForm1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}
void reproducirSonido()
{
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = @"C:\WINDOWS\Media\ding.wav";
player.Play();
}

void Timer1Tick(object sender, EventArgs e)
{
// Movemos la "pelota"
pelota.Left += dx;
pelota.Top += dy;
/* Para el movimiento de la pelota
dx = pelota.Location.X >= this.ClientSize.Width ? -1 : dx;
dx = pelota.Location.X == 0 ? 1 : dx;*/

if (pelota.Location.X + 18 >= this.ClientSize.Width)
{
Timer1.Enabled = false;
MessageBox.Show("Gana el jugador 1", "Felicidades");
}
if (pelota.Location.X == 0)
{
Timer1.Enabled = false;
MessageBox.Show("Gana el jugador 2", "Felicidades");
}

// Si choca contra la parte inferior o el menú
dy = pelota.Location.Y + 50 >= this.ClientSize.Width ? -1 : dy;
dy = pelota.Location.Y == 25 ? 1 : dy;
// Si choca contra la pala1

if (pelota.Left == pala1.Left + pala1.Width)
{
reproducirSonido();
if (pelota.Top > pala1.Top && pelota.Top < dx =" 1;" dy =" d1" left ="="> pala2.Top && pelota.Top < dx =" -1;" dy =" d2" a =" arriba," z =" abajo" k =" arriba," m =" abajo" top =" 25;" d1 =" 'u';">= this.ClientSize.Height)
pala1.Top = this.ClientSize.Height - pala1.Height;
d1 = 'd';
break;

case 'K':
//La pala2
pala2.Top -= 10;
if (pala2.Top < top =" 25;" d2 =" 'u';">= this.ClientSize.Height)
pala2.Top = this.ClientSize.Height - pala2.Height;
d2 = 'd';
break;
}
}

private void BtnControles_Click(object sender, EventArgs e)
{
MessageBox.Show ("Pulsar las teclas A y K para subir y las teclas Z y M para bajar las respectivas paletas de losjugadores 1 y 2", "Controles");
}

private void BtnSalir_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder