Buscando análisis y código fuente de juegos de mecanografía en lenguaje C puro
# incluye & ltstdio.h & gt
# incluye & ltstdlib.h & gt
# incluye & ltgraphics.h & gt
//Downloader
void main()
{
BOOL bQuit = FALSE/*¿Quieres salir* /
BOOL bPause = FALSE/*Si pausar*/
int tm1, tm2
Clave de byte;
aleatorio( ) ; /*Inicializar semilla de número aleatorio*/
SetGraphMode();
seleccionar nivel();
ShowBar();
tm1=CreateTimer(1, mover letra);/*Crear un reloj de objeto de carácter en movimiento*/
tm2=CreateTimer(Interval, crear letra);/*Crear un reloj que genera objetos de carácter*/ p>
crear letra();
clave = askey();
y(!bSalir)
{
evento del temporizador();
Interruptor (tecla)
{
Caso nulo:
Interrupción;
Caso Key_ESC:
bSalir = TRUE
Pausa;
Caso Key_Space:
bPausa=! bPausa;
tmTM[tm1]. Habilitar =! bPausa;
tmTM[tm2]. Habilitar =! bPausa;
Pausa;
Predeterminado:
Si (!bPausa) marca(tecla);
}
key = askey();
}
CloseGraphMode();
}
void SetGraphMode() p>
{
int Dispositivo=VGA, Modo = VGAHI
init gráfico(& dispositivo y.
modo, "";
settextstyle(TRIPLEX_FONT,HORIZ_DIR,1);
setfillstyle(SOLID_FILL,0);
establecer color(7); p>
p>
}
void CloseGraphMode()
{
restorrectmode();
}
/*Leer código ASC directamente desde el búfer del teclado*/
byte askey(void)
{
int start, end p>
Clave de palabra = 0;
start=peek(0, 0x 41a);
end=peek(0, 0x 41c);
si (inicio==fin) devuelve (0);
Otros
{
key=peek(0x40, inicio);
inicio+= 2;
if (inicio == 0x3e)inicio = 0x 1e;
sello (0x40, 0x1a, inicio
retorno); key & amp0x ff);
}
}
void MoveLetter(void)
{
int I;
for(I = 0;i<MAX_LETTERi++)
{
si (letra[i].usada)
{
OcultarLetra(一);
Letra [i]. y+=paso;
ShowLetter(one);
/*El objeto personaje cae al fondo*/
Si (letra [i]. y & gtMAX _ HEIGHT)eliminar letra(I);
}
}
}
void KillLetter(int LetterID)
{
si(letra[IDLetra]. usada)
{
letra[IDLetra]. Usado=false;
Usos de letras -;
ocultar letra(ID de letra);
}
/*Crear inmediatamente después de eliminar el rol objeto*/
crear letra();
}
void CrearLetra()
{
int I = 0;
int x;
Valor de byte;
if (LetterUsed==MAX_LETTER) devuelve /*Si no hay ningún objeto de carácter disponible, devuelve; */
while (letra [++i]. usada); /* Encuentra el primer objeto de carácter libre y genera un objeto de carácter */
x = I ;
Letra [i]. x = x * 640/MAX _ LETRA;
Letra[i]. y = 0;
Letra[i]. val = aleatorio(26)+A;
Letra[i]. Usado=Verdadero;
++ usado por letras;
}
void HideLetter(int ID)
{
/*Caracteres en blanco con rectángulo relleno*/
Columna(letra[ID].x,letra[ID].y,letra[ID].x+16,letra[ID] .
y+20);
}
void ShowLetter(int ID)
{
char str[2]={0, 0 };
str[0]=letra[ID]. val
outtextxy(letra[ID].x,letra[ID].y,str);
}
Comprobación no válida (clave de byte)
p>{
int I
char str[6];
golpes++; ;i<MAX_LETTERi++)
/*clic*/
if (letra[i]. usada&&&letra[i].
val==toupper(Clave))
{
Sonido (1000);
Retraso (10); );
Derecha++;
nosound();
}
/*Mostrar estado*/
setfillstyle(SOLID_FILL, 5);
Barra(260, 430, 320, 450);
Barra(410, 430, 470, 450); establecer color(2);
sprintf(str, " %4ld ", Visitas
outtextxy(260, 430, str); str, " %4ld ", derecha);
outtextxy(410, 430, str);
set color(7);
setfillstyle (SOLID_FILL, 0);
}
columna de visualización nula ()
{
ARCHIVO * bmp
Byte r , g, b, t;
int i, x, y
bmp=fopen("bar.bmp ", " Rb "); fseek(bmp, 54, SEEK_SET);
for(I = 0;i<16;i++)
{
setpalette (i, I); p>
b=fgetc(bmp)>& gt2;
g=fgetc(bmp)>& gt2;
r=fgetc (bmp)>& gt2;
t=fgetc(bmp)>& gt2;
setrgbpalette(i, r, g, b
}
para; (y = 0; y & lt80;y++)
for(x = 0; x & lt320;x++)
{
t = fgetc(BMP );
putpixel(x*2, 479-y, t>& gt4);
putpixel(x*2+1, 479-y, t & amp15);
}
fclose(BMP);
}
void SelectLevel()
{
int Pasos[3]={1, 2, 4};
int Intervalos[3]={18, 9, 5};
int Sel = 0; p>
ARCHIVO * bmp
Bytes r, g, b, t, Clave
int i, x, y
bmp=fopen( "sel.bmp","Rb");
fseek(bmp, 54, SEEK_SET);
for(I = 0;i<16;i++)
{
setpalette(i,I);
b=fgetc(bmp)>& gt2; p>
g=fgetc(bmp)>& gt2;
r=fgetc(bmp)>& gt2;
t=fgetc(bmp)>& gt2;
setrgbpalette(i, r, g, b
}
for(y = 0; y & lt200; y++)
for(x = 0; x & lt160;x++) p>
{
t = fgetc(BMP)
;
putpixel(x*2+160, 339-y, t & gt& gt4);
putpixel(x*2+161, 339-y, t & amp15);
}
fclose(BMP);
mientras(verdadero)
{
clave = toupper( Clave ASC());
if(Clave == ' A ')Sel = 1
if(Clave == ' B ')Sel = 2;
if(Key = = ' C ')Sel = 3;
Si (Sel) se rompe;
}
paso = Pasos[Sel- 1];
intervalo = Intervalos[Sel-1];
borrar dispositivo();
}
/*** ************************************************** * ****/
/*Archivo: temporizador. H */
/*************************************** * *******************/
/********************** ** **********************************/
/*El temporizador máximo disponible en el sistema Cantidad*/
#define MAXTIMER 10
# ifndef NULL
#define NULL 0
# endif
/*Estructura del temporizador*/
Estructura registrada
{
Intervalo DWORD /*Intervalo*/
DWORD; LastTimer /*Última hora del evento*/
BOOL habilitado /*Actividad*/
BOOL usado/*disponible*/
void(*puntero) );/*Puntero lejano del evento*/
};
struct TM tmTM[max timer+1];
int timer used = 0 ; p>
/*Obtener valor del contador BIOS*/
BiosTimer de doble palabra (vacío)
{
Temporizador DWORD BIOS = 0;
BIOSTIMER=peek(0x0, 0x46e);
BIOSTIMER & lt& lt=8;
BIOSTIMER+=peek(0x0, 0x 46c);
return(temporizador de BIOS);
}
/*Evento de tiempo (núcleo del sistema de reloj)*/
void TimerEvent()
{
int I;
DWORD TimerDiff
for(I = 1;i<= MAXTIMERi++)
{
if (tmTM[i]. usado&&tmTM[i].enabled)
{
TimerDiff=BiosTimer()-tmTM[i]. LastTimer
if (tmTM[i].interval & lt=TimerDiff)
{
tmTM[i]. Puntero();
tmTM[i].
último temporizador = temporizador BIOS();
}
}
}
}
/*Crear Reloj (devuelve el identificador del reloj correctamente; de lo contrario, devuelve NULL) */
int CreateTimer(DWORD Interval, void (*Pointer)())
{
int I = 0;
si (TimerUsed==MAXTIMER) devuelve NULL
mientras (tmTM[++i].used);
tmTM [ i]. puntero = puntero;
tmTM[i]. intervalo = intervalo;
tmTM[i]. Habilitar = VERDADERO
tmTM[i]. Usado=Verdadero;
tmTM[i]. último temporizador = temporizador BIOS();
tiempo usado++;
Regresar I;
}
/*Eliminar reloj*/
void KillTimer(int *TimerID)
{
if (tmTM[*TimerID]). Usado)
{
tiempo usado-;
tmTM[*TimerID]. usado = falso;
}
* tiempo eliminado = 0;
}
/*Eliminar todos los relojes*/ p >
void KillAllTimer()
{
int I;
for(I = 0; I<= MAXTIMERi++) tmTM[i] . usado = falso;
temporizador usado = 0;
}