#include <tigcclib.h>
#include "extgraph.h"
#define PutSpr() Sprite8_XOR(18,8*choix+24,5,carre,LCD_MEM);
#define wait(n) {OSRegisterTimer(USER_TIMER,n); while (!OSTimerExpired(USER_TIMER)) continue; OSFreeTimer(USER_TIMER)};
#define GetKey() (kbhit()?ngetchx():0);
void aide_credits();
short ecran_menu();
const unsigned char carre[]={0xF8, 0x88, 0x88, 0x88, 0xF8};
const unsigned short carre_vide[]=
{0xFFFF, 0x8001, 0x8001, 0x8001, 0x8001, 0x8001, 0x8001, 0x8001, 0x8001, 0x8001, 0x8001, 0x8001, 0x8001, 0x8001, 0x8001, 0xFFFF};
const unsigned short carre_plein[]=
{0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
const unsigned short faux_carre[]=
{0xFFFF, 0xAAAB, 0xD555, 0xAAAB, 0xD555,0xAAAB, 0xD555,0xAAAB, 0xD555,0xAAAB, 0xD555,0xAAAB, 0xD555,0xAAAB, 0xD555, 0xFFFF};
INT_HANDLER oldint1;
unsigned short temps;
DEFINE_INT_HANDLER(time)
{
temps++;
ExecuteHandler(oldint1);
}
void _main()
{
oldint1=GetIntVec(AUTO_INT_1);
randomize();
OSEnableBreak(); //pour debug
LCD_BUFFER bufr;
LCD_save(bufr);
clrscr();
short time_max=300; //temps max attente
short fake=30; //pourcentage d'apparition du faux carre
short count=0; //compte le nombre de vrais carres
short choix=0;
unsigned short total=0;
while ((choix!=1) && (choix!=4))
{
choix=ecran_menu(); //choix
FontSetSys(F_6x8);
if (choix==2) //Options
{
clrscr();
FontSetSys(F_4x6);
DrawStr(0,94,"Utilisez les touches flechees",1);
FontSetSys(F_6x8);
short chx=1;
short key=0;
DrawStr(0,0,"OPTIONS",1);
while (key!=KEY_ENTER)
{
printf_xy(10,12,"Attente max:%03d",time_max);
printf_xy(10,20,"Faux carre (%%):%03d",fake);
key=GetKey();
if ((key==KEY_DOWN) || (key==KEY_UP))
chx=(chx==1?2:1);
if (key==KEY_LEFT)
{
if ((chx==1) && (time_max>0))
time_max--;
if ((chx==2) && (fake>0))
fake--;
}
if (key==KEY_RIGHT)
{
if ((chx==1) && (time_max<300))
time_max++;
if ((chx==2) && (fake<100))
fake++;
}
}
clrscr();
}
if (choix==3) //Aide/Options
{
aide_credits();
}
if (choix==1) //Le jeu!!
{
clrscr();
Sprite16_XOR(144,0,16,carre_vide,LCD_MEM);
while (count<5)
{
Sprite16_AND(144,0,16,carre_vide,LCD_MEM);
wait(random(time_max));
short x=random(100);
short is_fake=(x<=fake?1:0);
if (is_fake)
{
Sprite16_OR(144,0,16,faux_carre,LCD_MEM);
}
else
{
Sprite16_OR(144,0,16,carre_plein,LCD_MEM);
count++;
}
SetIntVec(AUTO_INT_1,time);
short key=0;
temps=0;
while (temps<512)
{
key=GetKey();
if (key==13)
break;
}
if (((is_fake) && (key=KEY_ENTER)) || (temps<25))
total+=256;
if (!is_fake)
{
x=temps;
if (x>=25)
{
printf_xy(0,8*count,"%i>%d.%03d",count,x>>8,(x&255)*125>>(8-3));
total+=temps;
}
else
{
printf_xy(0,8*count,"%i>triche",count);
}
}
printf_xy(0,55,"%i",total);
SetIntVec(AUTO_INT_1,oldint1);
} //fin while
short x=total/5;
printf_xy(0,55,"%i>>>%d.%03d",total,count,x>>8,(x&255)*125>>(8-3));
short key;
while ((key=ngetchx())!=KEY_ESC)
continue;
} //fin if
} //fin while
//Fin du programme...On quitte proprement
LCD_restore(bufr);
ST_helpMsg("React v3.00 by Tama");
exit(0);
}
void aide_credits()
{
FontSetSys(F_4x6);
clrscr();
DrawStr(0,0,"React v3",1);
DrawStr(0,8,"Comme les precedentes versions de React",1);
DrawStr(0,16,"Le but est d'obtenir le meilleur temps",1);
DrawStr(0,24,"de reaction en faisant la moyenne des 5",1);
DrawStr(0,32,"essais.",1);
DrawStr(0,40,"MAIS ATTENTION! un intrus s'est glisse!",1);
DrawStr(0,48,"Il ne faut pas appuyer lorsque le carre est",1);
DrawStr(0,56,"a moitie noir! sinon cela rajoute 1 seconde de",1);
DrawStr(0,64,"penalite!",1);
FontSetSys(F_8x10);
DrawStr(25,80,"Bonne chance!
",1);
short z;
for(z=1;z<=90;z++)
{
ScrollUp160(LCD_MEM,100);
wait(4);
}
FontSetSys(F_6x8);
DrawStr(0,0,"React v3",1);
DrawStr(15,8,"By Tama",1);
DrawStr(20,16,"Mardi 06 Novembre 2007",1);
DrawStr(0,30,"Remerciements a:",1);
FontSetSys(F_4x6);
DrawStr(5,38,"-La tama's team",1);
DrawStr(5,44,"-Toute l'equipe de tibank",1);
DrawStr(5,50,"-L'equipe de Yaronet pour m'avoir aide",1);
DrawStr(5,56,"-Pollux particulierement pour GTC",1);
DrawStr(5,62,"-La TICT pour ExtGraph",1);
DrawStr(5,68,"-Vous qui testez =P",1);
DrawStr(5,74,"-Et tous ceux qui me connaissent, de pres ou",1);
DrawStr(5,80,"de loin",1);
for(z=1;z<=90;z++)
{
ScrollUp160(LCD_MEM,100);
wait(4);
}
}
short ecran_menu()
{
short choix=1,key=0;
FontSetSys(F_8x10);
DrawStr(10,15,"React v 3",1);
FontSetSys(F_6x8);
DrawStr(25,30,"Jouer!",1);
DrawStr(25,38,"Options",1);
DrawStr(25,46,"Aide/Credits",1);
DrawStr(25,54,"Quitter",1);
FontSetSys(F_4x6);
DrawStr(0,88,"Appuyez sur [Enter] le plus vite possible",1);
DrawStr(0,94,"apres que le carre NOIR apparaisse!",1);
PutSpr();
while (key!=13)
{
key=ngetchx();
if ((key==KEY_UP) && (choix>1))
{
PutSpr();
choix--;
PutSpr();
}
else if ((key==KEY_DOWN) && (choix<4))
{
PutSpr();
choix++;
PutSpr();
}
}
PutSpr();
return choix;
}