[C con Clase] Jueguito Grafico
Carlos Arriagada
carlos_arriagada en ipciisa.cl
Mar Ago 11 21:19:36 CEST 2009
##############################################
LOTO
/*LIBRERIA DONDE SE ENCUENTRA LOS BOTONES Y LAS VETANAS */
#include "GRAFICOS.H"
#include "musica.h"
#include<stdlib.h>
int c1,c2,c3,D[16],m,n;
//-------------------FUNCI ON PARA GRAFICAR DISCOS-------------------- ---
void Disco(int i,int Der,int Izq,int Arr,int Aba)
{
setcolor(YELLOW);
setfillstyle( SOLID_FILL,i);
fillellipse(Der,Izq+4,Arr, Aba);
fillellipse(Der,Izq,Arr,Ab a);
setcolor(YELLOW);
}
//-----------------FIN DE LA FUNCION PARA GRAFICAR DISCOS---------------
//---------------------FUN CION PARA LA PRESENTACION-------------- -------
void Presentacion()
{
for(int i=1;i<=6;i++)
Disco(i,290,300-(i*6),200- (i*6),55-(i*4));
settextstyle(TRIPLEX_FONT, HORIZ_DIR,4);
outtextxy(172,160,"Juego del LOTO";-) ;
setcolor(WHITE);
settextstyle(SANS_SERIF_FO NT, HORIZ_DIR,1);
outtextxy(0,0,"Instituto Profesional La Araraucana";-) ;
settextstyle(DEFAULT_FONT, HORIZ_DIR,1);
setcolor(9);
outtextxy(10,453,"Cargando ...";-) ;
setcolor(0);
for (int son=5;son<70;son++)
tocarnota(NDO,son,1);
for(int dow=100;dow<=500;dow++)
{
setfillstyle(INTERLEAVE_FI LL,BLUE);
bar(dow+50,450,dow+1,460);
delay(15);
}
}
//------------------------ ---PAGINA I------------------------- ----
void main()
{int Salir=1,N=1,dec,sig,dig=1, k=1,h=3,a=2,Desp,origen,de stino,auxiliar;char *Num,*Or;
Iniciar();
graton.Rmuestra(FALSO);
Presentacion();
Marco();
Titulo(0,0,getmaxx()-5,"In greso de Numeros";-) ;
Etiqueta(30,60,"Presione los 6 numeros que desee:";-) ;
rectangle(15,80,600,300);
Botones(150,50,25,25,1,"1" ;-) ;
Botones(200,50,25,25,1,"2" ;-) ;
Botones(150,90,25,25,1,"3" ;-) ;
Botones(200,90,25,25,1,"4" ;-) ;
Botones(150,130,25,25,1,"5 ";-) ;
Botones(200,130,25,25,1,"6 ";-) ;
Botones(500,380,80,25,1,"S orteo";-) ;
Botones(500,425,80,25,1,"S alir";-) ;
graton.Rmuestra(VERDAD);
Restado Posicion;
if(Result->presente)
{
do{
Posicion=graton.Rpulsado(B otonI);
if(Posicion.contador_boton )
{
if(TPos(Posicion.ejex,500, 580))
{
if(TPos(Posicion.ejey,425, 450))
{
graton.Rmuestra(FALSO);
Botones(500,425,80,25,2,"S alir";-) ;
delay(200);
Botones(500,425,80,25,1,"S alir";-) ;
graton.Rmuestra(VERDAD);
Salir=0;
}
}
if(TPos(Posicion.ejex,400, 480))
{
if(TPos(Posicion.ejey,50,7 5))
{
graton.Rmuestra(FALSO);
Botones(400,50,80,25,2,"Ac eptar";-) ;
delay(200);
Botones(400,50,80,25,1,"Ac eptar";-) ;
setfillstyle(SOLID_FILL,BL ACK);
bar(15,420,480,475);
setfillstyle(HATCH_FILL,7) ;
bar(17,205,202,410);
setfillstyle(HATCH_FILL,7) ;
bar(222,205,408,410);
setfillstyle(HATCH_FILL,7) ;
bar(428,205,611,410);
m=0;n=0;
if(k==1){Desp=0;c1=N;c2=0; c3=0;}
if(k==2){Desp=205;c1=0;c2= N;c3=0;}
if(k==3){Desp=410;c1=0;c2= 0;c3=N;}
for(int i=1;i<=N;i++)
{
setfillstyle(LINE_FILL,i);
bar(20+(5*i)+Desp,400-(10* i),200-(5*i)+Desp,390-(10* i));
D[i]=(N+1)-i;
}
if((k==1||k==2)&&(h==1||h= =2))a=3;
if((k==1||k==3)&&(h==1||h= =3))a=2;
if((k==2||k==3)&&(h==2||h= =3))a=1;
graton.Rmuestra(VERDAD);
}
}
if(TPos(Posicion.ejey,50,7 5))
{
if(TPos(Posicion.ejex,150, 175))
{
graton.Rmuestra(FALSO);
Botones(150,50,25,25,2,"<- ";-) ;
delay(200);
Botones(150,50,25,25,1,"<- ";-) ;
graton.Rmuestra(VERDAD);
if(N>1)N--;if(N>=10)dig=2; else dig=1;
Num = ecvt(N,dig,&dec,&sig);
setfillstyle(SOLID_FILL,7) ;
bar(178,55,195,70);
Etiqueta(187,65,Num);
}
if(TPos(Posicion.ejex,200, 225))
{
graton.Rmuestra(FALSO);
Botones(200,50,25,25,2,"-> ";-) ;
delay(200);
Botones(200,50,25,25,1,"-> ";-) ;
graton.Rmuestra(VERDAD);
if(N<15)N++;if(N>=10)dig=2 ;
Num = ecvt(N,dig,&dec,&sig);
setfillstyle(SOLID_FILL,7) ;
bar(178,55,195,70);
Etiqueta(187,65,Num);
}
}
if(TPos(Posicion.ejey,90,1 15))
{
if(TPos(Posicion.ejex,150, 175))
{
graton.Rmuestra(FALSO);
Botones(150,90,25,25,2,"<- ";-) ;
delay(200);
Botones(150,90,25,25,1,"<- ";-) ;
graton.Rmuestra(VERDAD);
if(k>1&&k-1!=h)k--;
else
{
if(k==3)k-=2;
}
Num = ecvt(k,1,&dec,&sig);
setfillstyle(SOLID_FILL,7) ;
bar(178,95,195,110);
Etiqueta(186,103,Num);
}
if(TPos(Posicion.ejex,200, 225))
{
graton.Rmuestra(FALSO);
Botones(200,90,25,25,2,"-> ";-) ;
delay(200);
Botones(200,90,25,25,1,"-> ";-) ;
graton.Rmuestra(VERDAD);
if(k<3&&k+1!=h)k++;
else
{
if(k==1)k+=2;
}
Num = ecvt(k,1,&dec,&sig);
setfillstyle(SOLID_FILL,7) ;
bar(178,95,195,110);
Etiqueta(186,103,Num);
}
}
if(TPos(Posicion.ejey,130, 155))
{
if(TPos(Posicion.ejex,150, 175))
{
graton.Rmuestra(FALSO);
Botones(150,130,25,25,2,"< -";-) ;
delay(200);
Botones(150,130,25,25,1,"< -";-) ;
graton.Rmuestra(VERDAD);
if(h>1&&h-1!=k)h--;
else
{
if(h==3)h-=2;
}
Num = ecvt(h,1,&dec,&sig);
setfillstyle(SOLID_FILL,7) ;
bar(178,135,195,150);
Etiqueta(188,145,Num);
}
if(TPos(Posicion.ejex,200, 225))
{
graton.Rmuestra(FALSO);
Botones(200,130,25,25,2,"- >";-) ;
delay(200);
Botones(200,130,25,25,1,"- >";-) ;
graton.Rmuestra(VERDAD);
if(h<3&&h+1!=k)h++;
else
{
if(h==1)h+=2;
}
Num = ecvt(h,1,&dec,&sig);
setfillstyle(SOLID_FILL,7) ;
bar(178,135,195,155);
Etiqueta(188,145,Num);
}
}
}
}while(Salir==1);
textcolor(BLACK);
clrscr();
gotoxy(17,15);
printf("Realizado por Carlos Arriagada Devia.";-) ;
gotoxy(17,16);
printf("04-100B.";-) ;
gotoxy(17,18);
printf("Presione cualquier tecla para salir...";-) ;
getch();
}
Finalizar();
}
//-------------------FIN DE LA FUNCION PRINCIPAL----------------- ---------
LIBRERIAS
Musica:
/*
Para reproducir una nota musical se usa:
tocarnota(nota, octav, duracion);
por ejemplo:
tocarnota(NSI, 5, 20);
Los nombres de las notas son:
NDO
NDOS
NRE
NRES
NMI
NFA
NFAS
NSOL
NSOLS
NLA
NLAS
NSI
Las octavas son 1, 2, 3, 4, 5, 6 y 7
Las duraciones son:
10 para nota negra
20 para nota blanca
...
Para agregar un silencia se usa:
silencio(duracion);
Por ejemplo:
silencio(5);
*
El tempo definido es 120, pero se puede cambiar
*/
#include<dos.h>
int NDO[7] = {32.70, 65.41, 130.81, 261.63, 523.25, 1046.50, 2093.00};
int NDOS[7]= {34.65, 69.30, 138.59, 277.18, 554.37, 1108.73, 2217.46};
int NRE[7] = {36.71, 73.42, 146.83, 293.66, 587.33, 1174.66, 2349.32};
int NRES[7]= {38.89, 77.78, 155.56, 311.13, 622.25, 1244.51, 2489.02};
int NMI[7] = {41.20, 82.41, 164.81, 329.63, 659.26, 1318.51, 2637.02};
int NFA[7] = {43.65, 87.31, 174.61, 349.23, 698.46, 1396.91, 2793.83};
int NFAS[7]= {46.25, 92.50, 185.00, 369.99, 739.99, 1479.98, 2959.96};
int NSOL[7]= {49.00, 98.00, 196.00, 392.00, 783.99, 1567.98, 3135.96};
int NSOLS[7]={51.91, 103.83, 207.65, 415.30, 830.61, 1661.22,3322.44};
int NLA[7] = {55.00, 110.00, 220.00, 440.00, 880.00, 1760.00,3520.00};
int NLAS[7]= {58.27, 116.54, 233.08, 466.16, 932.33, 1864.66,3729.31};
int NSI[7] = {61.74, 123.47, 246.94, 493.88, 987.77, 1975.53,3951.07};
int play_nota(int nota[], int oct, int duracion);
int silencio(int duracion);
int octava;
int o;
int duracion;
int tempo = 120;
int tn;
int frec;
int tocarnota(int nota[], int octava, int duracion)
{
int t = 6000/tempo;
o = octava -1;
tn =duracion * t;
frec = nota[o];
sound(frec);
delay(tn);
nosound();
return 1;
}
int silencio(int duracion)
{
tn =duracion * 6000/tempo;
delay(tn);
return 1;
}
Graficos:
#ifndef __GRAFICOS_cpp
#define __GRAFICOS_cpp
#include<graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<string.h>
#include<stdarg.h>
#include<fstream.h>
#include"raton.h"
#define ENTER 13
#define BACKSPACE '\b'
#define ESC 27
#define SUPR 83
#define IZQUIERDA 75
#define DERECHA 77
Rresultado *Result;
void Ventana(int x, int y, int x1, int y1, int modo3D = 0);
void Muestra_Texto(int a,int b,char *texto);
//------------------------ -------------------------- -----------
void Iniciar()
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "I:\\TC\\BGI";-) ;
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Error Grafico: %s\n", grapherrormsg(errorcode));
printf("Presione una tecla para continuar:";-) ;
getch();
exit(1);
}
Result=graton.Riniciar();
graton.Pon_Cursor(FLECHA);
}
void Finalizar()
{
closegraph();
}
int TPos(int TP,int Abajo,int Arriba)
{
return ( (TP>=Abajo) && (TP<=Arriba) );
}
//Dibuja una ventana vacia tipo WINDOWS98
void Ventana(int x, int y, int x1, int y1, int modo3D)
{
// modo3D=0 -> muestra una ventana sin efecto 3D
// modo3D=1 -> muestra una ventana saliente
// modo3D=2 -> muestra una ventana entrante
int marco1,marco2;
switch( modo3D )
{
case 0:
marco1=marco2=7;
break;
case 1:
marco1=15;
marco2=8;
break;
case 2:
marco1=8;
marco2=15;
}
setfillstyle(1,7);
bar(x,y,x1,y1);
setcolor(marco1);
line(x,y,x1,y);
line(x,y,x,y1);
setcolor(marco2);
line(x,y1,x1,y1);
line(x1,y,x1,y1);
}
void Marco()
{
Ventana(0,0,getmaxx()-10,g etmaxy(),0);
}
void Titulo(int izq,int arriba,int der,char *text)
{
//settextjustify(CENTER_TE XT,CENTER_TEXT);
setfillstyle(1,1);
bar(izq+2,arriba+2,der-2,a rriba+20);
setcolor(15);
outtextxy((der-izq)/2-50,a rriba+7,text);
}
void Botones(int x,int y,int w,int h,int modo,char *text)
{
settextjustify(CENTER_TEXT ,CENTER_TEXT);
Ventana(x,y,x+w,y+h,modo);
setcolor(15);
outtextxy(x+(w/2),y+(h/2), text);
}
void Etiqueta(int x,int y,char *text)
{
setcolor(15);
outtextxy(x,y,text);
}
#endif
##############################################
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.conclase.net/pipermail/cconclase_listas.conclase.net/attachments/20090811/df2515da/attachment.html>
Más información sobre la lista de distribución Cconclase