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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
| #include <iostream> // bibliothèque de gestion des E/S
#include <conio.h> // gestion de la console (ici _getch())
#include <Windows.h>
#define MIN(X,Y) ((X)<=(Y)?(X):(Y))
#define MAX(X,Y) ((X)>=(Y)?(X):(Y))
using namespace std;
const int H = 5, L = 5;
int iPersonnage = 0, jPersonnage = 0; // exemple
int jeu[L][H] = { { 0, 0, 0, 0, 1 },
{ 0, 0, 0, 3, 0 },
{ 0, 0, 1, 1, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 } };
/***************************
Affichage du plateau de jeu
***************************/
void affichageJeu()
{
int i, j;
for (i = 0; i < L; i++)
{
for (j = 0; j < H; j++)
{
cout << jeu[i][j] << "\t";
}
cout << endl;
}
}
/***************************
Explosion d'une bombe à la ligne i et colonne j
Le plus simple est de créer une fonction récursive
pour tenir compte des réactions en chaines
Personnellement, quand une zone est atteinte par une bombe,
je remplace le contenu de la case par -1
***************************/
void explosion(int iBombe, int jBombe)
{
int i = jeu[iBombe][jBombe]; //Permet de savoir la puissance de la bombe activée en premier
jeu[iPersonnage][jPersonnage] = -2; // Permet de localiser visuellement le personnage
int Explosion; // Utile pour la boucle for
int imin = H-1, jmin = L-1, imax = H, jmax = L;
if (jeu[iBombe][jBombe] == i) //Permet de répendre l'impacte de la bombe, même si celle ci est égale à 1000000000
{
// Explosion des cases
for (Explosion = 0; Explosion <= i; Explosion++)
{
//Il manque ici la gestion de définition des nouveaux coordonés d'une éventuelle bombe impacté par la première
// Appelle de cette fonction avec les coordonnés de la nouvelle bombe déclancher par la précedente
jeu[iBombe][jBombe] = -1; //Bombe elle même.
//iBombe H
//jBombe L
/*if (i + iBombe > H) break;*/
if (jeu[iBombe - (Explosion)][jBombe] > 0)
{
explosion(iBombe - Explosion, jBombe); // haut
}
if (jeu[iBombe][jBombe + (Explosion)] > 0)
{
explosion(iBombe, jBombe + Explosion); //Droite
}
if (jeu[iBombe + (Explosion)][jBombe] > 0)
{
explosion(iBombe + Explosion, jBombe); //Bas
}
if (jeu[iBombe][jBombe - (Explosion)] > 0)
{
explosion(iBombe, jBombe - Explosion); //Gauche
}
if (iBombe - Explosion >= 0)
break;
else jeu[iBombe - Explosion][jBombe] = -1; //Haut
if (jBombe + Explosion >= jmax)
break;
else jeu[iBombe][jBombe + Explosion] = -1;//Droite
if (iBombe + Explosion >= imax)
break;
else jeu[iBombe + Explosion][jBombe] = -1; //Bas
if (jBombe - Explosion >= jmin)
break;
else jeu[iBombe][jBombe - Explosion] = -1;//Gauche
/**********************************************************/
/*
int imin = 0, imax = H, jmin = 0, jmax = L;
// on applique une correction éventuelle pour les bords.
if (imin <0) imin = 0;
if (jmin <0) jmin = 0;
if (imax >= H) imax = H - 1;
if (jmax >=L) jmax = L - 1;
/***********************************************************/
}
}
}
/*****************************
Fonction principale
*****************************/
int main() // Fonction principale
{
// La commande ci-dessous permet d'obtenir les accents
// dans la console. Mais il faut choisir la police de
// caractères Consolas ou Lucida
SetConsoleOutputCP(1252);
explosion(2, 2);
cout << "PLATEAU DE JEU APRES EXPLOSION DE LA BOMBE " << endl;
cout << "LES -1 INDIQUENT LES POSITIONS DETRUITES" << endl;
cout << "Et pour finir, le -2 représente votre personnage, du moins si il est toujours vivant" << endl;
affichageJeu();
// Indiquer si le personnage est encore vivant après l'explosion
if (jeu[iPersonnage][jPersonnage] == -1)
cout << "Le personnage est mort";
else cout << "Le personnage est vivant";
_getch();
return 0; // fin du programme. Le code 0 est envoyé
} |
Partager