Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <windows.h>
- #define HAUT 22 //20+2 pour les bordures
- #define LARG 52 //50+2 pour les bordures
- typedef struct // définition de la structure des fantomes
- {
- int fantlig;
- int fantcol;
- int fantdeplig;
- int fantdepcol;
- } t_fant;
- typedef struct // définition de la structure position du pacman
- {
- int poslig;
- int poscol;
- } t_pos;
- void hidecursor() //fonction cachant le curseur (TROUVE SUR INTERNET)
- {
- HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
- CONSOLE_CURSOR_INFO info;
- info.dwSize = 100;
- info.bVisible = FALSE;
- SetConsoleCursorInfo(consoleHandle, &info);
- }
- void color(int t,int f) //Pour mettre des couleurs dans la console (trouvée sur internet)
- {
- HANDLE H=GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(H,f*16+t);
- }
- void gotoligcol( int lig, int col )
- {
- // ressources
- COORD mycoord;
- mycoord.X = col;
- mycoord.Y = lig;
- SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), mycoord );
- }
- void affiche (char mat[HAUT][LARG]) //Programme pour afficher une matrice
- {
- //Déclaration des variables
- int i, j ; //Compteurs dans boucles for
- //Code
- for (i=0 ; i<HAUT ; i++) //On parcourt les lignes
- {
- for (j=0 ; j<LARG ; j++) //On parcourt les colonnes
- {
- if (mat[i][j] == 'D')
- {
- color(9,0) ;
- printf("D") ;
- color(15,0) ;
- }
- else
- printf("%c", mat[i][j]) ; //On affiche tous les éléments de la matrice
- }
- printf("\n"); //Après chaque ligne faite, on retourne à la ligne
- }
- }
- void depfantome (t_fant *fantome,t_pos *position,char mat[HAUT][LARG]) //Déplacement des fantômes guidés
- {
- int deplacement_fantome;
- //Déplacement du fantome
- gotoligcol(fantome->fantlig,fantome->fantcol);//on place le curseur sur la position du fantome
- if (mat[fantome->fantlig][fantome->fantcol]=='D')
- {
- mat[fantome->fantlig][fantome->fantcol]='D' ;
- color(9,0) ;
- printf("D") ;
- color(15,0) ;
- }
- else
- {
- mat[fantome->fantlig][fantome->fantcol]=' ' ;
- printf(" ");
- }
- fantome->fantcol+=fantome->fantdepcol, fantome->fantlig+=fantome->fantdeplig ; //En fonction du déplacement, on modifie la position du fantome
- if (fantome->fantcol >= LARG-1) //Si le fantome dépasse la dernière colonne, il revient à la première
- {
- fantome->fantcol=1 ;
- }
- if (fantome->fantlig >= HAUT-1) //Si le fantome dépasse la dernière ligne, il revient à la première
- {
- fantome->fantlig=1 ;
- }
- if (fantome->fantcol < 1) //Si le fantome passe derrière la première colonne, il revient à la dernière
- {
- fantome->fantcol=LARG-2 ;
- }
- if (fantome->fantlig < 1) //Si le fantome passe derrière la première ligne, il revient à la dernière
- {
- fantome->fantlig=HAUT-2 ;
- }
- if (mat[fantome->fantlig][fantome->fantcol]=='D')
- {
- mat[fantome->fantlig][fantome->fantcol]='D' ;
- }
- else
- {
- mat[fantome->fantlig][fantome->fantcol]='F' ;
- }
- gotoligcol(fantome->fantlig,fantome->fantcol);//on place le curseur sur la nouvelle position du fantome
- color(12,0) ;
- printf("%c",mat[fantome->fantlig][fantome->fantcol]); //on affiche le fantome sur sa nouvelle position
- color(15,0) ;
- //déplacement fantome pour pousuivre le pacman
- if (fantome->fantcol>position->poscol)
- deplacement_fantome=3;
- if (fantome->fantcol<position->poscol)
- deplacement_fantome=4;
- if (fantome->fantlig>position->poslig)
- deplacement_fantome=1;
- if (fantome->fantlig<position->poslig)
- deplacement_fantome=2;
- switch (deplacement_fantome)
- {
- //Il monte
- case 1 :
- fantome->fantdeplig = -1 ;
- fantome->fantdepcol = 0 ;
- break ;
- //Il descend
- case 2 :
- fantome->fantdeplig = 1 ;
- fantome->fantdepcol = 0 ;
- break ;
- //Il va à gauche
- case 3 :
- fantome->fantdeplig = 0 ;
- fantome->fantdepcol = -1 ;
- break ;
- //Il va à droite
- case 4 :
- fantome->fantdeplig = 0 ;
- fantome->fantdepcol = 1 ;
- break ;
- }
- // pour gérer les murs au milieu de la map
- if ((mat[fantome->fantlig+fantome->fantdeplig][fantome->fantcol+fantome->fantdepcol]==(char)186) || (mat[fantome->fantlig+fantome->fantdeplig][fantome->fantcol+fantome->fantdepcol]==(char)205))
- {
- switch (deplacement_fantome)
- {
- //Il monte
- case 1 :
- fantome->fantdeplig = 1 ;
- fantome->fantdepcol = 0 ;
- break ;
- //Il descend
- case 2 :
- fantome->fantdeplig = -1 ;
- fantome->fantdepcol = 0 ;
- break ;
- //Il va à gauche
- case 3 :
- fantome->fantdeplig = 0 ;
- fantome->fantdepcol = 1 ;
- break ;
- //Il va à droite
- case 4 :
- fantome->fantdeplig = 0 ;
- fantome->fantdepcol = -1 ;
- break ;
- }
- }
- }
- void depfantomealea (t_fant *fantome,t_pos *position,char mat[HAUT][LARG], int* dep_lineaire, int bordure) //Déplacement des fantômes aléatoires
- {
- //Déclaration des variables
- int deplacement_fantome_alea ;
- int rand1 ;
- //Déplacement du fantome
- gotoligcol(fantome->fantlig,fantome->fantcol);//on place le curseur sur la position du fantome
- if (mat[fantome->fantlig][fantome->fantcol]=='D')
- {
- mat[fantome->fantlig][fantome->fantcol]='D' ;
- color(9,0) ;
- printf("D") ;
- color(15,0) ;
- }
- else
- {
- mat[fantome->fantlig][fantome->fantcol]=' ' ;
- printf(" ");
- }
- fantome->fantcol+=fantome->fantdepcol, fantome->fantlig+=fantome->fantdeplig ; //En fonction du déplacement, on modifie la position du fantome
- //Quand le PACMAN rencontre un mur sans bordure
- if (fantome->fantcol >= LARG-1) //Si le fantome dépasse la dernière colonne, il revient à la première
- {
- fantome->fantcol=1 ;
- }
- if (fantome->fantlig >= HAUT-1) //Si le fantome dépasse la dernière ligne, il revient à la première
- {
- fantome->fantlig=1 ;
- }
- if (fantome->fantcol < 1) //Si le fantome passe derrière la première colonne, il revient à la dernière
- {
- fantome->fantcol=LARG-3 ;
- }
- if (fantome->fantlig < 1) //Si le fantome passe derrière la première ligne, il revient à la dernière
- {
- fantome->fantlig=HAUT-2 ;
- }
- // Cas ou les bordures sont activé
- if (bordure == 1)
- {
- if ((fantome->fantcol+fantome->fantdepcol) >= LARG-1) //Si le PACMAN arrive a la dernière colonne, il rebondit
- {
- fantome->fantdepcol = -1 ;
- }
- if (fantome->fantlig+fantome->fantdeplig >= HAUT-1) //Si le PACMAN dépasse la dernière ligne, il rebondit
- {
- fantome->fantdeplig = -1 ;
- }
- if (fantome->fantcol+fantome->fantdepcol < 1) //Si le PACMAN passe derrière la première colonne, il rebondit
- {
- fantome->fantdepcol = 1;
- }
- if (fantome->fantlig+fantome->fantdeplig < 1) //Si le PACMAN passe derrière la première ligne, il rebondit
- {
- fantome->fantdeplig = 1;
- }
- }
- if (mat[fantome->fantlig][fantome->fantcol]=='D')
- {
- mat[fantome->fantlig][fantome->fantcol]='D' ;
- }
- else
- {
- mat[fantome->fantlig][fantome->fantcol]='F' ;
- }
- gotoligcol(fantome->fantlig,fantome->fantcol);//on place le curseur sur la nouvelle position du fantome
- color(12,0) ;
- printf("%c",mat[fantome->fantlig][fantome->fantcol]); //on affiche le fantome sur sa nouvelle position
- color(15,0) ;
- //déplacement fantome aléatoire
- switch (*dep_lineaire)
- {
- //Il monte
- case 1 :
- fantome->fantdeplig = -1 ;
- fantome->fantdepcol = 0 ;
- break ;
- //Il descend
- case 2 :
- fantome->fantdeplig = 1 ;
- fantome->fantdepcol = 0 ;
- break ;
- //Il va à gauche
- case 3 :
- fantome->fantdeplig = 0 ;
- fantome->fantdepcol = -1 ;
- break ;
- //Il va à droite
- case 4 :
- fantome->fantdeplig = 0 ;
- fantome->fantdepcol = 1 ;
- break ;
- }
- // pour gérer les murs au milieu de la map
- if ((mat[fantome->fantlig+fantome->fantdeplig][fantome->fantcol+fantome->fantdepcol]==(char)186) || (mat[fantome->fantlig+fantome->fantdeplig][fantome->fantcol+fantome->fantdepcol]==(char)205))
- {
- switch (*dep_lineaire)
- {
- //Il monte
- case 1 :
- fantome->fantdeplig = 1 ;
- fantome->fantdepcol = 0 ;
- break ;
- //Il descend
- case 2 :
- fantome->fantdeplig = -1 ;
- fantome->fantdepcol = 0 ;
- break ;
- //Il va à gauche
- case 3 :
- fantome->fantdeplig = 0 ;
- fantome->fantdepcol = 1 ;
- break ;
- //Il va à droite
- case 4 :
- fantome->fantdeplig = 0 ;
- fantome->fantdepcol = -1 ;
- break ;
- }
- }
- }
- void sauvegarde (int derniere_val_aj,int num_tableau) //procédure de sauvegarde du jeux
- {
- //Declaration des variables
- int val;
- char mot[21];
- FILE* fic=NULL;
- //Création (ou ouverture) du fichier de sauvegarde
- fic=fopen("sauvegarde.txt","a");
- if (fic) //test si le fichier abien été ouvert
- {
- printf("Saisissez le nom de votre sauvegarde \(20 caratere maximum et sans espace\) et appuyez sur entree:\n");
- fflush(stdin);
- gets(mot);//entrer le nom de la sauvegarde
- fprintf(fic,"Partie %d:%s %d\n",derniere_val_aj+1,mot,num_tableau);//écriture de la ligne de sauvegarde dans le fichier
- fclose(fic);
- }
- else //cas ou il y a eu une erreur dans la création du fichier
- {
- system("cls");
- printf("La sauvegarde n'a pas put etre effectue");
- }
- }
- void recup_sauvegarde () //Fonction de récupération de la sauvegarde du jeu
- {
- //déclaration des varaibles
- int val;
- char mot[21];
- int num_tableau;
- int valeur;
- int ligne;
- int i;
- int multiple;
- FILE* fic=NULL;
- //ouverture du fichier de sauvegarde
- fic=fopen("sauvegarde.txt","r");
- ligne=1;
- if (fic) //testsi le fichier a bien été ouvert
- {
- while (!feof(fic))
- printf("%c",fgetc(fic)); // Affichage des sauvegardes
- printf("\n\n\n Veuillez entrer le numero de la partie que vous souhaitez recuperer:\n");
- scanf("%d",&valeur); //Récupération du numéro de la partie que le joueur veut récupérer
- printf("\n");
- printf("\n");
- //on place le curseur au début du document texte
- rewind(fic);
- //on fait avancer le curseur tant qu'on est pas a la bonne ligne
- while(ligne != valeur)
- {
- val=fgetc(fic);
- if (val == '\n')
- ligne=ligne +1;
- }
- //on fait avancer le curseur jusqu'au début du nom de la sauvegarde
- while((val=fgetc(fic))!= ':');
- //on enregistre le nom de la sauvegarde dans la chaine de caratère mot
- strcpy(mot,"\0");
- while((val=fgetc(fic))!= ' ')
- strcat(mot,(char[])
- {
- val, '\0'
- });
- //on enregistre le numéro du tableau en cour dans l'entier num_tableau
- while((val=fgetc(fic))!= ' ')
- num_tableau=val-48;
- system("cls");
- //sauvegarde nous renvoi
- printf("%s\n",mot);
- printf("%d\n",num_tableau);
- }
- }
- void menu (int *tempo, int* bordure , int* tableau_lvl ) //Sous programme du menu
- {
- int choix;
- int choix2;
- int choix3;
- int debut;
- int i;
- debut=0;
- choix2='m';
- hidecursor();
- while (choix2=='m')
- {
- printf("\n ===== BIENVENUE SUR PACMAN ===== \n\n");
- printf(" MENU DU JEU :\n ");
- printf("1: Regles du jeux\n ");
- printf("2: Vitesse de depart\n ");
- printf("3: Bordure\n ");
- printf("4: Demarer une nouvelle partie\n ");
- printf("5: Reprendre la partie\n ");
- printf("6: Quitter la partie\n\n");
- printf("Saisissez votre choix et appuyer sur entree\n");
- fflush(stdin);
- scanf("%d",&choix);
- system("cls");
- switch (choix)
- {
- case 1:
- printf("\n\n ===REGLE DU JEUX===\n\n");
- printf("Le but du jeux est de manger des diamants repartis sur \n4 niveaux de difficultes croissante. Cependant,le pacman \nsera confronte a des obstacles que vous devrez eviter\n\n");
- printf(" ");
- printf("Voici les touches utiles:\n");
- printf(" ");
- printf("4: Se deplacer vers la gauche\n");
- printf(" ");
- printf("8: Se deplacer vers le haut\n");
- printf(" ");
- printf("6: Se deplacer vers la droite\n");
- printf(" ");
- printf("2: Se deplacer vers le bas\n");
- printf(" ");
- printf("p: Mettre le jeu en pause\n");
- printf(" ");
- printf("q: Retourner au menu\n");
- printf("\n\nPour retourner au menu, appuyer sur \"m\" et entree:\n");
- fflush(stdin);
- scanf("%c",&choix2);
- system("cls");
- break;
- case 2:
- printf("\n\n ===REGLER LA VITESSE DE JEU===\n\n ");
- printf("1: Pacman lent\n ");
- printf("2: Pacman a vitesse moyenne\n ");
- printf("3: Pacman rapide\n\n ");
- printf("Choisir la vitesse de votre Pacman et appuye sur entree:\n");
- scanf("%d",&choix3);
- system("cls");
- switch(choix3)
- {
- case 1:
- printf("\n\n ****Vous avez choisi un Pacman lent****\n\n");
- (*tempo) = (*tempo)*2;
- break;
- case 2:
- printf("\n\n ****Vous avez choisi un Pacman a vitesse moyenne****\n\n");
- break;
- case 3:
- printf("\n\n ****Vous avez choisi un Pacman rapide****\n\n");
- (*tempo) = (*tempo)/2;
- break;
- default:
- printf(" ===Votre saisi est errone===");
- }
- printf("\n\nPour retourner au menu, appuyer sur \"m\" et entree:\n");
- fflush(stdin);
- scanf("%c",&choix2);
- system("cls");
- break;
- case 3:
- printf("\n\n ===REGLER LA BORDURE DU JEU===\n\n ");
- printf("1: ON\n ");
- printf("2: OFF\n\n ");
- printf("Choisir si vous souhaitez des bordures ou non et appuyez sur entree:\n");
- scanf("%d",&choix3);
- system("cls");
- switch(choix3)
- {
- case 1:
- printf("\n\n ****Vous avez choisi d'avoir des bordures****\n\n");
- (*bordure) = 1;
- break;
- case 2:
- printf("\n\n ****Vous avez choisi de ne pas avoir de bordures****\n\n");
- (*bordure) = 0;
- break;
- default:
- printf(" ===Votre saisi est errone===");
- }
- printf("\n\nPour retourner au menu, appuyer sur \"m\" et entree:\n");
- fflush(stdin);
- scanf("%c",&choix2);
- system("cls");
- break;
- case 4:
- printf("\n\n ****Vous avez choisi de commencer une nouvelle partie****\n\n");
- (*tableau_lvl) = 1 ;
- debut=1;
- choix2='n';
- for (i=0; i<1000000000; i++)
- {
- }
- system("cls");
- break;
- case 5:
- printf("\n\n ****Vous avez choisi de reprendre votre partie sauvegarde****\n\n");
- system("cls");
- recup_sauvegarde();
- debut=1;
- choix2='n';
- break;
- case 6:
- printf("\n\n ****Vous avez choisi de quitter le jeu****\n\n");
- sauvegarde(1,1);
- system("cls");
- gotoligcol(5, 10) ;
- printf("%c%c%c%c%c%c%c%c%c%c%c%c%c", 201, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 187) ;
- gotoligcol(6, 10) ;
- printf("%c", 186) ;
- printf(" AU REVOIR ") ;
- printf("%c", 186) ;
- gotoligcol(7, 10) ;
- printf("%c%c%c%c%c%c%c%c%c%c%c%c%c", 200, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 188) ;
- choix2='n';
- debut=1;
- printf("\n\n\n\n\n");
- break;
- default:
- printf("\n===Saisi erone===\n");
- }
- }
- if (debut==0)
- printf("\n===Saisi errone, relancez le jeu===\n\n");
- }
- void tableau ( int nb_objets,int *vie, int NB_FANT, int *score, int nb_fant_alea, int nb_fant_guid, int *dep_lineaire, int tempo, int bordure, int *tableau_lvl ) //Sous-programme qui affcihe chaque tableau
- {
- hidecursor();
- //Déclaration des variables
- char mat[HAUT][LARG] ;
- int deplig, depcol ; //deplig & depcol correspondent aux déplacements lignes/colonnes du PACMAN
- int i, j ; //Compteurs dans boucles for
- int rand1, rand2 ; //Deux nombres aléatoires
- char touche ; //Variable contenant une touche tapée par l'utilisateur
- int coord_objet[2][nb_objets] ; //Tableau contenant les coordonnées des objets
- int bordure_v, bordure_h, coin_sg, coin_sd, coin_ig, coin_id ; //Bordure verticale/horizontale Coin inférieur/supérieur droit/gauche
- int boucle ; //Variable de la boucle du jeu
- boucle = 1 ; //Vraie au début du jeu
- int d; //Diviseur de tempo
- d=1;
- int temps_acceleration; //Durée de l'accélèration quand on a mangé un objet
- temps_acceleration=0;
- int score_tab ; //Score du tableau
- score_tab = 0 ;
- t_fant fantomas[NB_FANT];
- t_pos position;
- int t;
- int compteur;
- compteur=0;
- //initialisation des bordures
- if (bordure == 1)
- {
- bordure_h = 205, bordure_v = 186, coin_sg = 201, coin_sd = 187, coin_ig = 200, coin_id = 188 ; //J'assigne à chaque bordure sa valeur decimale ASCII
- }
- else
- {
- bordure_h = 46, bordure_v = 46, coin_sg = 46, coin_sd = 46, coin_ig = 46, coin_id = 46 ; //J'assigne à chaque bordure sa valeur decimale ASCII
- }
- //Initialisation du jeu
- rand1 = rand()%(HAUT-1 - 1) + 1 ; //Ici la borne inf efantomas[i].fantligst 1 et la borne sup est HAUT-1 (car on est sur les indices)
- rand2 = rand()%(LARG-1 - 1) + 1 ; //Ici la borne inf est 1 et la borne sup est LARG-1 (car on est sur les indices)
- position.poslig=rand1, position.poscol=rand2 ; //Par défaut, le PACMAN commence dans le coin supérieur gauche
- deplig=0, depcol=0 ; //Par défaut, le PACMAN est immobile
- //Spawn fantômes
- for (i=0; i<NB_FANT; i++)
- {
- rand1 = rand()%(HAUT-1 - 2) + 2 ; //Ici la borne inf est 2 et la borne sup est HAUT-1 (car on est sur les indices)
- rand2 = rand()%(LARG-1 - 2) + 2 ; //Ici la borne inf est 2 et la borne sup est LARG-1 (car on est sur les indices)
- fantomas[i].fantdeplig=0, fantomas[i].fantdepcol=0; //Par défaut, le fantome est immmobile
- while(mat[rand1][rand2] == 'X' || mat[rand1][rand2] == (char)205 || mat[rand1][rand2] == (char)186 ) //Vérification afin d'éviter d'avoir des fantomes sur le PACMAN & les murs
- {
- rand1 = rand()%(HAUT-1 - 1) + 1 ;
- rand2 = rand()%(LARG-1 - 1) + 1 ;
- coord_objet[0][i] = rand1 ;
- coord_objet[1][i] = rand2 ;
- }
- fantomas[i].fantlig=rand1, fantomas[i].fantcol=rand2;//Par défaut, le fantome commence à une position aléatoire
- }
- //Remplissage de la bordure
- for (j=1 ; j<LARG-1 ; j++)
- mat[0][j] = (char)bordure_h ; //Bordure verticale supérieure
- for (j=1 ; j<LARG-1 ; j++)
- mat[HAUT-1][j] = (char)bordure_h ; //Bordure verticale inférieure
- for (i=1 ; i<HAUT-1 ; i++)
- mat[i][0] = (char)bordure_v ; //Bordure horizontale gauche
- for (i=1 ; i<HAUT-1 ; i++)
- mat[i][LARG-1] = (char)bordure_v ; //Bordure horizontale droite
- mat[0][0] = (char)coin_sg ; //Coin supérieur gauche
- mat[0][LARG-1] = (char)coin_sd ; //Coin supérieur droit
- mat[HAUT-1][0] = (char)coin_ig ; //Coin inférieur gauche
- mat[HAUT-1][LARG-1] = (char)coin_id ; //Coin inférieur droit
- //Remplissage de l'air de jeu
- for (i=1 ; i<HAUT-1 ; i++)
- {
- for (j=1 ; j<LARG-1 ; j++)
- {
- if ((*tableau_lvl) == 3) //Dans le tableau 3
- {
- if (j == 10 && i>=6 && i<=14)
- mat[i][j]=186 ; //On place les murs
- else if (j == 41 && i>=6 && i<=14)
- mat[i][j]=186 ; //On place les murs
- else if (i == 10 && j>=16 && j<=35)
- mat[i][j]=205 ; //On place les murs
- else
- mat[i][j]=' ' ; //On remplit le reste de la matrice de cases vides
- }
- else
- mat[i][j]=' ' ; //On remplit la matrice de cases vides
- }
- }
- //Création des objets à manger
- for (i=0 ; i<nb_objets ; i++)
- {
- //On ne veut pas faire apparaitre d'objets sur la position de X
- rand1 = rand()%(HAUT-1 - 2) + 2 ; //Ici la borne inf est 2 et la borne sup est HAUT-1 (car on est sur les indices)
- rand2 = rand()%(LARG-1 - 2) + 2 ; //Ici la borne inf est 2 et la borne sup est LARG-1 (car on est sur les indices)
- coord_objet[0][i] = rand1 ; //On stocke dans le tableau les coordonnées de chaque objet
- coord_objet[1][i] = rand2 ; //On stocke dans le tableau les coordonnées de chaque objet
- while(mat[rand1][rand2] == 'D' || mat[rand1][rand2] == 'X' || mat[rand1][rand2] == 'F' || mat[rand1][rand2] == (char)205 || mat[rand1][rand2] == (char)186 ) //Vérification afin d'éviter d'avoir 2 pommes au même endroit ou sur le PACMAN ou sur les fantomes
- {
- rand1 = rand()%(HAUT-1 - 2) + 2 ;
- rand2 = rand()%(LARG-1 - 2) + 2 ;
- coord_objet[0][i] = rand1 ;
- coord_objet[1][i] = rand2 ;
- }
- color(9,0) ;
- mat[rand1][rand2] = 'D' ; //On place aléatoirement nb_objets objets dans l'aire de jeu
- color(15,0) ;
- }
- //Aux coordonnées du PACMAN, on remplace par un X
- mat[position.poslig][position.poscol]='X' ;
- //Affichage de l'écran de jeu
- affiche(mat) ;
- //Boucle du jeu
- while(boucle) //On fait tourner une boucle permanente
- {
- for (i=0 ; i<(tempo/d) ; i++)
- {
- //On fait tourner une longue boucle pour que l'utilisateur puisse voir le jeu à une vitesse normale
- }
- //Déplacement du PACMAN
- gotoligcol(position.poslig,position.poscol);//on place le curseur sur la position du pacman
- mat[position.poslig][position.poscol]=' ' ; //On efface le PACMAN de sa position
- printf(" "); //on efface le pacman
- position.poscol+=depcol, position.poslig+=deplig ; //En fonction du déplacement, on modifie la position du PACMAN
- if (position.poscol >= LARG-1) //Si le PACMAN dépasse la dernière colonne, il revient à la première
- {
- position.poscol=1 ;
- }
- if (position.poslig >= HAUT-1) //Si le PACMAN dépasse la dernière ligne, il revient à la première
- {
- position.poslig=1 ;
- }
- if (position.poscol < 1) //Si le PACMAN passe derrière la première colonne, il revient à la dernière
- {
- position.poscol=LARG-2 ;
- }
- if (position.poslig < 1) //Si le PACMAN passe derrière la première ligne, il revient à la dernière
- {
- position.poslig=HAUT-2 ;
- }
- //Quand on mange un objet
- if (mat[position.poslig][position.poscol] == 'D')
- {
- (*score)+=10 ; //Si les coordonnées du PACMAN correspondent à celles d'un des objets, le score augmente
- score_tab+=10 ; //Idem pour le score du tableau
- if ((*tableau_lvl) >= 3)
- temps_acceleration=60;
- }
- //Comportement entre PACMAN et fantomes
- for (i=0 ; i<NB_FANT ; i++)
- {
- if (fantomas[i].fantcol == position.poscol && fantomas[i].fantlig == position.poslig)
- *vie-=1 ;
- }
- mat[position.poslig][position.poscol]='X' ;
- gotoligcol(position.poslig,position.poscol);//on place le curseur sur la nouvelle position du pacman
- color(14,0) ;
- printf("X"); //on affiche le pacman sur sa nouvelle position
- color(15,0) ;
- //Pour les fantomes aleatoires
- if (temps_acceleration>0)
- {
- if ((*tableau_lvl) >=3)
- {
- t=3+compteur;
- if ((t%6)==0)
- {
- for (i=0; i<nb_fant_alea; i++)
- {
- depfantomealea (&fantomas[i],&position,mat, &dep_lineaire[i],bordure );
- }
- }
- if ((*tableau_lvl) == 2)
- compteur+=1;
- }
- }
- else if ((*tableau_lvl) >= 3)
- {
- t=3+compteur ;
- if ((t%3)==0)
- {
- for (i=0 ; i<nb_fant_alea; i++)
- {
- depfantomealea (&fantomas[i],&position,mat, &dep_lineaire[i],bordure );
- }
- }
- compteur +=1 ;
- }
- else
- {
- for (i=0; i<nb_fant_alea; i++)
- {
- depfantomealea (&fantomas[i],&position,mat, &dep_lineaire[i],bordure);
- }
- }
- //Pour les fantomes guidés
- if (temps_acceleration>0)
- {
- if ((*tableau_lvl) >=3)
- {
- t=3+compteur;
- if ((t%3)==0)
- {
- for (i=nb_fant_alea; i<(nb_fant_guid+nb_fant_alea); i++)
- {
- depfantome (&fantomas[i],&position,mat);
- }
- }
- compteur+=1;
- }
- }
- else
- {
- for (i=nb_fant_alea; i<(nb_fant_guid+nb_fant_alea); i++)
- {
- depfantome (&fantomas[i],&position,mat);
- }
- }
- for (i=0; i<NB_FANT; i++)
- {
- if (fantomas[i].fantlig == position.poslig && fantomas[i].fantcol == position.poscol)
- (*vie) = (*vie) - 1 ;
- }
- //Affichage du score
- gotoligcol(HAUT+2,0) ;
- printf("Score : %d", (*score)) ;
- //Affichage des vies
- gotoligcol(HAUT, 0) ;
- printf("Vie(s) : %d", (*vie)) ;
- //Action utilisateur
- if (kbhit())
- touche = getch() ; //Si l'utilisateur tape sur son clavier, alors le caractère tapé se met dans la variable touche
- //Analyse action utilisateur
- switch (touche) //En fonction de la touche tapée, on modifie le déplacement du PACMAN
- {
- //Il monte
- case '8' :
- deplig = -1 ;
- depcol = 0 ;
- d=1;
- gotoligcol(HAUT+1, 0) ;
- printf(" ") ;
- break ;
- //Il descend
- case '2' :
- deplig = 1 ;
- depcol = 0 ;
- d=1;
- gotoligcol(HAUT+1, 0) ;
- printf(" ") ;
- break ;
- //Il va à gauche
- case '4' :
- deplig = 0 ;
- depcol = -1 ;
- d=2;
- gotoligcol(HAUT+1, 0) ;
- printf(" ") ;
- break ;
- //Il va à droite
- case '6' :
- deplig = 0 ;
- depcol = 1 ;
- d=2;
- gotoligcol(HAUT+1, 0) ;
- printf(" ") ;
- break ;
- //Pause
- case 'p' :
- for (i=0 ; i<NB_FANT ; i++)
- fantomas[i].fantdeplig=0, fantomas[i].fantdepcol=0 ;
- deplig = 0 ;
- depcol = 0 ;
- gotoligcol(HAUT+1, 0) ;
- printf("APPUYEZ SUR 2,4,6,8 POUR REPARTIR DANS UNE DIRECTION") ;
- break ;
- //
- case 'q' :
- //Faire la sauvegarde
- (*tableau_lvl) = (*tableau_lvl) - 1 ;
- (*vie) = 5 ;
- return ;
- break ;
- }
- // pour gérer les murs au milieu de la map
- if ((mat[position.poslig+ deplig][position.poscol+ depcol]==(char)186) || (mat[position.poslig+ deplig][position.poscol+ depcol]==(char)205))
- {
- switch (touche)
- {
- //Il monte
- case '8' :
- deplig = 1 ;
- depcol = 0 ;
- d=1;
- break ;
- //Il descend
- case '2' :
- deplig = -1 ;
- depcol = 0 ;
- d=1;
- break ;
- //Il va à gauche
- case '4' :
- deplig = 0 ;
- depcol = 1 ;
- d=2;
- break ;
- //Il va à droite
- case '6' :
- deplig = 0 ;
- depcol = -1 ;
- d=2;
- break ;
- }
- }
- // Cas ou les bordures sont activé
- if (bordure == 1)
- {
- if ((position.poscol+depcol) >= LARG-1) //Si le PACMAN arrive a la dernière colonne, il rebondit
- {
- depcol = -1 ;
- (*vie) = (*vie) -1;
- touche = '4';
- }
- if (position.poslig+deplig >= HAUT-1) //Si le PACMAN dépasse la dernière ligne, il rebondit
- {
- deplig= -1 ;
- (*vie) = (*vie) -1;
- touche = '8';
- }
- if (position.poscol+depcol < 1) //Si le PACMAN passe derrière la première colonne, il rebondit
- {
- depcol = 1;
- (*vie) = (*vie) -1;
- touche = '6';
- }
- if (position.poslig+deplig < 1) //Si le PACMAN passe derrière la première ligne, il rebondit
- {
- deplig = 1;
- (*vie) = (*vie) -1;
- touche = '2';
- }
- }
- if(temps_acceleration>0)
- {
- temps_acceleration = temps_acceleration-1;
- d=d*3;
- }
- if ((*vie)<=0) //Affichage GAME OVER
- {
- system("cls") ;
- gotoligcol(5, 10) ;
- printf("%c%c%c%c%c%c%c%c%c%c%c", 201, 205, 205, 205, 205, 205, 205, 205, 205, 205, 187) ;
- gotoligcol(6, 10) ;
- printf("%c", 186) ;
- printf("GAME OVER") ;
- printf("%c", 186) ;
- gotoligcol(7, 10) ;
- printf("%c%c%c%c%c%c%c%c%c%c%c", 200, 205, 205, 205, 205, 205, 205, 205, 205, 205, 188) ;
- gotoligcol(8, 10) ;
- printf("Score : %d", *score) ;
- gotoligcol(12, 10) ;
- break ;
- }
- //Passage d'un tableau à un autre
- if (score_tab%50 == 0 && score_tab!=0)
- {
- boucle = 0 ;
- system("cls") ;
- score_tab = 0 ;
- }
- }
- }
- int main()
- {
- //Initialisation du générateur aléatoire
- srand(time(NULL)) ;
- //Déclaration des varibales
- int score ;
- int dep_lineaire [4] ;
- int i, j;
- int vie;
- int tempo;
- int bordure;
- int tableau_lvl;
- //Code
- tempo = 80000000;
- hidecursor();
- score = 0;
- vie = 5;
- bordure = 0;
- tableau_lvl = 1 ;
- //Écran d'acceuil
- color(14, 0) ;
- printf("\n\n 8b,dPPYba, ,adPPYYba, ,adPPYba, 88,dPYba,,adPYba, ,adPPYYba, 8b,dPPYba,\n") ;
- printf(" 88P' \"8a \"\" `Y8 a8\" \"\" 88P' \"88\" \"8a \"\" `Y8 88P' `\"8a\n") ;
- printf(" 88 d8 ,adPPPPP88 8b 88 88 88 ,adPPPPP88 88 88 \n") ;
- printf(" 88b, ,a8\" 88, ,88 \"8a, ,aa 88 88 88 88, ,88 88 88\n") ;
- printf(" 88`YbbdP\"' `\"8bbdP\"Y8 `\"Ybbd8\"' 88 88 88 `\"8bbdP\"Y8 88 88\n") ;
- printf(" 88\n") ;
- printf(" 88\n") ;
- color(15, 0) ;
- printf("\n Made by : FABRE Maximilien\n") ;
- printf(" DESCOTTES Martin\n\n") ;
- printf(" Year : 2018\n") ;
- printf(" Referent : RAVAUT Frederic") ;
- for (i=0; i<2000000000; i++)
- {
- }
- system("cls");
- while(1)
- {
- menu(&tempo,&bordure ,&tableau_lvl);
- system("cls");
- gotoligcol(HAUT/2,LARG/2);
- if (tableau_lvl == 1)
- {
- printf ("TABLEAU 1");
- for (i=0; i<1000000000; i++)
- {
- }
- system("cls");
- score=0 ;
- tableau(5,&vie,0,&score, 0, 0,0, tempo, bordure, &tableau_lvl) ;
- tableau_lvl+=1 ;
- }
- for (i=0; i<4; i++)
- {
- dep_lineaire[i] = rand()%(5-1) + 1 ;
- }
- system("cls");
- gotoligcol(HAUT/2,LARG/2);
- if (tableau_lvl == 2)
- {
- printf ("TABLEAU 2");
- for (i=0; i<1000000000; i++)
- {
- }
- system("cls");
- score = 50 ;
- tableau(5,&vie, 4,&score, 4, 0, &dep_lineaire, tempo, bordure, &tableau_lvl) ;
- tableau_lvl+=1 ;
- }
- if (vie>0)
- {
- for (i=0; i<4; i++)
- {
- dep_lineaire[i] = rand()%(5-1) + 1 ;
- }
- system("cls");
- gotoligcol(HAUT/2,LARG/2);
- if (tableau_lvl == 3)
- {
- printf ("TABLEAU 3");
- for (i=0; i<1000000000; i++)
- {
- }
- system("cls");
- score = 100 ;
- tableau(5,&vie, 4,&score, 2, 2, &dep_lineaire, tempo, bordure, &tableau_lvl) ;
- tableau_lvl+=1 ;
- }
- }
- system("cls");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement