You are on page 1of 9

UNIVERSIDAD PRIVADA SERGIO

SEGIO BERNALES
FACULTAD DE INGENIERIA
ESCUELA ACADEMICA PROFESIONAL DE
INGENIRIA DE SISTEMAS Y COMPUTACION

INTELIGENCIA ARTIFICIAL
PROYECTO CALCULADORA
PRESENTADO POR EL ALUMNOS
YANGALI PEREZ, Abigael
Llamoga Raico Luis Walter
CICLO: IX
CAETE, PERU 2015

1. QUE ES C#
C# o C Sharp es un lenguaje de programacin que est incluido en la
Plataforma .NET y corre en el lenguaje comn en tiempo de ejecucin
(CLR, Common Languaje Runtime). El primer lenguaje en importancia
para el CLR es C#, mucho de lo que soporta la plataforma .NET est
escrito en C#
C# intenta ser el lenguaje base para ecribir aplicaciones .NET
C# deriva C y C++, es moderno, simple y enteramente orientado
a objetos.
2. DEEFINICIONES BASICAS
NameSpace
Utilizados para organizar las clases y otros tipos en una estructura
jerrquica. El propsito del uso de namespace hacen las clases fciles
de usar y prevenir colisiones con las clases escritas por otros
programadores.
Un namespace contiene tipos que pueden ser utilizados en la
construccin de programas:
Clases
Estructuras
Enumeraciones
Delegados e interfaces
Por ejemplo para poder escribir a la consola se utiliza el
namespace System.
Clases
Una clase es una plantilla para un objeto.
Una clase define la operaciones que un objeto puede realizar y definir
un valor que mantiene el estado del objeto, los componentes
principales de una clase son: mtodos eventos y propiedades
Eventos
Un mtodo es un conjunto de instrucciones las que se les da un
determinado nombre de tal manera que sea posible ejecutarlas en
cualquier momento sin tenerlas que escribir sino usando solo su
nombre estas instrucciones se les denomina cuerpo del mtodo, y a
su ejecucin a travs de su nombre se le denomina llamado al
mtodo.

CALCUADORA BASICA
En esta ocasin veremos cmo hacer una calculadora sencilla en C# ,
sencilla porque solo contara con las cuatro operaciones bsicas. Es similar a
la calculadora que trae por defecto Windows.
Esta es la vista de la calculadora

Los controladores a utilizar son:

27 Button
2 Textbox

Para tener el control se agrega una palabra clave, en este caso para
los Button le pondremos cmd1, cmd2, lo mismo se hace con el
Textbox le llamara Txtpantalla el control a la hora de programar

LOS CONTROLADORES
namespace calculadora2
{
Public partial class Form1 : Form
{
bool detectaoperacion = true;
string operacion;
double resultado;
double numero1;
double numero2;
public Form1()
{
InitializeComponent();
}

//INICIO
private void cmd1_Click(object sender, EventArgs e)
{
if (detectaoperacion)
{
TxtPantalla.Text = "";
TxtPantalla.Text = "1";
detectaoperacion = false;
}
else
{
TxtPantalla.Text = TxtPantalla.Text + "1";
}
}
private void cmd2_Click(object sender, EventArgs e)
{
if (detectaoperacion)
{
TxtPantalla.Text = "";
TxtPantalla.Text = "2";
detectaoperacion = false;
}
else
{
TxtPantalla.Text = TxtPantalla.Text + "2";
}
}
private void cmd3_Click(object sender, EventArgs e)
{
if (detectaoperacion)
{
TxtPantalla.Text = "";
TxtPantalla.Text = "3";
detectaoperacion = false;
}
else
{
TxtPantalla.Text = TxtPantalla.Text + "3";
}
}
private void cmd4_Click(object sender, EventArgs e)
{
if (detectaoperacion)
{
TxtPantalla.Text = "";
TxtPantalla.Text = "4";
detectaoperacion = false;
}
else
{
TxtPantalla.Text = TxtPantalla.Text + "4";
}
}
private void cmd5_Click(object sender, EventArgs e)
{
if (detectaoperacion)
{
TxtPantalla.Text = "";

TxtPantalla.Text = "5";
detectaoperacion = false;

}
else
{
TxtPantalla.Text = TxtPantalla.Text + "5";
}
}
private void cmd6_Click(object sender, EventArgs e)
{
if (detectaoperacion)
{
TxtPantalla.Text = "";
TxtPantalla.Text = "6";
detectaoperacion = false;
}
else
{
TxtPantalla.Text = TxtPantalla.Text + "6";
}
}
private void cmd7_Click(object sender, EventArgs e)
{
if (detectaoperacion)
{
TxtPantalla.Text = "";
TxtPantalla.Text = "7";
detectaoperacion = false;
}
else
{
TxtPantalla.Text = TxtPantalla.Text + "7";
}
}
private void cmd8_Click(object sender, EventArgs e)
{
if (detectaoperacion)
{
TxtPantalla.Text = "";
TxtPantalla.Text = "8";
detectaoperacion = false;
}
else
{
TxtPantalla.Text = TxtPantalla.Text + "8";
}
}
private void cmd9_Click(object sender, EventArgs e)
{
if (detectaoperacion)
{
TxtPantalla.Text = "";
TxtPantalla.Text = "9";
detectaoperacion = false;
}
else
{
TxtPantalla.Text = TxtPantalla.Text + "9";
}

}
private void cmd0_Click(object sender, EventArgs e)
{
/* if (detectaoperacion)
{
TxtPantalla.Text = "";
TxtPantalla.Text = "0";
detectaoperacion = false;
}
else
{
TxtPantalla.Text = TxtPantalla.Text + "0";
}*/
if (TxtPantalla.Text == "0")
{
return;
}
else
{
TxtPantalla.Text = TxtPantalla + "0";
}
}
//FIN DE BOTONES NUMERICOS
//BOTONES DE OPERACION
private void cmdMas_Click(object sender, EventArgs e)
{
operacion = "+";
detectaoperacion= true;
numero1 = double.Parse(TxtPantalla.Text);
}
private void cmdResta_Click(object sender, EventArgs e)
{
operacion = "-";
detectaoperacion = true;
numero1 = double.Parse(TxtPantalla.Text);
}
private void cmdMulti_Click(object sender, EventArgs e)
{
operacion = "*";
detectaoperacion = true;
numero1 = double.Parse(TxtPantalla.Text);
}
private void cmdDiv_Click(object sender, EventArgs e)
{
operacion = "/";
detectaoperacion = true;
numero1 = double.Parse(TxtPantalla.Text);
}
//FIN DE OPERACIONES
private void cmdIgual_Click(object sender, EventArgs e)
{
numero2 = double.Parse(TxtPantalla.Text);
detectaoperacion = true;
switch (operacion)
{
case "+":
resultado = numero1 + numero2;

TxtPantalla.Text = resultado.ToString();
break;
case "-":
resultado = numero1 - numero2;
TxtPantalla.Text = resultado.ToString();
break;
case "*":
resultado = numero1 * numero2;
TxtPantalla.Text = resultado.ToString();
break;
case "/":
resultado = numero1 / numero2;
TxtPantalla.Text = resultado.ToString();
break;
}

}
}

Juego de enemigo
public partial class Form1 : Form
{
int prinicipal; // para elnlasar a la juego

int time =60; // se ddeclara el timpo maximo


int Points = 0; // se declara elpuntaje
public Form1()
{
InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
Points = Points + 1; // al hacer click en en la imagen contaria
label1.Text = "Puntuacin :" + Points;// mustr ael mensaje d epuntaucion
}
private void timer1_Tick(object sender, EventArgs e)
{
if (time == 0) //si el tiempo llega a sero se termina el juego
{
timer1.Stop(); // par aque se dtenga eltiempo
timer2.Stop();// se declar apar aque el ememigo al culminar no se muaba
MessageBox.Show("Tu puntuacion es: "+ Points); // s emustra mensaje masla
puntuacion optenido
Points = 0;
time = 60;
label1.Text = "Puntuacin :" + Points;// lelvar l a conteo de la puntuacion
label2.Text = "Tiempo: " + time;// el tiempo se
timer1.Start();
timer2.Start();

}
else {
time = time - 1; // el teimpo disminuye
label2.Text = "Tiempo: " + time;
}
}
private void move_enemigo()// se declara el monr del enemigo
{
Random radom = new Random();
pictureBox1.Location = new Point(radom.Next(900), radom.Next(580));// este
e spar amedir el espacio que recorrera el enemigo
}
private void timer2_Tick(object sender, EventArgs e)
{
move_enemigo(); // moviendo el enemigo

}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}

}
}

You might also like