Accueil > > > SERPENT BETA0.9999
SERPENT BETA0.9999
Information sur la source
Description
bon c'est pas propre le code! Mais marche bien! J'ai pas fais de header, la classe est au dessus! Comme ca pour compilé suffit de faire copier coller! J'ai pas encore mis de la deco, ca serai pour apres! Y'aura des images etc....
Source
- #include <iostream.h>
- #include <conio.h>
- #include <graphics.h>
- #include <stdlib.h>
- #include <math.h>
- #include <stdio.h>
- #include <dos.h>
- #include <string.h>
-
-
- class serpent
- {
- public:
- //fct graphique
- unsigned char * ecran;
- void modeVGA();
- void modeTexte(){_AX=0x03;geninterrupt(0x10);}
- void putpixel(int X, int Y,int couleur);
- int getpixel(int X,int Y){return ecran[(Y*320)+X];}
- void lirePal(unsigned char index, unsigned char &rouge, unsigned char &vert, unsigned char &bleue);
- void ecrirePal(unsigned char index, unsigned char rouge, unsigned char vert, unsigned char bleue);
- void genPal();
- void cls (){ memset(ecran,0,64000L);}
- int colToblack(unsigned temps);
-
-
- //fct geometrique
- void cercle(int x, int y, int rayon,int couleur);
- void cercleBis(int x, int y, int rayon,int couleur);
-
- void verti(int X,int y1,int y2,int col);
- void corps (int x,int y,int col);
- void cadre();
- void pomme(int &x, int &y);
- void generePomme();
- //moteur
- int verifDanger(int X,int Y,int addX,int addY,int espace,int score,int couleur);
- void affichePerdu();
- void lireMaxScore();
- void ecrireMaxScore(int score);
- int controle(int &addX,int &addY,int espace);
- void comptePomme(int X,int Y,int &Xpomme,int &Ypomme,int &nombrePomme,int &taille,int &pommeAffiche);
- //fct menu
- void presentation();
- int menu();
- void option();
- void genereOption();
- void titre(int X);
- void moteur();
- void explosion(int x,int y);
-
-
-
- private:
- char *scoreMax;
- int colUser;
- int vitesseUser;
-
-
- };
-
-
-
-
-
-
-
- /*--------------------------------*/
- /* FONCTION 13h */
- /*--------------------------------*/
-
- //==============================================================================
- void serpent ::modeVGA(){
- ecran=(unsigned char*) (0xA0000000L);
- _AX=0x13;
- geninterrupt(0x10);}
- //==============================================================================
-
-
- void serpent ::putpixel(int X, int Y,int couleur){
-
- ecran[(Y*320)+X]=couleur;
-
- }
- //==============================================================================
-
- int serpent::colToblack(unsigned temps){
-
- unsigned char r,g,b;
- for (int i=0;i<64;i++)
- {
-
- delay(temps);
- for (int j=0;j<256;j++)
- {
-
- lirePal(j,r,g,b);
- if (r>0)r--;
- if (g>0)g--;
- if (b>0)b--;
- ecrirePal((unsigned char)j,r,g,b);
- }
- }
- return 0;
-
-
- }
-
- //==============================================================================
-
-
-
- //==============================================================================
-
-
- void serpent::lirePal(unsigned char index, unsigned char &rouge, unsigned char &vert, unsigned char &bleue)
- {
- outportb(0x03C7,index);
- rouge= inportb(0x03C9);
- vert = inportb(0x03C9);
- bleue = inportb(0x03C9);
- }
- //==============================================================================
- void serpent::ecrirePal(unsigned char index, unsigned char rouge, unsigned char vert, unsigned char bleue)
- {
- outportb(0x03C8,index);
- outportb(0x03C9,rouge);
- outportb(0x03C9,vert);
- outportb(0x03C9,bleue);
- }
- //==============================================================================
-
- void serpent::genPal()
- {
- for (int i=0;i<=63;i++) ecrirePal(i,i,0,0); // 64 tons de rouge
- for (i=64;i<=127;i++) ecrirePal(i,0,i,0); // 64 tons de vert
- for (i=128;i<=191;i++) ecrirePal(i,0,0,i); // 64 tons de bleu
- for (i=192;i<=255;i++) ecrirePal(i,i,i,i); // 64 tons de gris
-
- }
- //==============================================================================
-
-
-
- /*--------------------------------*/
- /* FONCTION GEOMETRIQUE */
- /*--------------------------------*/
-
-
-
- void serpent::cercle(int x, int y, int rayon,int couleur)
- {
-
- const float pi=3.14;
- float Adeg;
- float Arad;
- float X;
- float Y;
-
-
- for (Adeg=1;Adeg<360;Adeg++)
- {
- Arad=(Adeg*pi)/180;
- X=cos(Arad);
- Y=sin(Arad);
- putpixel((X*rayon)+x,(Y*rayon)+y,couleur);
- }
- }
- //==============================================================================
- void serpent::cercleBis(int x, int y, int rayon,int couleur)
- {
-
- const float pi=3.14;
- float Adeg;
- float Arad;
- float X;
- float Y;
-
-
- for (Adeg=1;Adeg<360;Adeg=Adeg+15)
- {
- Arad=(Adeg*pi)/180;
- X=cos(Arad);
- Y=sin(Arad);
- putpixel((X*rayon)+x,(Y*rayon)+y,couleur);
- }
- }
-
- //==============================================================================
-
-
-
-
- void serpent::verti(int X,int y1,int y2,int col)
- {
- for (int Y=y1;Y<y2;Y++)
- {
- putpixel(X,Y,col);
-
- }
-
-
- }
- //==============================================================================
- void serpent::corps(int x,int y,int col){
-
-
- int rayon=1;
- int bleu;
-
- if (col!=0){
-
-
- for (bleu=43+col;bleu>=0+col;bleu=bleu-10)
- {
- cercle(x,y,rayon,bleu);
- rayon++;
- }
- }
-
- if (col==0)
- {
- for (bleu=43;bleu>=0;bleu=bleu-10)
- {
- cercle(x,y,rayon,0);
- rayon++;
- }
- }
- }
- //==============================================================================
- void serpent::cadre()
- {
-
-
-
- for (int i=14;i<306;i++){
- putpixel(i,14,63);
- putpixel(i,13,53);
- putpixel(i,12,43);
- }
-
- for (i=14;i<306;i++){
- putpixel(i,185,63);
- putpixel(i,186,53);
- putpixel(i,187,43);
-
- }
-
-
- for (i=15;i<185;i++){
- putpixel(14,i,63);
- putpixel(13,i,53);
- putpixel(12,i,43);
- }
-
-
- for (i=15;i<185;i++){
- putpixel(305,i,63);
- putpixel(306,i,53);
- putpixel(307,i,43);
- }
-
- }
-
-
-
- //==============================================================================
- void serpent :: pomme(int &x,int &y)
- {
-
- randomize();
-
- int color=1;
-
- while (color!=0){
-
- x=(((rand()%28)+2)*10);
- y=(((rand()%16)+2)*10);
- color=getpixel(x,y);
- }
-
-
- corps(x,y,1);
-
- }
- //==============================================================================
-
-
- void serpent::generePomme()
- {
-
- int x,y;
- for (int i=0;i<=10;i++)
- {
- pomme(x,y);
- }
-
-
-
- }
-
- //==============================================================================
- int serpent::verifDanger(int X,int Y,int addX,int addY,int espace,int score,int couleur){
-
- int THEX,THEY;
- int detectColor;
-
- if (addX==espace){
- THEX=X+espace+4;
- THEY=Y;
- }
-
- if (addX==-espace){
- THEX=X-espace-5;
- THEY=Y;
- }
-
- if (addY==espace){
- THEX=X;
- THEY=Y+espace+4;
- }
-
- if (addY==-espace){
- THEX=X;
- THEY=Y-espace-5;
- }
-
-
-
- detectColor=getpixel(THEX,THEY);
-
-
- if (( THEX>320) || (THEX<0) || (THEY>200) || (THEY<0) ) {
- affichePerdu();
- ecrireMaxScore(score);
- return 0;
- }
-
-
-
- if (detectColor==couleur+3){
-
- affichePerdu();
- ecrireMaxScore(score);
- return 0;
- }
-
- return 1;
- }
- //==============================================================================
-
- void serpent::affichePerdu(){
-
-
- gotoxy(17,10);
- cout<<"PERDU";
- }
- //==============================================================================
- void serpent::lireMaxScore()
- {
- FILE*fichier;
-
-
- fichier=fopen("score.idk", "r");
-
- fgets(scoreMax, strlen("1000"), fichier);
-
- gotoxy(20,1);
- cout<<"HIGHT SCORE: "<<scoreMax;
-
-
-
- }
-
-
- //==============================================================================
- void serpent::ecrireMaxScore(int score){
- char *scoreString="";
- int scoreMaxInt=atoi(scoreMax);
-
-
- if (score > scoreMaxInt)
- {
- FILE *fichier;
- fichier=fopen("score.idk","w+");
- itoa(score, scoreString, 10);
- fputs(scoreString, fichier);
- fclose(fichier);
-
- }
- }
-
-
-
- //==============================================================================
- int serpent::controle(int &addX,int &addY,int espace)
- {
-
- int touche=0;
- if (kbhit())
- {
- touche=getch();
- switch (touche)
- {
- case 77:if (addX!=-espace){
- addX=espace;
- addY=0;}
- break;
-
- case 75: if (addX!=espace){
- addX=-espace;
- addY=0;}
- break;
-
- case 72: if (addY!=espace){
- addX=0;
- addY=-espace;}
- break;
-
- case 80: if (addY!=-espace){
- addX=0;
- addY=espace;}
- break;
-
-
-
- }
-
- }
-
-
- return touche;
- }
- //==============================================================================
-
- void serpent::comptePomme(int X,int Y,int &Xpomme,int &Ypomme,int &nombrePomme,int &taille,int &pommeAffiche){
-
-
-
- if (pommeAffiche==0)
- {pomme(Xpomme,Ypomme);
- pommeAffiche=1;}
-
-
- if (( X==Xpomme) && (Y==Ypomme) )
- {
- pommeAffiche=0;
- nombrePomme++;
- taille++;
- }
-
-
-
-
- }
- //==============================================================================
-
- //------------------------//
- // MENU //
- //------------------------//
-
- void serpent:: presentation()
- {
-
-
-
-
- for (int i=0;i<64;i++)
- {
- if (kbhit())
- return ;
- ecrirePal(7,i,0,0);
- gotoxy(13,10);
- delay(100);
- cout<<" IDK PRODUCTION\n ";
- }
-
-
- for (i=63;i>=0;i--)
- {
- if (kbhit())
- return ;
- ecrirePal(7,i,0,0);
- gotoxy(13,10);
- delay(60);
- cout<<" IDK PRODUCTION\n ";
- }
-
-
- for ( i=0;i<64;i++)
- {
- if (kbhit())
- return ;
- ecrirePal(7,i,0,0);
- gotoxy(13,10);
- delay(100);
- cout<<" presente......\n ";
- }
-
-
- for (i=63;i>=0;i--)
- {
- if (kbhit())
- return ;
- ecrirePal(7,i,0,0);
- gotoxy(13,10);
- delay(60);
- cout<<" presente......\n ";
- }
-
-
- colToblack(20);
- cls();
- genPal();
- titre(40);
-
- getch();
- delay(100);
- colToblack(20);
- genPal();
- ecrirePal(7,63,63,63);
-
- }
- //==============================================================================
- int serpent::menu()
- {
-
- titre(40);
- int x=140,y=75;
- int r=63,v=63,b=63;
- int touche=0;
- int choix=1;
-
- ecrirePal(7,63,63,63);
- gotoxy(20,10);
- cout<<"JOUER\n";
- gotoxy(20,12);
- cout<<"HIGHT SCORE\n";
- gotoxy(20,14);
- cout<<"OPTION\n";
- gotoxy(20,16);
- cout<<"CREDITS";
- gotoxy(20,18);
- cout<<"QUITTER";
-
- while (touche!=13){
-
-
- r=r-1;
- v=v-1;
- b=b-1;
-
- if (choix==6){
- y=75;
- choix=1;}
-
- if (choix==0){
- y=138;
- choix=5;}
-
- corps(x,y,63);
-
-
-
- touche=getch();
-
-
- switch (touche)
- {
- case 80:corps(x,y,0);
- y=y+16;
- choix++;
- break;
-
- case 72:corps(x,y,0);
- choix--;
- y=y-16;
- break;
-
-
- }
-
- }
-
- return choix;
- }
-
-
-
- //=======================================================================
-
- void serpent::option()
- {
-
-
-
-
- int var=0;
- int plus=vitesseUser-22;
- int touche=0;
- int vitesse=vitesseUser;
- int y=20;
- int col=63;
- int choix=1;
- ecrirePal(7,63,63,63);
-
- gotoxy(4,3);
- cout<<"VITESSE:"<<endl;
- for (int X=200;X<=252;X=X+2){
- verti(X,20,25,30);}
-
- gotoxy(4,5);
- cout<<"COULEUR:"<<endl;
- for (X=200;X<260;X=X+10)
- corps(X,37,col);
-
- for (X=200;X<200+plus;X=X+2){
- verti(X,20,25,63);}
-
-
-
-
- while (touche!=13){
-
- if (choix==3){y=20;choix=1;}
- if (choix==0){y=36;choix=2;}
-
-
- corps(10,y,63);
- touche=getch();
-
- switch (touche){
- case 80:corps(10,y,0);
- y=y+16;
- choix++;
- break;
-
- case 72:corps(10,y,0);
- choix--;
- y=y-16;
- break;
- case 13:colUser=col;
- vitesseUser=vitesse;
- return ;
-
- }
-
-
-
- if (choix==2){ //choix couleur
-
-
-
- if (col>256)
- col=63;
- if (col<=0)
- col=255;
-
-
- switch(touche)
- {case 77:col=col+64;
- break;
-
- case 75:col=col-64;
- break;
-
- case 13:colUser=col;
- vitesseUser=vitesse;
- return ;}
-
- for (X=200;X<260;X=X+10)
- corps(X,37,col);
- }
-
-
-
-
- if (choix==1){ //choix vitesse
-
-
- vitesse=plus+22;
- gotoxy(14,3);
- cout<<vitesse<<" mSec";
-
-
- switch(touche)
- {
- case 77:
- if (plus>52)
- plus=52;
- plus=plus+2;
- for (X=200;X<200+plus;X=X+2){
- verti(X,20,25,63);}
- break;
-
- case 75: if (plus<0)
- plus=0;
- plus=plus-2;
- for (X=252;X>200+plus;X=X-2){
- verti(X,20,25,30);}
- break;
-
- case 13:colUser=col;
- vitesseUser=vitesse;
- return ; }
-
-
-
- }
-
-
-
-
-
-
- }
-
-
- }
- //============================================================================
-
- void serpent::genereOption() {
- colUser=63;
- vitesseUser=50;
-
- }
-
-
-
- //============================================================================
- void serpent::titre(int X){
-
-
- int Y=10;
-
-
-
- corps(X+8,Y,63);
- corps(X,Y,63);
- corps(X,Y+8,63);
- corps(X,Y+16,63);
- corps(X+8,Y+16,63);
- corps(X+8,Y+24,63);
- corps(X+8,Y+32,63);
- corps(X,Y+32,63);
-
-
- corps(X+36,10,63);
- corps(X+28,10,63);
- corps(X+28,18,63);
- corps(X+28,26,63);
- corps(X+36,26,63);
- corps(X+28,34,63);
- corps(X+28,42,63);
- corps(X+36,42,63);
-
-
- corps(X+56,10,63);
- corps(X+64,10,63);
- corps(X+72,10,63);
- corps(X+72,18,63);
- corps(X+72,26,63);
- corps(X+64,26,63);
- corps(X+64,34,63);
- corps(X+72,42,63);
- corps(X+56,18,63);
- corps(X+56,26,63);
- corps(X+56,34,63);
- corps(X+56,42,63);
-
-
- corps(X+100,10,63);
- corps(X+108,10,63);
- corps(X+108,18,63);
- corps(X+108,26,63);
- corps(X+100,26,63);
- corps(X+92,10,63);
- corps(X+92,18,63);
- corps(X+92,26,63);
- corps(X+92,34,63);
- corps(X+92,42,63);
-
-
- corps(X+136,10,63);
- corps(X+128,10,63);
- corps(X+128,18,63);
- corps(X+128,26,63);
- corps(X+136,26,63);
- corps(X+128,34,63);
- corps(X+128,42,63);
- corps(X+136,42,63);
-
-
- corps(X+156,10,63);
- corps(X+156,18,63);
- corps(X+164,18,63);
- corps(X+172,26,63);
- corps(X+180,42,63);
- corps(X+180,34,63);
- corps(X+180,26,63);
- corps(X+180,18,63);
- corps(X+180,10,63);
- corps(X+156,26,63);
- corps(X+156,34,63);
- corps(X+156,42,63);
-
-
- corps(X+200,10,63);
- corps(X+208,10,63);
- corps(X+216,10,63);
- corps(X+208,10,63);
- corps(X+208,18,63);
- corps(X+208,26,63);
- corps(X+208,34,63);
- corps(X+208,42,63);
-
-
- }
- //============================================================================
- void serpent::explosion(int x,int y)
- {
-
-
-
- for (int i=1;i<20;i++){
-
- cercleBis(x,y,i,colUser+50);
- cercleBis(x+1,y,i,colUser+40);
- cercleBis(x,y+1,i,colUser+30);
- delay(50);
- cercleBis(x,y,i,0);
- cercleBis(x+1,y,i,0);
- cercleBis(x,y+1,i,0);
-
- }
-
-
-
-
- }
-
-
-
-
-
-
-
-
-
- //============================================================================
-
- void serpent:: moteur(){
-
-
- const tailleMax=100;
- int espace=10;
-
- int vitesse=vitesseUser;
-
- int X[tailleMax];
- int Y[tailleMax];
- int Xst=-920;
- int Yst=100;
- int i;
- int touche;
- int addX=espace;
- int addY=0;
- int taille=5;
-
- int couleur=colUser;
-
- int pommeAffiche=0;
- int nombrePomme=0;
- int Xpomme,Ypomme;
- int score=0;
- int etat=1;
-
-
-
-
-
-
- ecrirePal(7,63,63,63);
- cls();
- cadre();
- lireMaxScore();
-
-
- //incrementation
- for (i=tailleMax-1;i>=0;i--)
- {X[i]=Xst;
- Y[i]=Yst;
- Xst=Xst+espace;}
-
- getch();
-
-
- while (1==1)
- {
-
-
-
- comptePomme(X[0],Y[0],Xpomme,Ypomme,nombrePomme,taille,pommeAffiche);
-
- score=nombrePomme*5;
- gotoxy(2,1);
- cout<<"SCORE: "<<score;
-
- etat=verifDanger(X[0],Y[0],addX,addY,espace,score,couleur);//DETECTION DANGER
-
- if (etat==0) {
- explosion(X[0],Y[0]);
- colToblack(20);
- break;
- }
-
- //moteur
- touche=controle(addX,addY,espace);//commande
- corps(X[taille],Y[taille],0);
-
- for (i=tailleMax-1;i>0;i--)
- {X[i]=X[i-1];
- Y[i]=Y[i-1];}
-
- X[0]=X[0]+addX;
- Y[0]=Y[0]+addY;
-
- corps(X[0],Y[0],couleur);
-
- delay(vitesse);
-
-
-
- touche=controle(addX,addY,espace); //commande
-
- }
-
-
- }
-
-
-
-
-
- //============================================================================
- int main()
- {
-
-
- serpent go;
- int choix;
-
- go.modeVGA();
- go.genPal();
-
-
- go.presentation();
- go.genereOption();
-
- while (1==1){
- go.cls();
- go.genPal();
- choix=go.menu();
-
-
-
-
-
-
- switch(choix){
-
- case 1:go.moteur();
- break;
-
-
-
- case 3:go.cls();
- go.option();
- break;
-
- case 5: go.colToblack(30);
- go.modeTexte();
- cout<<"IDK production";
- exit(0);
-
- }
-
- }
-
-
-
-
- }
#include <iostream.h>
#include <conio.h>
#include <graphics.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <dos.h>
#include <string.h>
class serpent
{
public:
//fct graphique
unsigned char * ecran;
void modeVGA();
void modeTexte(){_AX=0x03;geninterrupt(0x10);}
void putpixel(int X, int Y,int couleur);
int getpixel(int X,int Y){return ecran[(Y*320)+X];}
void lirePal(unsigned char index, unsigned char &rouge, unsigned char &vert, unsigned char &bleue);
void ecrirePal(unsigned char index, unsigned char rouge, unsigned char vert, unsigned char bleue);
void genPal();
void cls (){ memset(ecran,0,64000L);}
int colToblack(unsigned temps);
//fct geometrique
void cercle(int x, int y, int rayon,int couleur);
void cercleBis(int x, int y, int rayon,int couleur);
void verti(int X,int y1,int y2,int col);
void corps (int x,int y,int col);
void cadre();
void pomme(int &x, int &y);
void generePomme();
//moteur
int verifDanger(int X,int Y,int addX,int addY,int espace,int score,int couleur);
void affichePerdu();
void lireMaxScore();
void ecrireMaxScore(int score);
int controle(int &addX,int &addY,int espace);
void comptePomme(int X,int Y,int &Xpomme,int &Ypomme,int &nombrePomme,int &taille,int &pommeAffiche);
//fct menu
void presentation();
int menu();
void option();
void genereOption();
void titre(int X);
void moteur();
void explosion(int x,int y);
private:
char *scoreMax;
int colUser;
int vitesseUser;
};
/*--------------------------------*/
/* FONCTION 13h */
/*--------------------------------*/
//==============================================================================
void serpent ::modeVGA(){
ecran=(unsigned char*) (0xA0000000L);
_AX=0x13;
geninterrupt(0x10);}
//==============================================================================
void serpent ::putpixel(int X, int Y,int couleur){
ecran[(Y*320)+X]=couleur;
}
//==============================================================================
int serpent::colToblack(unsigned temps){
unsigned char r,g,b;
for (int i=0;i<64;i++)
{
delay(temps);
for (int j=0;j<256;j++)
{
lirePal(j,r,g,b);
if (r>0)r--;
if (g>0)g--;
if (b>0)b--;
ecrirePal((unsigned char)j,r,g,b);
}
}
return 0;
}
//==============================================================================
//==============================================================================
void serpent::lirePal(unsigned char index, unsigned char &rouge, unsigned char &vert, unsigned char &bleue)
{
outportb(0x03C7,index);
rouge= inportb(0x03C9);
vert = inportb(0x03C9);
bleue = inportb(0x03C9);
}
//==============================================================================
void serpent::ecrirePal(unsigned char index, unsigned char rouge, unsigned char vert, unsigned char bleue)
{
outportb(0x03C8,index);
outportb(0x03C9,rouge);
outportb(0x03C9,vert);
outportb(0x03C9,bleue);
}
//==============================================================================
void serpent::genPal()
{
for (int i=0;i<=63;i++) ecrirePal(i,i,0,0); // 64 tons de rouge
for (i=64;i<=127;i++) ecrirePal(i,0,i,0); // 64 tons de vert
for (i=128;i<=191;i++) ecrirePal(i,0,0,i); // 64 tons de bleu
for (i=192;i<=255;i++) ecrirePal(i,i,i,i); // 64 tons de gris
}
//==============================================================================
/*--------------------------------*/
/* FONCTION GEOMETRIQUE */
/*--------------------------------*/
void serpent::cercle(int x, int y, int rayon,int couleur)
{
const float pi=3.14;
float Adeg;
float Arad;
float X;
float Y;
for (Adeg=1;Adeg<360;Adeg++)
{
Arad=(Adeg*pi)/180;
X=cos(Arad);
Y=sin(Arad);
putpixel((X*rayon)+x,(Y*rayon)+y,couleur);
}
}
//==============================================================================
void serpent::cercleBis(int x, int y, int rayon,int couleur)
{
const float pi=3.14;
float Adeg;
float Arad;
float X;
float Y;
for (Adeg=1;Adeg<360;Adeg=Adeg+15)
{
Arad=(Adeg*pi)/180;
X=cos(Arad);
Y=sin(Arad);
putpixel((X*rayon)+x,(Y*rayon)+y,couleur);
}
}
//==============================================================================
void serpent::verti(int X,int y1,int y2,int col)
{
for (int Y=y1;Y<y2;Y++)
{
putpixel(X,Y,col);
}
}
//==============================================================================
void serpent::corps(int x,int y,int col){
int rayon=1;
int bleu;
if (col!=0){
for (bleu=43+col;bleu>=0+col;bleu=bleu-10)
{
cercle(x,y,rayon,bleu);
rayon++;
}
}
if (col==0)
{
for (bleu=43;bleu>=0;bleu=bleu-10)
{
cercle(x,y,rayon,0);
rayon++;
}
}
}
//==============================================================================
void serpent::cadre()
{
for (int i=14;i<306;i++){
putpixel(i,14,63);
putpixel(i,13,53);
putpixel(i,12,43);
}
for (i=14;i<306;i++){
putpixel(i,185,63);
putpixel(i,186,53);
putpixel(i,187,43);
}
for (i=15;i<185;i++){
putpixel(14,i,63);
putpixel(13,i,53);
putpixel(12,i,43);
}
for (i=15;i<185;i++){
putpixel(305,i,63);
putpixel(306,i,53);
putpixel(307,i,43);
}
}
//==============================================================================
void serpent :: pomme(int &x,int &y)
{
randomize();
int color=1;
while (color!=0){
x=(((rand()%28)+2)*10);
y=(((rand()%16)+2)*10);
color=getpixel(x,y);
}
corps(x,y,1);
}
//==============================================================================
void serpent::generePomme()
{
int x,y;
for (int i=0;i<=10;i++)
{
pomme(x,y);
}
}
//==============================================================================
int serpent::verifDanger(int X,int Y,int addX,int addY,int espace,int score,int couleur){
int THEX,THEY;
int detectColor;
if (addX==espace){
THEX=X+espace+4;
THEY=Y;
}
if (addX==-espace){
THEX=X-espace-5;
THEY=Y;
}
if (addY==espace){
THEX=X;
THEY=Y+espace+4;
}
if (addY==-espace){
THEX=X;
THEY=Y-espace-5;
}
detectColor=getpixel(THEX,THEY);
if (( THEX>320) || (THEX<0) || (THEY>200) || (THEY<0) ) {
affichePerdu();
ecrireMaxScore(score);
return 0;
}
if (detectColor==couleur+3){
affichePerdu();
ecrireMaxScore(score);
return 0;
}
return 1;
}
//==============================================================================
void serpent::affichePerdu(){
gotoxy(17,10);
cout<<"PERDU";
}
//==============================================================================
void serpent::lireMaxScore()
{
FILE*fichier;
fichier=fopen("score.idk", "r");
fgets(scoreMax, strlen("1000"), fichier);
gotoxy(20,1);
cout<<"HIGHT SCORE: "<<scoreMax;
}
//==============================================================================
void serpent::ecrireMaxScore(int score){
char *scoreString="";
int scoreMaxInt=atoi(scoreMax);
if (score > scoreMaxInt)
{
FILE *fichier;
fichier=fopen("score.idk","w+");
itoa(score, scoreString, 10);
fputs(scoreString, fichier);
fclose(fichier);
}
}
//==============================================================================
int serpent::controle(int &addX,int &addY,int espace)
{
int touche=0;
if (kbhit())
{
touche=getch();
switch (touche)
{
case 77:if (addX!=-espace){
addX=espace;
addY=0;}
break;
case 75: if (addX!=espace){
addX=-espace;
addY=0;}
break;
case 72: if (addY!=espace){
addX=0;
addY=-espace;}
break;
case 80: if (addY!=-espace){
addX=0;
addY=espace;}
break;
}
}
return touche;
}
//==============================================================================
void serpent::comptePomme(int X,int Y,int &Xpomme,int &Ypomme,int &nombrePomme,int &taille,int &pommeAffiche){
if (pommeAffiche==0)
{pomme(Xpomme,Ypomme);
pommeAffiche=1;}
if (( X==Xpomme) && (Y==Ypomme) )
{
pommeAffiche=0;
nombrePomme++;
taille++;
}
}
//==============================================================================
//------------------------//
// MENU //
//------------------------//
void serpent:: presentation()
{
for (int i=0;i<64;i++)
{
if (kbhit())
return ;
ecrirePal(7,i,0,0);
gotoxy(13,10);
delay(100);
cout<<" IDK PRODUCTION\n ";
}
for (i=63;i>=0;i--)
{
if (kbhit())
return ;
ecrirePal(7,i,0,0);
gotoxy(13,10);
delay(60);
cout<<" IDK PRODUCTION\n ";
}
for ( i=0;i<64;i++)
{
if (kbhit())
return ;
ecrirePal(7,i,0,0);
gotoxy(13,10);
delay(100);
cout<<" presente......\n ";
}
for (i=63;i>=0;i--)
{
if (kbhit())
return ;
ecrirePal(7,i,0,0);
gotoxy(13,10);
delay(60);
cout<<" presente......\n ";
}
colToblack(20);
cls();
genPal();
titre(40);
getch();
delay(100);
colToblack(20);
genPal();
ecrirePal(7,63,63,63);
}
//==============================================================================
int serpent::menu()
{
titre(40);
int x=140,y=75;
int r=63,v=63,b=63;
int touche=0;
int choix=1;
ecrirePal(7,63,63,63);
gotoxy(20,10);
cout<<"JOUER\n";
gotoxy(20,12);
cout<<"HIGHT SCORE\n";
gotoxy(20,14);
cout<<"OPTION\n";
gotoxy(20,16);
cout<<"CREDITS";
gotoxy(20,18);
cout<<"QUITTER";
while (touche!=13){
r=r-1;
v=v-1;
b=b-1;
if (choix==6){
y=75;
choix=1;}
if (choix==0){
y=138;
choix=5;}
corps(x,y,63);
touche=getch();
switch (touche)
{
case 80:corps(x,y,0);
y=y+16;
choix++;
break;
case 72:corps(x,y,0);
choix--;
y=y-16;
break;
}
}
return choix;
}
//=======================================================================
void serpent::option()
{
int var=0;
int plus=vitesseUser-22;
int touche=0;
int vitesse=vitesseUser;
int y=20;
int col=63;
int choix=1;
ecrirePal(7,63,63,63);
gotoxy(4,3);
cout<<"VITESSE:"<<endl;
for (int X=200;X<=252;X=X+2){
verti(X,20,25,30);}
gotoxy(4,5);
cout<<"COULEUR:"<<endl;
for (X=200;X<260;X=X+10)
corps(X,37,col);
for (X=200;X<200+plus;X=X+2){
verti(X,20,25,63);}
while (touche!=13){
if (choix==3){y=20;choix=1;}
if (choix==0){y=36;choix=2;}
corps(10,y,63);
touche=getch();
switch (touche){
case 80:corps(10,y,0);
y=y+16;
choix++;
break;
case 72:corps(10,y,0);
choix--;
y=y-16;
break;
case 13:colUser=col;
vitesseUser=vitesse;
return ;
}
if (choix==2){ //choix couleur
if (col>256)
col=63;
if (col<=0)
col=255;
switch(touche)
{case 77:col=col+64;
break;
case 75:col=col-64;
break;
case 13:colUser=col;
vitesseUser=vitesse;
return ;}
for (X=200;X<260;X=X+10)
corps(X,37,col);
}
if (choix==1){ //choix vitesse
vitesse=plus+22;
gotoxy(14,3);
cout<<vitesse<<" mSec";
switch(touche)
{
case 77:
if (plus>52)
plus=52;
plus=plus+2;
for (X=200;X<200+plus;X=X+2){
verti(X,20,25,63);}
break;
case 75: if (plus<0)
plus=0;
plus=plus-2;
for (X=252;X>200+plus;X=X-2){
verti(X,20,25,30);}
break;
case 13:colUser=col;
vitesseUser=vitesse;
return ; }
}
}
}
//============================================================================
void serpent::genereOption() {
colUser=63;
vitesseUser=50;
}
//============================================================================
void serpent::titre(int X){
int Y=10;
corps(X+8,Y,63);
corps(X,Y,63);
corps(X,Y+8,63);
corps(X,Y+16,63);
corps(X+8,Y+16,63);
corps(X+8,Y+24,63);
corps(X+8,Y+32,63);
corps(X,Y+32,63);
corps(X+36,10,63);
corps(X+28,10,63);
corps(X+28,18,63);
corps(X+28,26,63);
corps(X+36,26,63);
corps(X+28,34,63);
corps(X+28,42,63);
corps(X+36,42,63);
corps(X+56,10,63);
corps(X+64,10,63);
corps(X+72,10,63);
corps(X+72,18,63);
corps(X+72,26,63);
corps(X+64,26,63);
corps(X+64,34,63);
corps(X+72,42,63);
corps(X+56,18,63);
corps(X+56,26,63);
corps(X+56,34,63);
corps(X+56,42,63);
corps(X+100,10,63);
corps(X+108,10,63);
corps(X+108,18,63);
corps(X+108,26,63);
corps(X+100,26,63);
corps(X+92,10,63);
corps(X+92,18,63);
corps(X+92,26,63);
corps(X+92,34,63);
corps(X+92,42,63);
corps(X+136,10,63);
corps(X+128,10,63);
corps(X+128,18,63);
corps(X+128,26,63);
corps(X+136,26,63);
corps(X+128,34,63);
corps(X+128,42,63);
corps(X+136,42,63);
corps(X+156,10,63);
corps(X+156,18,63);
corps(X+164,18,63);
corps(X+172,26,63);
corps(X+180,42,63);
corps(X+180,34,63);
corps(X+180,26,63);
corps(X+180,18,63);
corps(X+180,10,63);
corps(X+156,26,63);
corps(X+156,34,63);
corps(X+156,42,63);
corps(X+200,10,63);
corps(X+208,10,63);
corps(X+216,10,63);
corps(X+208,10,63);
corps(X+208,18,63);
corps(X+208,26,63);
corps(X+208,34,63);
corps(X+208,42,63);
}
//============================================================================
void serpent::explosion(int x,int y)
{
for (int i=1;i<20;i++){
cercleBis(x,y,i,colUser+50);
cercleBis(x+1,y,i,colUser+40);
cercleBis(x,y+1,i,colUser+30);
delay(50);
cercleBis(x,y,i,0);
cercleBis(x+1,y,i,0);
cercleBis(x,y+1,i,0);
}
}
//============================================================================
void serpent:: moteur(){
const tailleMax=100;
int espace=10;
int vitesse=vitesseUser;
int X[tailleMax];
int Y[tailleMax];
int Xst=-920;
int Yst=100;
int i;
int touche;
int addX=espace;
int addY=0;
int taille=5;
int couleur=colUser;
int pommeAffiche=0;
int nombrePomme=0;
int Xpomme,Ypomme;
int score=0;
int etat=1;
ecrirePal(7,63,63,63);
cls();
cadre();
lireMaxScore();
//incrementation
for (i=tailleMax-1;i>=0;i--)
{X[i]=Xst;
Y[i]=Yst;
Xst=Xst+espace;}
getch();
while (1==1)
{
comptePomme(X[0],Y[0],Xpomme,Ypomme,nombrePomme,taille,pommeAffiche);
score=nombrePomme*5;
gotoxy(2,1);
cout<<"SCORE: "<<score;
etat=verifDanger(X[0],Y[0],addX,addY,espace,score,couleur);//DETECTION DANGER
if (etat==0) {
explosion(X[0],Y[0]);
colToblack(20);
break;
}
//moteur
touche=controle(addX,addY,espace);//commande
corps(X[taille],Y[taille],0);
for (i=tailleMax-1;i>0;i--)
{X[i]=X[i-1];
Y[i]=Y[i-1];}
X[0]=X[0]+addX;
Y[0]=Y[0]+addY;
corps(X[0],Y[0],couleur);
delay(vitesse);
touche=controle(addX,addY,espace); //commande
}
}
//============================================================================
int main()
{
serpent go;
int choix;
go.modeVGA();
go.genPal();
go.presentation();
go.genereOption();
while (1==1){
go.cls();
go.genPal();
choix=go.menu();
switch(choix){
case 1:go.moteur();
break;
case 3:go.cls();
go.option();
break;
case 5: go.colToblack(30);
go.modeTexte();
cout<<"IDK production";
exit(0);
}
}
}
Conclusion
Le but du jeu c'est de prendre les pommes et de trouver les bugs!
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
RE : SAC A DOS RE : SAC A DOS par hadjkaddour
Cliquez pour lire la suite par hadjkaddour
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|