j'ai pas pu mettre l'exe car devc++5 genere des monstres de 500 Ko
j'sais pas pourquoi?
Source / Exemple :
/*
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;
}
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.