Ejercicios de Programación Aplicada: Ejercicio 1
Ejercicios de Programación Aplicada: Ejercicio 1
Ejercicio 1
1.1 Código
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 ejercicio24
{
public partial class Form1 : Form
{
int a, b, c, d;
int a1, b1, c1, d1;
int vg = 0, vg1 = 0;
int pulsap = 0;
int n2;
int acierto = 0;
Random r = new Random();
int[] al = new int[4];
int[] al2 = new int[4];
public Form1()
{
InitializeComponent();
}
int xd;
pictureBox1.Image = Image.FromFile(Application.StartupPath +
"/"+a+".jpg");
if (pulsap == 0)
{
pulsap++;
pulsa1(a);
vg = 1;
}
else if (pulsap == 1)
{
vg1 = 1;
pulsa2(a);
pulsap = 0;
}
}
vg = 9;
}
else if (pulsap == 1)
{
vg1 = 9;
pulsa2(b1);
pulsap = 0;
}
}
if (pulsap == 0)
{
pulsap++;
pulsa1(b);
vg = 2;
}
else if (pulsap == 1) {
vg1 = 2;
pulsa2(b);
pulsap = 0;
}
}
}
}
MessageBox.Show("Felicidades! GANASTE");
label2.Text = "0";
volteartodo();
reiniciar();
}
}
else
{
//ventanas a sus lugares
timer1.Enabled = true;
}
}
int i = 0;
int z = 0;
generar();
asignar();
volteartodo();
2.1 Código
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 Calle_peatona
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Boolean m;
int s = 10;
private void Form1_Load(object sender, EventArgs e)
{
label2.ForeColor = Color.Red;
pictureBox6.BackColor = Color.Red;
label1.Text = "";
label2.Text = "";
pictureBox3.BackColor = Color.White;
timer3.Enabled = true;
pictureBox2.BackColor = Color.Green;
timer2.Enabled = true;
timer2.Interval = timer2.Interval * s;
timer1.Enabled = true;
timer4.Interval = timer4.Interval * (s-1);
timer4.Enabled = true;
label3 = label2;
timer5.Interval = timer5.Interval * 2;
timer5.Enabled = true;
}
if (pictureBox2.BackColor == Color.Green)
{
label1.ForeColor = Color.Red;
pictureBox2.BackColor = Color.Black;
pictureBox4.BackColor = Color.Red;
}
else if (pictureBox4.BackColor == Color.Red) {
label1.ForeColor = Color.Green;
pictureBox2.BackColor = Color.Green;
pictureBox4.BackColor = Color.Black;
}
}
}
int co = 1;
int co2 = 0;
private void timer3_Tick(object sender, EventArgs e)
{
if (co < s|co2<s)
{
if (pictureBox2.BackColor == Color.Green)
{
co++;
co2 = 0;
label1.Text = Convert.ToString(s - co+1);
label2.Visible = false;
label1.Visible = true;
}
else if (pictureBox4.BackColor == Color.Red)
{
label1.Visible = false;
label2.Visible = true;
co2++;
co = 0;
label2.Text = Convert.ToString(s - co2+1);
}
}
}
int sw;
Boolean cru;
private void timer1_Tick(object sender, EventArgs e)
{
if (m == true)
{
if (cru == true)
{
if (sw == 0)
{
if (pictureBox5.Left + pictureBox5.Width <= 670)
{
pictureBox5.Left = pictureBox5.Left + 50;
}
else { sw = 1; cru = false; }
}
else if (cru == true)
{
if
(pictureBox5.Left >= 50)
{
pictureBox5.Left = pictureBox5.Left - 50;
}
else
{
sw = 0; cru = false;
}
}
}
}
else { }
}
int co3=0;
int coa3 = 0;
int sui;
private void timer4_Tick(object sender, EventArgs e)
{
if (pictureBox8.BackColor == Color.Green)
{
pictureBox8.BackColor = Color.Black;
pictureBox7.BackColor = Color.Orange;
sui = 0;
}
else if (pictureBox6.BackColor == Color.Red)
{
sui = 1;
pictureBox7.BackColor = Color.Orange;
pictureBox6.BackColor = Color.Black;
}
else if (sui == 1)
{
pictureBox7.BackColor = Color.Black;
pictureBox8.BackColor = Color.Green;
}
}
}
}
}
2.2 Prueba
3.Ejercicio
3.1 Código
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 PROYECTO_PING_PONG
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int VELOCIDAD = 15;
int PUNTAJE = 0;
bool ARRIBA;
bool IZQUIERDA;
}
if (PUNTAJE >= 30 && PUNTAJE <31)
{
timer1.Enabled = false;
MessageBox.Show("SU PUNTAJE ES: " + PUNTAJE.ToString());
MessageBox.Show("GANASTE");
this.Close();
}
//MOVIMIENTO DE LA PELOTA.
if (IZQUIERDA==true)
{
pictureBox1.Left += VELOCIDAD; //VA PARA LA DERECHA
}
else
{
pictureBox1.Left -= VELOCIDAD;// VA PARA LA IZQUIERDA
}
if (ARRIBA==true)
{
pictureBox1.Top += VELOCIDAD; //VA PARA ARRIBA
}
else
{
pictureBox1.Top -= VELOCIDAD;// VA PARA ABAJO
}
4.1 Código
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _3enraya
{
class analizar
{
public int v1=2, v2=9, v3=9, v4=9, v5=9, v6=9, v7=9, v8=9, v9=9;
public Boolean ganador = false; public int g;
public analizar(int v1, int v2, int v3, int v4, int v5, int v6, int v7,
int v8, int v9) {
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;
this.v4 = v4;
this.v5 = v5;
this.v6 = v6;
this.v7 = v7;
this.v8 = v8;
this.v9 = v9;
m1();
m2();
m3();
m4();
m5();
m6();
m7();
m8();
}
if (v7 == 1) {
c++;
}
if (v5 == 1) {
c++;
}
if (v3 == 1) {
c++;
}
if (c==3) {
ganador = true;
g = 1;
}
if (v7 == 0)
{
c1++;
}
if (v5 == 0)
{
c1++;
}
if (v3 == 0)
{
c1++;
}
if (c1 == 3)
{
ganador = true;
g = 0;
}
}
if (v1 == 1)
{
c++;
}
if (v5 == 1)
{
c++;
}
if (v9 == 1)
{
c++;
}
if (c == 3)
{
ganador = true;
g = 1;
}
if (v1 == 0)
{
c1++;
}
if (v5 == 0)
{
c1++;
}
if (v9 == 0)
{
c1++;
}
if (c1 == 3)
{
ganador = true;
g = 0;
}
}
if (v1 == 1)
{
c++;
}
if (v2 == 1)
{
c++;
}
if (v3 == 1)
{
c++;
}
if (c == 3)
{
ganador = true;
g = 1;
}
if (v1 == 0)
{
c1++;
}
if (v2 == 0)
{
c1++;
}
if (v3 == 0)
{
c1++;
}
if (c1 == 3)
{
ganador = true;
g = 0;
}
}
if (v4 == 1)
{
c++;
}
if (v5 == 1)
{
c++;
}
if (v6 == 1)
{
c++;
}
if (c == 3)
{
ganador = true;
g = 1;
}
if (v4 == 0)
{
c1++;
}
if (v5 == 0)
{
c1++;
}
if (v6 == 0)
{
c1++;
}
if (c1 == 3)
{
ganador = true;
g = 0;
}
}
if (v7 == 1)
{
c++;
}
if (v8 == 1)
{
c++;
}
if (v9 == 1)
{
c++;
}
if (c == 3)
{
ganador = true;
g = 1;
}
if (v7 == 0)
{
c1++;
}
if (v8 == 0)
{
c1++;
}
if (v9 == 0)
{
c1++;
}
if (c1 == 3)
{
ganador = true;
g = 0;
}
}
if (v2 == 1)
{
c++;
}
if (v5 == 1)
{
c++;
}
if (v8 == 1)
{
c++;
}
if (c == 3)
{
ganador = true;
g = 1;
}
if (v2 == 0)
{
c1++;
}
if (v5 == 0)
{
c1++;
}
if (v8 == 0)
{
c1++;
}
if (c1 == 3)
{
ganador = true;
g = 0;
}
}
if (v1 == 1)
{
c++;
}
if (v4 == 1)
{
c++;
}
if (v7 == 1)
{
c++;
}
if (c == 3)
{
ganador = true;
g = 1;
}
if (v1 == 0)
{
c1++;
}
if (v4 == 0)
{
c1++;
}
if (v7 == 0)
{
c1++;
}
if (c1 == 3)
{
ganador = true;
g = 0;
}
}
public void m8() {
int c = 0;
int c1 = 0;
if (v3 == 1)
{
c++;
}
if (v6 == 1)
{
c++;
}
if (v9 == 1)
{
c++;
}
if (c == 3)
{
ganador = true;
g = 1;
}
if (v3 == 0)
{
c1++;
}
if (v6 == 0)
{
c1++;
}
if (v9 == 0)
{
c1++;
}
if (c1 == 3)
{
ganador = true;
g = 0;
}
}
4.2. Prueba