Aqui les dejo un pequeño juego en C++ que ize hace un tiempo...
Es el conocido SIMON.
Se juega con las teclas:
___ ___
|_7_|_8_| 7- azul 8- rojo
|_4_|_5_| 4- verde 5- amarillo
Se podria perfeccionar mucho...
- Deje a medias lo del orden aleatorio para las jugadas y el almacenamiento de records...
Esto sera para version nº2 :)
Aqui los sources:
simon.cpp (archivo principal, contiene la main())
#include <stdio.h>
#include <iostream>
#include<winbgim.h>
#include<windows.h>
#include<conio.h>
#include<time.h>
#include "presentacion.h"
#include "tablero.h"
using namespace std;
class jugadas:public tablero
{
public:
jugadas():tablero()
{
}
void juego();
void a1();
void r2();
void v3();
void z4();
void perdiste();
int var1;
int avance;
int var3;
void teclado();
void inicializaAvance();
private:
};
void jugadas::perdiste()
{
outtextxy(300,300,"Perdiste");
delay(8000);
}
void jugadas::inicializaAvance()
{
avance=0;
}
void jugadas::a1()
{
setcolor(CYAN);
rectangle(200,50,400,250);
int xBLUE1=201;
int yBLUE1=51;
int xBLUE2=399;
int yBLUE2=249;
int z1=0;
while(z1<99)
{
setcolor(CYAN);
rectangle(xBLUE1,yBLUE1,xBLUE2,yBLUE2);
xBLUE1++;
yBLUE1++;
xBLUE2--;
yBLUE2--;
z1++;
delay(10);
}
tablero::azul();/*
// la tecla 7 coincide con el azul, su codigo ascii es 55
// llamo a la variable ta (Tecla Azul)
int ta=(int)getch();
if (ta != 55)
{
perdiste();
}*/
}
void jugadas::r2()
{
setcolor(CYAN);
rectangle(401,50,600,250);
int xRED1=401;
int yRED1=51;
int xRED2=599;
int yRED2=249;
int z3=0;
while(z3<100)
{
setcolor(CYAN);
rectangle(xRED1,yRED1,xRED2,yRED2);
xRED1++;
yRED1++;
xRED2--;
yRED2--;
z3++;
delay(10);
}
tablero::rojo();/*
// la tecla 8 coincide con el rojo, su codigo ascii es 56
// llamo a la variable tr (Tecla Roja)
int tr=(int)getch();
if (tr != 56)
{
perdiste();
}*/
}
void jugadas::v3()
{
setcolor(CYAN);
rectangle(200,251,400,450);
int xGREEN1=201;
int yGREEN1=252;
int xGREEN2=399;
int yGREEN2=449;
int z2=0;
while(z2<99)
{
setcolor(CYAN);
rectangle(xGREEN1,yGREEN1,xGREEN2,yGREEN2);
xGREEN1++;
yGREEN1++;
xGREEN2--;
yGREEN2--;
z2++;
delay(10);
}
tablero::verde(); /*
// la tecla 4 coincide con el verde, su codigo ascii es 52
// llamo a la variable tv (Tecla Verde)
int tv=(int)getch();
if (tv != 52)
{
perdiste();
}*/
}
void jugadas::z4()
{
setcolor(CYAN);
rectangle(401,251,601,450);
int xYELLOW1=402;
int yYELLOW1=252;
int xYELLOW2=600;
int yYELLOW2=449;
int z4=0;
while(z4<99)
{
setcolor(CYAN);
rectangle(xYELLOW1,yYELLOW1,xYELLOW2,yYELLOW2);
xYELLOW1++;
yYELLOW1++;
xYELLOW2--;
yYELLOW2--;
z4++;
delay(10);
}
tablero::amarillo();
/*
// la tecla 5 coincide con el amarillo, su codigo ascii es 53
// llamo a la variable tz porque llame al metodo z4
int tz=(int)getch();
if (tz != 53)
{
perdiste();
}*/
}
void jugadas::juego()
{
int jugadas[10]={4,2,3,4,1,2,3,4,1,2};
int jugadas1[10]={2,1,4,2,1,3,2,4,1,2};
int jugadas2[10]={4,1,4,2,1,4,3,2,3,1};
int a;
a=0;
//int alt=random();
int alt=0;
switch (alt)
{
case 0:
for (var1=0; var1<=avance;)
{
if (jugadas[a]==1)
{
a1();
}
if (jugadas[a]==2)
{
r2();
}
if (jugadas[a]==3)
{
v3();
}
if (jugadas[a]==4)
{
z4();
}
var1++;
a++;
}
teclado();
}
}
void jugadas::teclado()
{
int jugadas[10]={4,2,3,4,1,2,3,4,1,2};
int c;
c=0;
int contador;
contador=0;
fflush(stdin);
for (contador=0; contador<=avance;)
{
int tecla=(int)getch();
printf("%d",tecla);
if (tecla==55) // 7 ascii 55
{
if (jugadas[c]!=1)
{
perdiste();
}
}
if (tecla==56) // 8 ascii 56
{
if (jugadas[c]!=2)
{
perdiste();
}
}
if (tecla==52) // 4 ascii 52
{
if (jugadas[c]!=3)
{
perdiste();
}
}
if (tecla==53) // 5 ascii 53
{
if (jugadas[c]!=4)
{
perdiste();
}
}
contador++;
c++;
}
avance++;
juego();
}
int main()
{
srand(time (NULL));
presentacion pantalla;
pantalla.titulo();
pantalla.persiana();
tablero cuadros;
cuadros.limpiar();
cuadros.azul();
cuadros.rojo();
cuadros.verde();
cuadros.amarillo();
jugadas niveles;
niveles.inicializaAvance();
niveles.juego();
}
presentacion.h
class presentacion
{
public:
presentacion();
void persiana();
void titulo();
private:
int coordenadaXpantalla;
int coordenadaYpantalla;
};
presentacion::presentacion()
{
coordenadaXpantalla=800;
coordenadaYpantalla=600;
initwindow(coordenadaXpantalla,coordenadaYpantalla);
}
void presentacion::persiana()
{
setcolor(BLUE);
int xBLUE=0;
int yBLUE=0;
int z4=0;
while(z4<100)
{
while(xBLUE<coordenadaXpantalla)
{
putpixel(xBLUE,yBLUE,BLUE);
xBLUE++;
}
z4++;
yBLUE++;
xBLUE=0;
delay(5);
}
Beep(100,100);
setcolor(RED);
int xRED=0;
int yRED=100;
int z3=0;
while(z3<100)
{
while(xRED<coordenadaXpantalla)
{
putpixel(xRED,yRED,RED);
xRED++;
}
z3++;
yRED++;
xRED=0;
delay(5);
}
Beep(200,100);
setcolor(GREEN);
int xGREEN=0;
int yGREEN=400;
int z2=0;
while(z2<100)
{
while(xGREEN<coordenadaXpantalla)
{
putpixel(xGREEN,yGREEN,GREEN);
xGREEN++;
}
z2++;
yGREEN++;
xGREEN=0;
delay(5);
}
Beep(300,100);
setcolor(YELLOW);
int xYELLOW=0;
int yYELLOW=500;
int z1=0;
while(z1<coordenadaYpantalla)
{
while(xYELLOW<coordenadaXpantalla)
{
putpixel(xYELLOW,yYELLOW,YELLOW);
xYELLOW++;
}
z1++;
yYELLOW++;
xYELLOW=0;
delay(5);
}
Beep(500,100);
settextstyle(9,0,3); //(estilo,forma,tamaño)
outtextxy(300,550,"Pulsa una tecla para continuar");
int continuar=(int)getch();
fflush(stdin);
}
void presentacion::titulo()
{
// TEXTO DE SIMON
setcolor(WHITE);
line(470,230,790,230);
setcolor(CYAN);
line(50,230,450,230);
outtextxy(470,250,"Videojuego creado en C++ (using winbgim)");
outtextxy(470,270,"Code posteado en e-root.org");
outtextxy(470,290,"Por ---- Endif");
setcolor(BLUE);
int auxr;
int auxr1=610;
int auxr2=320;
int auxr3=630;
int auxr4=340;
for (auxr=0; auxr<11; auxr++)
{
rectangle(auxr1,auxr2,auxr3,auxr4);
auxr1++;
auxr2++;
auxr3--;
auxr4--;
}
setcolor(RED);
int auxb;
int auxb1=631;
int auxb2=320;
int auxb3=651;
int auxb4=340;
for (auxb=0; auxb<11; auxb++)
{
rectangle(auxb1,auxb2,auxb3,auxb4);
auxb1++;
auxb2++;
auxb3--;
auxb4--;
}
setcolor(GREEN);
int auxg;
int auxg1=610;
int auxg2=341;
int auxg3=630;
int auxg4=361;
for (auxg=0; auxg<11; auxg++)
{
rectangle(auxg1,auxg2,auxg3,auxg4);
auxg1++;
auxg2++;
auxg3--;
auxg4--;
}
setcolor(YELLOW);
int auxy;
int auxy1=631;
int auxy2=341;
int auxy3=651;
int auxy4=361;
for (auxy=0; auxy<11; auxy++)
{
rectangle(auxy1,auxy2,auxy3,auxy4);
auxy1++;
auxy2++;
auxy3--;
auxy4--;
}
setcolor(WHITE);
rectangle(610,320,651,361);
// LETRA S
setcolor(WHITE);
rectangle(50,250,170,270);
int s1=51;
int s2=251;
int s3=169;
int s4=269;
int s5;
for (s5=0; s5<10; s5++)
{
rectangle(s1,s2,s3,s4);
s1++;
s2++;
s3--;
s4--;
}
rectangle(50,270,70,300);
int s6=51;
int s7=271;
int s8=69;
int s9=299;
int s10;
for (s10=0; s10<10; s10++)
{
rectangle(s6,s7,s8,s9);
s6++;
s7++;
s8--;
s9--;
}
rectangle(50,300,170,320);
int s11=51;
int s12=301;
int s13=169;
int s14=319;
int s15;
for (s15=0; s15<10; s15++)
{
rectangle(s11,s12,s13,s14);
s11++;
s12++;
s13--;
s14--;
}
rectangle(150,320,170,350);
int s16=151;
int s17=321;
int s18=169;
int s19=349;
int s20;
for (s20=0; s20<10; s20++)
{
rectangle(s16,s17,s18,s19);
s16++;
s17++;
s18--;
s19--;
}
rectangle(50,350,170,370);
int s25=51;
int s21=351;
int s22=169;
int s23=369;
int s24;
for (s24=0; s24<10; s24++)
{
rectangle(s25,s21,s22,s23);
s25++;
s21++;
s22--;
s23--;
}
// letra I
setcolor(WHITE);
rectangle(180,250,200,370);
int i1=181;
int i2=251;
int i3=199;
int i4=369;
int i5;
for (i5=0; i5<10; i5++)
{
rectangle(i1,i2,i3,i4);
i1++;
i2++;
i3--;
i4--;
}
// letra M
setcolor(WHITE);
rectangle(210,250,230,370);
int i6=211;
int i7=251;
int i8=229;
int i9=369;
int i10;
for (i10=0; i10<10; i10++)
{
rectangle(i6,i7,i8,i9);
i6++;
i7++;
i8--;
i9--;
}
rectangle(250,250,270,370);
int i11=251;
int i12=251;
int i13=269;
int i14=369;
int i15;
for (i15=0; i15<10; i15++)
{
rectangle(i11,i12,i13,i14);
i11++;
i12++;
i13--;
i14--;
}
rectangle(290,250,310,370);
int i16=291;
int i17=251;
int i18=309;
int i19=369;
int i20;
for (i20=0; i20<10; i20++)
{
rectangle(i16,i17,i18,i19);
i16++;
i17++;
i18--;
i19--;
}
rectangle(210,250,310,270);
int i21=211;
int i22=251;
int i23=309;
int i24=269;
int i25;
for (i25=0; i25<10; i25++)
{
rectangle(i21,i22,i23,i24);
i21++;
i22++;
i23--;
i24--;
}
//LA O
setcolor(WHITE);
rectangle(320,250,380,370);
int o1=321;
int o2=251;
int o3=379;
int o4=369;
int o5;
for (o5=0; o5<20; o5++)
{
rectangle(o1,o2,o3,o4);
o1++;
o2++;
o3--;
o4--;
}
//la n
rectangle(390,250,410,370);
int n1=391;
int n2=251;
int n3=409;
int n4=369;
int n5;
for (n5=0; n5<10; n5++)
{
rectangle(n1,n2,n3,n4);
n1++;
n2++;
n3--;
n4--;
}
rectangle(430,250,450,370);
int n6=431;
int n7=251;
int n8=449;
int n9=369;
int n10;
for (n10=0; n10<10; n10++)
{
rectangle(n6,n7,n8,n9);
n6++;
n7++;
n8--;
n9--;
}
rectangle(390,250,450,270);
int n11=391;
int n12=251;
int n13=449;
int n14=269;
int n15;
for (n15=0; n15<10; n15++)
{
rectangle(n11,n12,n13,n14);
n11++;
n12++;
n13--;
n14--;
}
}
tablero.h
class tablero
{
public:
tablero();
void azul();
void verde();
void rojo();
void amarillo();
void limpiar();
private:
};
tablero::tablero()
{
int nada;
}
void tablero::limpiar()
{
// limpiamos la presentacion
setcolor(BLACK);
int xlimp=0;
int ylimp=0;
int limp=0;
while(limp<600)
{
while(xlimp<800)
{
putpixel(xlimp,ylimp,BLACK);
xlimp++;
}
limp++;
ylimp++;
xlimp=0;
delay(5);
}
}
void tablero::azul()
{
// cuadro AZUL
setcolor(BLUE);
rectangle(200,50,400,250);
int xBLUE1=201;
int yBLUE1=51;
int xBLUE2=399;
int yBLUE2=249;
int z1=0;
while(z1<99)
{
setcolor(BLUE);
rectangle(xBLUE1,yBLUE1,xBLUE2,yBLUE2);
xBLUE1++;
yBLUE1++;
xBLUE2--;
yBLUE2--;
z1++;
delay(10);
}
}
void tablero::verde()
{
// cuadros VERDE
setcolor(GREEN);
rectangle(200,251,400,450);
int xGREEN1=201;
int yGREEN1=252;
int xGREEN2=399;
int yGREEN2=449;
int z2=0;
while(z2<99)
{
setcolor(GREEN);
rectangle(xGREEN1,yGREEN1,xGREEN2,yGREEN2);
xGREEN1++;
yGREEN1++;
xGREEN2--;
yGREEN2--;
z2++;
delay(10);
}
}
void tablero::rojo()
{
// cuadros ROJO
setcolor(RED);
rectangle(401,50,600,250);
int xRED1=401;
int yRED1=51;
int xRED2=599;
int yRED2=249;
int z3=0;
while(z3<100)
{
setcolor(RED);
rectangle(xRED1,yRED1,xRED2,yRED2);
xRED1++;
yRED1++;
xRED2--;
yRED2--;
z3++;
delay(10);
}
}
void tablero::amarillo()
{
// cuadros AMARILLO
setcolor(YELLOW);
rectangle(401,251,601,450);
int xYELLOW1=402;
int yYELLOW1=252;
int xYELLOW2=600;
int yYELLOW2=449;
int z4=0;
while(z4<99)
{
setcolor(YELLOW);
rectangle(xYELLOW1,yYELLOW1,xYELLOW2,yYELLOW2);
xYELLOW1++;
yYELLOW1++;
xYELLOW2--;
yYELLOW2--;
z4++;
delay(10);
}
}
Si tienen algun problema me dicen!
Espero que les sirva de algo :P
Autor: Radón