begin process at 2012 05 27 19:12:47
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Jeux

 > SERPENT BETA0.9999

SERPENT BETA0.9999


 Information sur la source

Note :
9 / 10 - par 1 personne
9,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Jeux Niveau :Initié Date de création :06/01/2002 Date de mise à jour :06/01/2002 16:08:19 Vu / téléchargé :4 027 / 142

Auteur : istdasklar

Ecrire un message privé
Commentaire sur cette source (4)
Ajouter un commentaire et/ou une note

 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!  

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
  • SCORE.IDKTélécharger ce fichier [Réservé aux membres club]5 octets
  • SERPENT4.CPPTélécharger ce fichier [Réservé aux membres club]Voir ce fichier15 498 octets
  • SERPENT4.EXETélécharger ce fichier [Réservé aux membres club]118 392 octets

Télécharger le zip


 Sources de la même categorie

Source avec Zip Source avec une capture JEU DES CARTES par eapaceinfo
PROGRAMME DE JEU DE MPT par KerizGarmm
Source avec Zip Source avec une capture JEUX SERPENT par antho974
Source avec Zip Source avec une capture PENDU EN SDL par Damsou91
Source avec Zip STATE MACHINE MODIFICATION MATH BUCKHAM par billybones79

Commentaires et avis

Commentaire de Jo le 06/01/2002 20:33:38

Salut, pourrait tu indiquer le nom du compilateur, dans le titre ou au-dessu de ta source, que tu a utilise pour compiler ton programm.

Commentaire de NerOcrO le 06/01/2002 20:57:31

Il faut mettre "int i, X;" au début sinon il ne reconnaît pas ces variables.
Après teste du jeu très rapide, j'ai vu que le serpent peut se mordre la queue sans qu'on perde.
Sinon, il est bien foutu, mais le code, va falloir revoir ça, c'est presque illisible.

Commentaire de djnos le 29/08/2005 15:58:49

Allez mon vieux IDK, ta source m'a pas trop fait pitié, j'ai donc choisi de te mettre 9/10 mais faudra faire mieux la prochaine fois :
tu utiliseras plutôt GLUT pour nous faire de l'opengl et tout... OK.

Bravo quand même, même si, c'est sale...

Commentaire de istdasklar le 20/08/2007 01:48:26

DJnos....j'ai programmé ce truc, à l'epoque ou tu savais meme pas demarrer ton pc....

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,421 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales