1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| #include <stdio.h>
#include <stdlib.h>
int DeterminerDirection(char ToucheAppuyee) //On associe la touche appuyée au nombre qu'il faut ajouter à la position
{
switch(ToucheAppuyee)
{
case 'z':
return -10;
break;
case 'q':
return -1;
break;
case 's':
return 10;
break;
case 'd':
return 1;
break;
}
return 0;
}
int TypeMouvement(char PositionNext,char PositionNextNext) //Qu'y a-t-il devant et peut-on avancer ?
{
if (PositionNext == ' ' ) //S'il y a rien devant
{
return 1; //Cas numéro 1
}
if (PositionNext == '#' ) //S'il y a un bloc devant
{
if (PositionNextNext == ' ' ) //Et qu'après c'est libre
{
return 2;
}
if ( PositionNextNext == 'O' )
{
return 3;
}
}
return 0;
}
int main(int argc, char *argv[])
{
//Déclaration et initialisataion des variables
char Matrice[100] = {'X','X','X','X','X','X','X','X','X','X','X',' ',' ',' ',' ',' ',' ',' ',' ','X','X',' ','J',' ',' ',' ',' ',' ',' ','X','X',' ',' ',' ',' ',' ',' ',' ',' ','X','X',' ',' ',' ',' ','#',' ',' ',' ','X','X',' ',' ',' ',' ',' ',' ',' ',' ','X','X',' ',' ',' ',' ',' ',' ',' ',' ','X','X',' ',' ',' ',' ',' ',' ',' ','O','X','X',' ',' ',' ',' ',' ',' ',' ',' ','X','X','X','X','X','X','X','X','X','X','X'}; //On initialise le niveau
long PositionDuJoueur;
int NombreDeCubesRestants,Quitter,Direction,Mouvement;
char ToucheAppuyee,i,j;
NombreDeCubesRestants = 1;
Quitter = 1;
PositionDuJoueur = 22;//On initialise la position du joueur
//Présentation
printf(" \n");
printf(" _____________________ \n");
printf(" | | \n");
printf(" | PushBlocConsole | \n");
printf(" |_____________________| \n");
printf(" \n\n");
printf(" Appuyer sur 'q' pour aller a gauche.\n");
printf(" -sur 'z' pour aller en haut.\n");
printf(" -sur 's' pour aller en bas.\n");
printf(" -sur 'd' pour aller a droite.\n\n");
printf("Poussez les Blocs dans le trou.\n\n");
printf("Le Joueur -> 'J'\n");
printf("Les Blocs -> '#'\n");
printf("Le Trou -> 'O'\n\n");
printf("Appuyez sur n'importe quelle touche pour jouer");
getch();
//InitialiserJeu();
//Début de la boucle de jeu
while (NombreDeCubesRestants != 0 && Quitter == 1)
{
system("CLS");//On efface l'écran
//On affiche le niveau
printf("%c%c%c%c%c%c%c%c%c%c \n",Matrice[0],Matrice[1],Matrice[2],Matrice[3],Matrice[4],Matrice[5],Matrice[6],Matrice[7],Matrice[8],Matrice[9]);
printf("%c%c%c%c%c%c%c%c%c%c \n",Matrice[10],Matrice[11],Matrice[12],Matrice[13],Matrice[14],Matrice[15],Matrice[16],Matrice[17],Matrice[18],Matrice[19]);
printf("%c%c%c%c%c%c%c%c%c%c \n",Matrice[20],Matrice[21],Matrice[22],Matrice[23],Matrice[24],Matrice[25],Matrice[26],Matrice[27],Matrice[28],Matrice[29]);
printf("%c%c%c%c%c%c%c%c%c%c \n",Matrice[30],Matrice[31],Matrice[32],Matrice[33],Matrice[34],Matrice[35],Matrice[36],Matrice[37],Matrice[38],Matrice[39]);
printf("%c%c%c%c%c%c%c%c%c%c \n",Matrice[40],Matrice[41],Matrice[42],Matrice[43],Matrice[44],Matrice[45],Matrice[46],Matrice[47],Matrice[48],Matrice[49]);
printf("%c%c%c%c%c%c%c%c%c%c \n",Matrice[50],Matrice[51],Matrice[52],Matrice[53],Matrice[54],Matrice[55],Matrice[56],Matrice[57],Matrice[58],Matrice[59]);
printf("%c%c%c%c%c%c%c%c%c%c \n",Matrice[60],Matrice[61],Matrice[62],Matrice[63],Matrice[64],Matrice[65],Matrice[66],Matrice[67],Matrice[68],Matrice[69]);
printf("%c%c%c%c%c%c%c%c%c%c \n",Matrice[70],Matrice[71],Matrice[72],Matrice[73],Matrice[74],Matrice[75],Matrice[76],Matrice[77],Matrice[78],Matrice[79]);
printf("%c%c%c%c%c%c%c%c%c%c \n",Matrice[80],Matrice[81],Matrice[82],Matrice[83],Matrice[84],Matrice[85],Matrice[86],Matrice[87],Matrice[88],Matrice[89]);
printf("%c%c%c%c%c%c%c%c%c%c \n",Matrice[90],Matrice[91],Matrice[92],Matrice[93],Matrice[94],Matrice[95],Matrice[96],Matrice[97],Matrice[98],Matrice[99]);
ToucheAppuyee = getch();//Détermination de la touche appuyée
if (ToucheAppuyee != '0') //Si la touche appuyée n'est pas celle qui permet de quitter le jeu
{
Direction = DeterminerDirection(ToucheAppuyee);
i = PositionDuJoueur + Direction;
j = PositionDuJoueur + Direction * 2;
Mouvement = TypeMouvement(Matrice[i],Matrice[j]);
if (Mouvement != 0)
{
if (Mouvement == 1) //Y a rien devant, le chemin est libre
{
Matrice[PositionDuJoueur] = ' ';
Matrice[PositionDuJoueur + Direction] = 'J';
PositionDuJoueur = i;
}
if (Mouvement == 2) //On pousse le bloc
{
Matrice[PositionDuJoueur + Direction * 2] = '#';
Matrice[PositionDuJoueur + Direction] = 'J';
Matrice[PositionDuJoueur] = ' ';
PositionDuJoueur = i;
}
if (Mouvement == 3) //On pousse le bloc dans le trou
{
Matrice[PositionDuJoueur] = ' ';
Matrice[PositionDuJoueur + Direction] = 'J';
PositionDuJoueur = i;
NombreDeCubesRestants--;
}
}
}
else //Si tu ne veux pas ne pas quitter, c'est que tu veux quitter !!!
{
Quitter = 0;
}
}
system("CLS");// On fait le champ libre
if (NombreDeCubesRestants == 0) printf("Bravo tu a reussi !");
else printf("Bye Bye !");
getch();
return 0;
} |
Partager