begin process at 2012 05 27 19:21:14
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Jeux

 > UN SNAKE AVEC PRESQUE PAS DE BUGS

UN SNAKE AVEC PRESQUE PAS DE BUGS


 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 :Débutant Date de création :02/02/2004 Vu / téléchargé :3 590 / 295

Auteur : skinia

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

 Description

Cliquez pour voir la capture en taille normale
j'ai pas pu mettre l'exe car devc++5 genere des monstres de 500 Ko
j'sais pas pourquoi?

Source

  • /*
  • Name: SNAKE 2003
  • Copyright:
  • Author: $kinia
  • Date: 2/02/04 14:21
  • Description: Jeu du Snake compile avec dev-c++ 5
  • */
  • #include <fstream.h>
  • #include <conio.c>
  • #include <cstdlib>
  • #include <ctime>
  • #define GAUCHE 75
  • #define DROITE 77
  • #define HAUT 72
  • #define BAS 80
  • #define ENTER 13
  • #define ESC 27
  • struct Coord{
  • int x;
  • int y;
  • };
  • /********************************************************/
  • /*variables utilisees dans jeu()*/
  • int vitesse = 50;//vitesse du snake en miles/h
  • int gpomme=5;//nb de pommes a bouffer avnt un bonus
  • int gbonus=3;//nb de bonus a passer avnt de changer de niv
  • int time_bonus;
  • /********************************************************/
  • int NB_PARTIES;
  • int INTRO;
  • int NB_NIVEAUX;
  • int VIES;
  • bool DEBUT;
  • bool invincible;
  • /*score inscrit ds un fichier*/
  • int MAX_SCORE;
  • char nom_fichier[40] = "C:/WINDOWS/Snake_Max_Score.txt";
  • fstream fichier;
  • /*pour le chargement des niveaux*/
  • int Niv[80][23];
  • fstream fich;
  • char* Niveau[10];
  • /*============================================================================*/
  • /* FONCTIONS SECONDAIRES POUR L'INTERFACE ET AUTRES */
  • /*============================================================================*/
  • void efface_menu()
  • {
  • gotoxy(1,1);
  • for(int i=1; i<79; i++)
  • cout << " ";
  • }
  • void message(char* mess1)
  • {
  • textcolor(LIGHTBLUE);
  • gotoxy(50,1);
  • cout << mess1;
  • getch();
  • efface_menu();
  • }
  • void gameOver()
  • {
  • Beep(200,100);
  • message("===== GAME OVER =====");
  • }
  • int affiche(Coord snak[],Coord p,Coord b,int t,int s,int ind){
  • int i, j, ms = 100;
  • //si le code d'invincibilite n'est pas rentre
  • if(!invincible && !DEBUT)
  • {
  • //si snake bouffe sa queue
  • for(i = 2; i < t; i++){
  • if(snak[0].x == snak[i].x && snak[0].y == snak[i].y){
  • gameOver();
  • return 0;
  • }
  • }
  • }
  • DEBUT=false;
  • //teste les collisions avec des paroies
  • for(i=0; i<23; i++){
  • for(int j=0; j<80; j++){
  • if(Niv[j][i]==1){
  • if(snak[0].x==(j+1) && snak[0].y==(i+3))
  • {
  • gameOver();
  • return 0;
  • }
  • }
  • }
  • }
  • //dessine le snake
  • for(i = 0; i < t; i++){
  • gotoxy(snak[i].x, snak[i].y);
  • if(i == 0){
  • textcolor(9);
  • cout << "\x2";
  • }
  • else{
  • if(i == t-1){
  • textcolor(BLACK);
  • cout << " ";
  • }
  • else{
  • if(i == t-2){
  • textcolor(9);
  • cout << "\xf";
  • }
  • else{
  • textcolor(26);
  • cout << " ";
  • }
  • }
  • }
  • }
  • gotoxy(snak[0].x, snak[0].y);
  • textcolor(9);
  • cout << "\x2";
  • //dessine la pomme
  • gotoxy(p.x, p.y);
  • textcolor(12);
  • cout << "\x9d";
  • if(b.x<100 && b.y<100)
  • {
  • //dessine le bonus
  • gotoxy(b.x, b.y);
  • textcolor(14);
  • cout << "\xf5";
  • gotoxy(75,1);
  • cout<<time_bonus << " ";
  • }
  • //dessine le score
  • gotoxy(1, 2);
  • for(i = 0; i < 80; i++)
  • cout << "\xC4";
  • gotoxy(2,1);
  • textcolor(LIGHTRED);
  • for(i=0; i<VIES; i++)
  • cout << "\x3";
  • textcolor(WHITE);
  • cout << " Score: " << s;
  • if(s >= MAX_SCORE) MAX_SCORE = s;
  • cout << " Record: " << MAX_SCORE;
  • //dessine le No niveau
  • cout << " LEVEL " << ind;
  • return 1;
  • }
  • void intro(){
  • int x, y;
  • int i, vit = 5;
  • textcolor(26);
  • //S
  • x = 20, y = 5;
  • for(i = 0; i < 10; i++){ gotoxy(x - i, y); cout << " ";Sleep(vit);} x = 10;
  • for(i = 0; i < 8; i++){ gotoxy(x, y + i);cout << " ";Sleep(vit);} y = 13;
  • for(i = 0; i < 10; i++){ gotoxy(x + i, y); cout << " ";Sleep(vit);} x = 20;
  • for(i = 0; i < 8; i++){ gotoxy(x, y + i);cout << " ";Sleep(vit);} y = 21;
  • for(i = 0; i <= 10; i++){ gotoxy(x - i, y); cout << " ";Sleep(vit);}
  • //N
  • x = 23, y = 21;
  • for(i = 0; i < 16; i++){ gotoxy(x, y - i); cout << " ";Sleep(vit);} y = 5;
  • for(i = 0; i < 10; i++){ gotoxy(x + i, y + i);cout << " ";Sleep(vit);} x = 33; y = 21;
  • for(i = 0; i <= 16; i++){ gotoxy(x, y - i); cout << " ";Sleep(vit);}
  • //A
  • x = 36, y = 21;
  • for(i = 0; i < 16; i++){ gotoxy(x, y - i); cout << " ";Sleep(vit);} y = 5;
  • for(i = 0; i < 10; i++){ gotoxy(x + i, y);cout << " ";Sleep(vit);} x = 46;
  • for(i = 0; i <= 16; i++){ gotoxy(x, y + i); cout << " ";Sleep(vit);} x = 36; y = 12;
  • for(i = 0; i < 10; i++){ gotoxy(x + i, y);cout << " ";Sleep(vit);}
  • //K
  • x = 49, y = 21;
  • for(i = 0; i <= 16; i++){ gotoxy(x, y - i); cout << " ";Sleep(vit);} y = 12;
  • for(i = 0; i < 10; i++){ gotoxy(x + i, y + i);cout << " ";Sleep(vit);} x = 49, y = 14;
  • for(i = 0; i < 10; i++){ gotoxy(x + i, y - i);cout << " ";Sleep(vit);}
  • //E
  • x = 71, y = 5;
  • for(i = 0; i < 10; i++){ gotoxy(x - i, y); cout << " ";Sleep(vit);} x = 61;
  • for(i = 0; i < 16; i++){ gotoxy(x, y + i);cout << " ";Sleep(vit);} y = 21;
  • for(i = 0; i <= 10; i++){ gotoxy(x + i, y); cout << " ";Sleep(vit);} x = 61; y = 13;
  • for(i = 0; i < 8; i++){ gotoxy(x + i, y);cout << " ";Sleep(vit);}
  • textcolor(LIGHTBLUE);
  • gotoxy(72, 21);
  • cout << " 2003 ";
  • getch();
  • }
  • void dessineNiveau()
  • {
  • //dessine le niveau
  • textcolor(11);
  • for(int i=0; i<23; i++){
  • for(int j=0; j<80; j++){
  • if(Niv[j][i]==1){
  • gotoxy(j+1,i+3);
  • cout << "\xdb";
  • }
  • }
  • }
  • gotoxy(1,1);
  • }
  • void aide()
  • {
  • int x=21;
  • textcolor(26);
  • gotoxy(x+1,8);cout << " " << endl;
  • gotoxy(x,9);cout << " AIDE " << endl;
  • gotoxy(x,10);cout << " " << endl;
  • gotoxy(x,11);cout << " Z ------- monter! " << endl;
  • gotoxy(x,12);cout << " S ------- descendre! " << endl;
  • gotoxy(x,13);cout << " Q ------- gauche! " << endl;
  • gotoxy(x,14);cout << " D ------- droite! " << endl;
  • gotoxy(x,15);cout << " ESC ----- quitter! " << endl;
  • gotoxy(x,16);cout << " C ------- prompt! " << endl;
  • gotoxy(x,17);cout << " AUTRE --- pause! " << endl;
  • gotoxy(x,18);cout << " " << endl;
  • gotoxy(x,19);cout << " A l'invite du prompt taper \"aide\" pour " << endl;
  • gotoxy(x,20);cout << " acceder a l'aide a tout moment du jeu, " << endl;
  • gotoxy(x,21);cout << " ou \"man\" pour toutes les commandes. " << endl;
  • gotoxy(x+1,22);cout << " " << endl;
  • message("===== PRET? ===== ");
  • textcolor(BLACK);
  • clrscr();
  • dessineNiveau();
  • }
  • //lit le fichier score
  • void lecture()
  • {
  • fichier.open(nom_fichier, ios::in);
  • if(!fichier.good())
  • MAX_SCORE = 0;
  • else
  • fichier >> MAX_SCORE >> INTRO;
  • fichier.close();
  • }
  • //ecrit le nouveau score
  • void ecriture()
  • {
  • fichier.open(nom_fichier, ios::out);
  • fichier << MAX_SCORE << " " << INTRO;
  • fichier.close();
  • }
  • void prompt()
  • {
  • char code[50];
  • gotoxy(50,1);
  • cout << "[prompt@snake]$ ";
  • cin >> code;
  • textcolor(26);
  • if(strcmp(code, "snakeinvincible") == 0)
  • {
  • if(!invincible) invincible = true;
  • else invincible = false;
  • }
  • if(strcmp(code, "aide") == 0)
  • aide();
  • if(strcmp(code, "man") == 0){
  • int x=25;
  • gotoxy(x+1, 11);cout << " ";
  • gotoxy(x, 12);cout << " 'aide' affiche l'aide du jeu ";
  • gotoxy(x, 13);cout << " 'intro' (des)active l'intro ";
  • gotoxy(x, 14);cout << " 'mail' pour des suggestions ";
  • gotoxy(x, 15);cout << " 'man' affiche ce manuel ";
  • gotoxy(x+1, 16);cout << " ";
  • getch();
  • }
  • if(strcmp(code, "mail") == 0){
  • int x=20;
  • gotoxy(x+1, 11);cout << " ";
  • gotoxy(x, 12);cout << " Pour toute suggestion envoyez un mail a ";
  • gotoxy(x, 13);cout << " cbwinny@yahoo.fr ";
  • gotoxy(x+1, 14);cout << " ";
  • getch();
  • }
  • if(strcmp(code, "intro") == 0){
  • int x=28;
  • gotoxy(x+1,10);cout << " ";
  • if(INTRO){
  • INTRO=0;
  • gotoxy(x, 11);cout << " L'intro a ete desactive ";
  • }
  • else{
  • INTRO=1;
  • gotoxy(x, 11);cout << " L'intro a ete active ";
  • }
  • gotoxy(x+1,12);cout << " ";
  • getch();
  • }
  • textcolor(BLACK);
  • clrscr();
  • dessineNiveau();
  • }
  • /*============================================================================*/
  • /* MOTEUR DU JEU */
  • /*============================================================================*/
  • void initialiseNiveaux()
  • {
  • Niveau[1]="Niveau1";
  • Niveau[2]="Niveau2";
  • Niveau[3]="Niveau3";
  • Niveau[4]="Niveau4";
  • NB_NIVEAUX=4;
  • }
  • int chargeNiveau(int ind)
  • {
  • char c;
  • int i=0, j=0;
  • fich.open(Niveau[ind], ios::in);
  • if(!fich.good())
  • {
  • message("===== Probleme de NIVEAU =====");
  • return 0;
  • }
  • while(!fich.eof()){
  • fich.get(c);
  • switch(c)
  • {
  • case 'H':
  • Niv[j][i]=1;
  • break;
  • case ' ':
  • Niv[j][i]=0;
  • break;
  • default:
  • break;
  • }
  • if(c=='\n'){
  • i++;
  • j=0;
  • }
  • else j++;
  • }
  • fich.close();
  • return 1;
  • }
  • void cherche_pomme(Coord snake[], Coord &p, int taille){
  • int x, y;
  • int exit, ind;
  • do{
  • exit = 1;
  • x = (rand() % 79) + 1;
  • y = (rand() % 22) + 3;
  • ind = 0;
  • //verifie si la pomme n'est pas ds le serpent
  • while(ind <= taille && exit){
  • if(x == snake[ind].x && y == snake[ind].y)
  • exit = 0;
  • ind++;
  • }
  • //verifie si la pomme n'est pas ds le mur
  • for(int i=0; i<23; i++){
  • for(int j=0; j<80; j++){
  • if(Niv[j][i]==1){
  • if(x==(j+1) && y==(i+3))
  • exit=0;
  • }
  • if(!exit) break;
  • }
  • if(!exit) break;
  • }
  • }while(! exit);
  • p.x = x;
  • p.y = y;
  • }
  • void cherche_bonus(Coord snake[], Coord &b, int taille)
  • {
  • cherche_pomme(snake, b, taille);
  • }
  • void initialisationJeu(int nb_niv, Coord snak[], Coord &s, Coord &p, int t)
  • {
  • int ni;
  • clrscr();
  • ni=chargeNiveau(nb_niv);
  • cherche_pomme(snak, p, t);
  • //initialisation du snake
  • s.x = 10, s.y = 23;
  • snak[0].x = s.x;
  • snak[0].y = s.y;
  • for(int i = 1; i < t; i++){
  • snak[i].x = s.x;
  • snak[i].y = s.y;
  • }
  • if(ni) dessineNiveau();
  • else exit(0);
  • }
  • //fonction qui gere le jeu
  • void jeu(){
  • Coord snake[1000];//coord du snake
  • Coord p;//coord de la pomme
  • Coord b;//coord du bonus
  • b.x=100; b.y=100;
  • Coord s;//coord de la tete du snake
  • int score = 0;
  • int taille = 5;
  • int i, exit = 0, v;
  • int sens=DROITE;
  • char c;//charactere appuye
  • int nb_pomme=0;//nb de pommes bouffees
  • int nb_bonus=0;//nb de bonus passes
  • int nb_niv=1;
  • initialisationJeu(nb_niv, snake, s, p, taille);
  • DEBUT=true;
  • affiche(snake, p, b, taille, score, nb_niv);
  • DEBUT=true;
  • if(NB_PARTIES == 1)
  • aide();
  • //grande boucle du jeu
  • while(!exit)
  • {
  • //qd on frappe une touche
  • while(kbhit())
  • {
  • switch(getch())
  • {
  • case 'z':
  • if(sens != BAS) sens = HAUT;
  • break;
  • case 's':
  • if(sens != HAUT) sens = BAS;
  • break;
  • case 'q':
  • if(sens != DROITE) sens = GAUCHE;
  • break;
  • case 'd':
  • if(sens != GAUCHE) sens = DROITE;
  • break;
  • case ESC:
  • exit = 1;
  • break;
  • case 'c':
  • prompt();
  • break;
  • default:
  • message("===== PAUSE =====");
  • break;
  • }
  • }
  • //qd on frappe pas de touches
  • while(!kbhit() && exit!=1)
  • {
  • time_bonus--;
  • //si snake bouffe la pomme
  • if(snake[0].x == p.x && snake[0].y == p.y){
  • score += 9;
  • taille += 3;
  • nb_pomme=(nb_pomme%gpomme)+1;
  • cherche_pomme(snake, p, taille);
  • if(nb_pomme == gpomme){
  • cherche_bonus(snake, b, taille);
  • time_bonus=45;
  • nb_bonus=(nb_bonus%gbonus)+1;
  • }
  • }
  • //si snake bouffe un bonus
  • if((snake[0].x == b.x && snake[0].y == b.y) || time_bonus == 0){
  • score += time_bonus*5;
  • taille += 3;
  • //enleve le bonus
  • if(time_bonus==0){
  • gotoxy(b.x,b.y);
  • cout << " ";
  • }
  • b.x=100;
  • b.y=100;
  • //si on change de niveau
  • if(nb_bonus==gbonus){
  • time_bonus=0;
  • nb_niv=(nb_niv%NB_NIVEAUX)+1;
  • initialisationJeu(nb_niv, snake, s, p, taille);
  • sens=DROITE;
  • DEBUT=true;
  • affiche(snake, p, b, taille, score, nb_niv);
  • DEBUT=true;
  • message("===== PRET =====");
  • }
  • efface_menu();
  • }
  • //v=0 -> recommence le jeu
  • v = affiche(snake, p, b, taille, score, nb_niv);
  • if(v == 0){
  • if(VIES==0){
  • NB_PARTIES++;
  • VIES=5;
  • jeu();//on recommence le jeu jusqua qu on le quitte grace
  • exit = 1;//a ESC et alors on exit (astuce pour quitter le jeu)
  • }
  • else{
  • VIES--;
  • initialisationJeu(nb_niv, snake, s, p, taille);
  • sens=DROITE;
  • DEBUT=true;
  • affiche(snake, p, b, taille, score, nb_niv);
  • DEBUT=true;
  • message("===== PRET =====");
  • }
  • }
  • for(int h = taille; h >=1; h--){
  • snake[h].x = snake[h - 1].x;
  • snake[h].y = snake[h - 1].y;
  • }
  • //deplace le snake dans telle direction
  • switch(sens)
  • {
  • case HAUT:
  • snake[0].x = s.x;
  • snake[0].y = --s.y;
  • if(snake[0].y == 2){
  • snake[0].y = 25;
  • s.y = 25;
  • }
  • break;
  • case BAS:
  • snake[0].x = s.x;
  • snake[0].y = ++s.y;
  • if(snake[0].y == 26){
  • snake[0].y = 3;
  • s.y = 3;
  • }
  • break;
  • case GAUCHE:
  • snake[0].x = --s.x;
  • snake[0].y = s.y;
  • if(snake[0].x == 0){
  • snake[0].x = 80;
  • s.x = 80;
  • }
  • break;
  • case DROITE:
  • snake[0].x = ++s.x;
  • snake[0].y = s.y;
  • if(snake[0].x == 80){
  • snake[0].x = 1;
  • s.x = 1;
  • }
  • break;
  • }
  • Sleep(vitesse);
  • }
  • }
  • }
  • /*============================================================================*/
  • /* FONCTION PRINCIPALE */
  • /*============================================================================*/
  • int main(){
  • srand(time(0));
  • system("title SNAKE 2003 by $kinia");
  • NB_PARTIES=1;
  • VIES=5;
  • invincible = false;
  • initialiseNiveaux();
  • lecture();//lit le score
  • if(INTRO) intro();
  • jeu();
  • ecriture();//ecrit le score
  • return 1;
  • }
/*
  Name: SNAKE 2003
  Copyright: 
  Author: $kinia
  Date: 2/02/04 14:21
  Description: Jeu du Snake compile avec dev-c++ 5
*/





#include <fstream.h>
#include <conio.c>
#include <cstdlib>
#include <ctime>

#define     GAUCHE   75
#define     DROITE   77
#define     HAUT     72
#define     BAS      80
#define     ENTER    13
#define     ESC      27

struct Coord{
    int x;
    int y;
};

/********************************************************/
/*variables utilisees dans jeu()*/
int vitesse = 50;//vitesse du snake en miles/h
int gpomme=5;//nb de pommes a bouffer avnt un bonus
int gbonus=3;//nb de bonus a passer avnt de changer de niv
int time_bonus;
/********************************************************/
int NB_PARTIES;
int INTRO;
int NB_NIVEAUX;
int VIES;
bool DEBUT;
bool invincible;
/*score inscrit ds un fichier*/
int MAX_SCORE;
char nom_fichier[40] = "C:/WINDOWS/Snake_Max_Score.txt";
fstream fichier;
/*pour le chargement des niveaux*/
int Niv[80][23];
fstream fich;
char* Niveau[10];





/*============================================================================*/
/*              FONCTIONS SECONDAIRES POUR L'INTERFACE ET AUTRES              */
/*============================================================================*/

void efface_menu()
{
    gotoxy(1,1);
    for(int i=1; i<79; i++)
        cout << " ";
}

void message(char* mess1)
{
    textcolor(LIGHTBLUE);
    gotoxy(50,1);
    cout << mess1;
    getch();
    efface_menu();
}


void gameOver()
{
    Beep(200,100);
    message("===== GAME OVER =====");
}



int affiche(Coord snak[],Coord p,Coord b,int t,int s,int ind){
    int i, j, ms = 100;
    
    //si le code d'invincibilite n'est pas rentre
    if(!invincible && !DEBUT)
    {
        //si snake bouffe sa queue
        for(i = 2; i < t; i++){
            if(snak[0].x == snak[i].x && snak[0].y == snak[i].y){
                gameOver();
                return 0;
            }
        }
    }
    DEBUT=false;
    
    //teste les collisions avec des paroies
    for(i=0; i<23; i++){
        for(int j=0; j<80; j++){
            if(Niv[j][i]==1){
                if(snak[0].x==(j+1) && snak[0].y==(i+3))
                {
                    gameOver();
                    return 0;
                }
            }
        }
    }
    //dessine le snake
    for(i = 0; i < t; i++){
        gotoxy(snak[i].x, snak[i].y);
        if(i == 0){
                textcolor(9);
                cout << "\x2";
        }
        else{
                if(i == t-1){
                    textcolor(BLACK);
                    cout << " ";
                }
                else{
                    if(i == t-2){
                        textcolor(9);
                        cout << "\xf";
                    }
                    else{
                        textcolor(26);
                        cout << " ";
                    }
                }
        }
    }
    gotoxy(snak[0].x, snak[0].y);
    textcolor(9);
    cout << "\x2";
    //dessine la pomme
    gotoxy(p.x, p.y);
    textcolor(12);
    cout << "\x9d";
    if(b.x<100 && b.y<100)
    {
        //dessine le bonus
        gotoxy(b.x, b.y);
        textcolor(14);
        cout << "\xf5";
        gotoxy(75,1);
        cout<<time_bonus << " ";
    }
    //dessine le score
    gotoxy(1, 2);
    for(i = 0; i < 80; i++)
        cout << "\xC4";
    gotoxy(2,1);
    textcolor(LIGHTRED);
    for(i=0; i<VIES; i++)
        cout << "\x3";
    textcolor(WHITE);
    cout << "    Score: " << s;
    if(s >= MAX_SCORE) MAX_SCORE = s;
    cout << "    Record: " << MAX_SCORE;
    //dessine le No niveau
    cout << "    LEVEL " << ind;
    return 1;
}


void intro(){
    int x, y;
    int i, vit = 5;
    
    textcolor(26);
    //S
    x = 20, y = 5;
    for(i = 0; i < 10; i++){  gotoxy(x - i, y); cout << " ";Sleep(vit);} x = 10;
    for(i = 0; i < 8; i++){   gotoxy(x, y + i);cout << " ";Sleep(vit);}  y = 13;
    for(i = 0; i < 10; i++){  gotoxy(x + i, y); cout << " ";Sleep(vit);} x = 20;
    for(i = 0; i < 8; i++){   gotoxy(x, y + i);cout << " ";Sleep(vit);}  y = 21;
    for(i = 0; i <= 10; i++){ gotoxy(x - i, y); cout << " ";Sleep(vit);}
    //N
    x = 23, y = 21;
    for(i = 0; i < 16; i++){  gotoxy(x, y - i); cout << " ";Sleep(vit);}    y = 5;
    for(i = 0; i < 10; i++){  gotoxy(x + i, y + i);cout << " ";Sleep(vit);} x = 33; y = 21;
    for(i = 0; i <= 16; i++){ gotoxy(x, y - i); cout << " ";Sleep(vit);}
    //A
    x = 36, y = 21;
    for(i = 0; i < 16; i++){ gotoxy(x, y - i); cout << " ";Sleep(vit);}  y = 5;
    for(i = 0; i < 10; i++){   gotoxy(x + i, y);cout << " ";Sleep(vit);} x = 46;
    for(i = 0; i <= 16; i++){ gotoxy(x, y + i); cout << " ";Sleep(vit);} x = 36; y = 12;
    for(i = 0; i < 10; i++){   gotoxy(x + i, y);cout << " ";Sleep(vit);}
    //K
    x = 49, y = 21;
    for(i = 0; i <= 16; i++){ gotoxy(x, y - i); cout << " ";Sleep(vit);}  y = 12;
    for(i = 0; i < 10; i++){   gotoxy(x + i, y + i);cout << " ";Sleep(vit);} x = 49, y = 14;
    for(i = 0; i < 10; i++){   gotoxy(x + i, y - i);cout << " ";Sleep(vit);}
    //E
    x = 71, y = 5;
    for(i = 0; i < 10; i++){ gotoxy(x - i, y); cout << " ";Sleep(vit);}  x = 61;
    for(i = 0; i < 16; i++){   gotoxy(x, y + i);cout << " ";Sleep(vit);} y = 21;
    for(i = 0; i <= 10; i++){ gotoxy(x + i, y); cout << " ";Sleep(vit);} x = 61; y = 13;
    for(i = 0; i < 8; i++){   gotoxy(x + i, y);cout << " ";Sleep(vit);}
    textcolor(LIGHTBLUE);
    gotoxy(72, 21);
    cout << " 2003 ";
    getch();
}

void dessineNiveau()
{
    //dessine le niveau
    textcolor(11);
    for(int i=0; i<23; i++){
        for(int j=0; j<80; j++){
            if(Niv[j][i]==1){
                gotoxy(j+1,i+3);
                cout << "\xdb";
            }
        }
    }
    gotoxy(1,1);
}


void aide()
{
    int x=21;
    textcolor(26);
    gotoxy(x+1,8);cout << "                                      " << endl;
    gotoxy(x,9);cout << "                   AIDE                 " << endl;
    gotoxy(x,10);cout << "                                        " << endl;
    gotoxy(x,11);cout << " Z ------- monter!                      " << endl;
    gotoxy(x,12);cout << " S ------- descendre!                   " << endl;
    gotoxy(x,13);cout << " Q ------- gauche!                      " << endl;
    gotoxy(x,14);cout << " D ------- droite!                      " << endl;
    gotoxy(x,15);cout << " ESC ----- quitter!                     " << endl;
    gotoxy(x,16);cout << " C ------- prompt!                      " << endl;
    gotoxy(x,17);cout << " AUTRE --- pause!                       " << endl;
    gotoxy(x,18);cout << "                                        " << endl;
    gotoxy(x,19);cout << " A l'invite du prompt taper \"aide\" pour " << endl;
    gotoxy(x,20);cout << " acceder a l'aide a tout moment du jeu, " << endl;
    gotoxy(x,21);cout << " ou \"man\" pour toutes les commandes.    " << endl;
    gotoxy(x+1,22);cout << "                                      " << endl;
    message("===== PRET? =====   ");
    textcolor(BLACK);
    clrscr();
    dessineNiveau();
}

//lit le fichier score
void lecture()
{
    fichier.open(nom_fichier, ios::in);
    if(!fichier.good())
        MAX_SCORE = 0;
    else
        fichier >> MAX_SCORE >> INTRO;
    fichier.close();
}

//ecrit le nouveau score
void ecriture()
{
    fichier.open(nom_fichier, ios::out);
    fichier << MAX_SCORE << " " << INTRO;
    fichier.close();
}

void prompt()
{
    char code[50];
    gotoxy(50,1);
    cout << "[prompt@snake]$ ";
    cin >> code;
    textcolor(26);
    if(strcmp(code, "snakeinvincible") == 0)
    {
        if(!invincible) invincible = true;
        else invincible = false;
    }
    if(strcmp(code, "aide") == 0)
        aide();
    if(strcmp(code, "man") == 0){
        int x=25;
        gotoxy(x+1, 11);cout << "                             ";
        gotoxy(x, 12);cout << " 'aide'  affiche l'aide du jeu ";
        gotoxy(x, 13);cout << " 'intro' (des)active l'intro   ";
        gotoxy(x, 14);cout << " 'mail'  pour des suggestions  ";
        gotoxy(x, 15);cout << " 'man'   affiche ce manuel     ";
        gotoxy(x+1, 16);cout << "                             ";
        getch();
    }
    if(strcmp(code, "mail") == 0){
        int x=20;
        gotoxy(x+1, 11);cout << "                                        ";
        gotoxy(x, 12);cout << " Pour toute suggestion envoyez un mail a  ";
        gotoxy(x, 13);cout << "            cbwinny@yahoo.fr              ";
        gotoxy(x+1, 14);cout << "                                        ";
        getch();
    }
    if(strcmp(code, "intro") == 0){
        int x=28;
        gotoxy(x+1,10);cout << "                       ";
        if(INTRO){
            INTRO=0;
            gotoxy(x, 11);cout << " L'intro a ete desactive ";
        }
        else{
            INTRO=1;
            gotoxy(x, 11);cout << " L'intro a ete active    ";
        }
        gotoxy(x+1,12);cout << "                       ";
        getch();
    }
    textcolor(BLACK);
    clrscr();
    dessineNiveau();
}



/*============================================================================*/
/*                              MOTEUR DU JEU                                 */
/*============================================================================*/

void initialiseNiveaux()
{
    Niveau[1]="Niveau1";
    Niveau[2]="Niveau2";
    Niveau[3]="Niveau3";
    Niveau[4]="Niveau4";
    NB_NIVEAUX=4;
}

int chargeNiveau(int ind)
{
    char c;
    int i=0, j=0;
    fich.open(Niveau[ind], ios::in);
    if(!fich.good())
    {
        message("===== Probleme de NIVEAU =====");
        return 0;
    }
    
    while(!fich.eof()){
        fich.get(c);
        switch(c)
        {
            case 'H':
                Niv[j][i]=1;
                break;
            case ' ':
                Niv[j][i]=0;
                break;
            default:
                break;
        }
        if(c=='\n'){
            i++;
            j=0;
        }
        else j++;
        
    }
    fich.close();
    return 1;
}

void cherche_pomme(Coord snake[], Coord &p, int taille){
    int x, y;
    int exit, ind;
    do{
        exit = 1;
        x = (rand() % 79) + 1;
        y = (rand() % 22) + 3;
        ind = 0;
        //verifie si la pomme n'est pas ds le serpent
        while(ind <= taille && exit){
                if(x == snake[ind].x && y == snake[ind].y)
                     exit = 0;
                ind++;
        }
        //verifie si la pomme n'est pas ds le mur
        for(int i=0; i<23; i++){
            for(int j=0; j<80; j++){
                if(Niv[j][i]==1){
                    if(x==(j+1) && y==(i+3))
                        exit=0;
                }
                if(!exit) break;
            }
            if(!exit) break;
        }
    }while(! exit);
    p.x = x;
    p.y = y;
}

void cherche_bonus(Coord snake[], Coord &b, int taille)
{
    cherche_pomme(snake, b, taille);
}

void initialisationJeu(int nb_niv, Coord snak[], Coord &s, Coord &p, int t)
{
    int ni;
    clrscr();
    ni=chargeNiveau(nb_niv);
    cherche_pomme(snak, p, t);
    //initialisation du snake
    s.x = 10, s.y = 23;
    snak[0].x = s.x;
    snak[0].y = s.y;
    for(int i = 1; i < t; i++){
        snak[i].x = s.x;
        snak[i].y = s.y;
    }
    if(ni) dessineNiveau();
    else exit(0);
}


//fonction qui gere le jeu
void jeu(){
    Coord snake[1000];//coord du snake
    Coord p;//coord de la pomme
    Coord b;//coord du bonus
    b.x=100; b.y=100;
    Coord s;//coord de la tete du snake
    
    int score = 0;
    int taille = 5;
    int i, exit = 0, v;
    int sens=DROITE;
    char c;//charactere appuye
    int nb_pomme=0;//nb de pommes bouffees
    int nb_bonus=0;//nb de bonus passes
    int nb_niv=1;

    initialisationJeu(nb_niv, snake, s, p, taille);
    DEBUT=true;
    affiche(snake, p, b, taille, score, nb_niv);
    DEBUT=true;
    
    
    if(NB_PARTIES == 1)
        aide();
    
    //grande boucle du jeu 
    while(!exit)
    {
        //qd on frappe une touche
        while(kbhit())
        {
        switch(getch())
        {
                case 'z':
                    if(sens != BAS) sens = HAUT;
                    break;      
                case 's':
                    if(sens != HAUT) sens = BAS;
                    break;
                case 'q':
                    if(sens != DROITE) sens = GAUCHE;
                    break;
                case 'd':
                    if(sens != GAUCHE) sens = DROITE;
                    break;
                case ESC:
                    exit = 1;
                    break;
                case 'c':
                    prompt();
                    break;
                default:
                    message("===== PAUSE =====");
                    break;
        }
        }
        //qd on frappe pas de touches
        while(!kbhit() && exit!=1)
        {
        
            time_bonus--;
            //si snake bouffe la pomme
            if(snake[0].x == p.x && snake[0].y == p.y){
                score += 9;
                taille += 3;
                nb_pomme=(nb_pomme%gpomme)+1;
                cherche_pomme(snake, p, taille);
                if(nb_pomme == gpomme){
                    cherche_bonus(snake, b, taille);
                    time_bonus=45;
                    nb_bonus=(nb_bonus%gbonus)+1;
                }
            }
            //si snake bouffe un bonus
            if((snake[0].x == b.x && snake[0].y == b.y) || time_bonus == 0){
                score += time_bonus*5;
                taille += 3;
                //enleve le bonus
                if(time_bonus==0){
                    gotoxy(b.x,b.y);
                    cout << " ";
                }
                b.x=100;
                b.y=100;
                //si on change de niveau
                if(nb_bonus==gbonus){
                    time_bonus=0;
                    nb_niv=(nb_niv%NB_NIVEAUX)+1;
                    initialisationJeu(nb_niv, snake, s, p, taille);
                    sens=DROITE;
                    DEBUT=true;
                    affiche(snake, p, b, taille, score, nb_niv);
                    DEBUT=true;
                    message("===== PRET =====");
                }
                efface_menu();
            }
            //v=0 -> recommence le jeu
            v = affiche(snake, p, b, taille, score, nb_niv);
            if(v == 0){
                if(VIES==0){
                    NB_PARTIES++;
                    VIES=5;
                    jeu();//on recommence le jeu jusqua qu on le quitte grace
                    exit = 1;//a ESC et alors on exit (astuce pour quitter le jeu)
                }
                else{
                    VIES--;
                    initialisationJeu(nb_niv, snake, s, p, taille);
                    sens=DROITE;
                    DEBUT=true;
                    affiche(snake, p, b, taille, score, nb_niv);
                    DEBUT=true;
                    message("===== PRET =====");
                }
            }
            
            for(int h = taille; h >=1; h--){
                snake[h].x = snake[h - 1].x;
                snake[h].y = snake[h - 1].y;
            }
            //deplace le snake dans telle direction
            switch(sens)
            {
            case HAUT:
                snake[0].x = s.x;
                snake[0].y = --s.y;
                if(snake[0].y == 2){
                    snake[0].y = 25;
                    s.y = 25;
                }
                break;
            case BAS:
                snake[0].x = s.x;
                snake[0].y = ++s.y;
                if(snake[0].y == 26){
                    snake[0].y = 3;
                    s.y = 3;
                }
                break;
            case GAUCHE:
                snake[0].x = --s.x;
                snake[0].y = s.y;
                if(snake[0].x == 0){
                    snake[0].x = 80;
                    s.x = 80;
                }
                break;
            case DROITE:
                snake[0].x = ++s.x;
                snake[0].y = s.y;
                if(snake[0].x == 80){
                    snake[0].x = 1;
                    s.x = 1;
                }
                break;
            }
            Sleep(vitesse);
        }
    }
}




/*============================================================================*/
/*                           FONCTION PRINCIPALE                              */
/*============================================================================*/

int main(){
    srand(time(0));
    system("title SNAKE 2003 by $kinia");
    NB_PARTIES=1;
    VIES=5;
    invincible = false;
    
    initialiseNiveaux();
    lecture();//lit le score
    if(INTRO) intro();
    jeu();
    ecriture();//ecrit le score
    
    
    return 1;
}


 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
  • Niveau1Télécharger ce fichier [Réservé aux membres club]1 884 octets
  • Niveau2Télécharger ce fichier [Réservé aux membres club]1 884 octets
  • Niveau3Télécharger ce fichier [Réservé aux membres club]1 884 octets
  • Niveau4Télécharger ce fichier [Réservé aux membres club]1 884 octets
  • snak.jpgTélécharger ce fichier [Réservé aux membres club]Voir ce fichier19 355 octets
  • snake.cppTélécharger ce fichier [Réservé aux membres club]Voir ce fichier17 443 octets

Télécharger le zip


 Sources du même auteur

Source avec Zip SHOOT 2D POLITIQUE : LA REVANCHE DE L.J
Source avec Zip Source avec une capture CASSE BRIQUE SOUS DEV CPP (POUR PASSER LE TEMPS PENDANT MON ...
Source avec Zip Source avec une capture PUISSANCE 4 GRAPHIQUE EN MODE DOS AVEC IA IMBATTABLE
PROG QUI CALCULE LE NB DE LIGNE D'UN CODE(AVEC COMMENTAIRES,...
Source avec Zip Source avec une capture SUPER MASTERMIND EN MODE GRAPHIQUE

 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 Cyberboy2054 le 02/02/2004 18:52:48

Argh, tu mas devancé ... le mien est avec la sdl, du coup je sais pas si je le mettrais :/
sinon c est plutot sympa comme programme ....

Commentaire de kuroro le 02/02/2004 20:18:53

Mets le , mets le , j'adore tout ce qui se fait avec SDL et comme j'arrive pas à très bien l'utiliser ca me fera un exemple de plus :)

Commentaire de LordBob le 03/02/2004 14:20:28

juste pour repondre a ta question, ton programme est compilé en mode Debug, pour que ton exe "perde du poid", il faut que tu le compile en mode Release... Sous Dev je sais pas comment on fait...

Commentaire de skinia le 03/02/2004 19:50:27

t'avais raison j'ai reussi a generer un exe de 100 Ko
en virant le debug mais c'est encore trop

Commentaire de LordBob le 03/02/2004 19:54:05

oui, mais la, on ne peut rien faire de plus...

Commentaire de vecchio56 le 03/02/2004 20:49:35 administrateur CS

bien sur que si: /ALIGN:4096 par exemple dans les options du linker, mais de toute facon pourquoi mettre a tout prix un exe?

Commentaire de Ro3034 le 08/03/2004 15:01:26

sous dev c++ 5.0, j'arrive à compiler un exe, mais celui-ci ne marche pas. dans le compilateur, y'a marqué "error linker win@main16". du coup, quand je lance l'exe, j'obtiens un message d'erreur. étant un peu débutant, pourriez-vous m'aider, s'il-vous-plaît ? merci d'avance (et le plus tôt serait le mieux car c surement une erreur de rien du tout et ça m'énerve!!!).

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

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,530 sec (3)

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