|
@@ -353,15 +353,17 @@ boolean player_collision_index(Game* g, int x, int y, int* index) {
|
|
|
}
|
|
|
|
|
|
boolean bomb_explode(Game* g, int playerIndex, int x, int y, JsonEncoder* json) {
|
|
|
- JsonEncoder object, notif;
|
|
|
- JsonArray bomb, bonus, chain;
|
|
|
+ JsonEncoder object, notif, coord;
|
|
|
+ JsonArray bomb, bonus, chain, explosion;
|
|
|
int res, index, cBomb = 0, cBonus = 0, cChain = 0;
|
|
|
//Inie json
|
|
|
ini_encoder(&object);
|
|
|
ini_encoder(¬if);
|
|
|
+ ini_encoder(&coord);
|
|
|
ini_array_encoder(&bomb);
|
|
|
ini_array_encoder(&bonus);
|
|
|
ini_array_encoder(&chain);
|
|
|
+ ini_array_encoder(&explosion);
|
|
|
//Mutex
|
|
|
pthread_mutex_lock(&gameMutex[g->index]);
|
|
|
if (playerIndex >= 0) pthread_mutex_lock(&playerMutex[(g->index * MAXPLAYER) + playerIndex]);
|
|
@@ -392,6 +394,11 @@ boolean bomb_explode(Game* g, int playerIndex, int x, int y, JsonEncoder* json)
|
|
|
memset(pos, 0, 20);
|
|
|
snprintf(pos, 20, "%d,%d", x, y);
|
|
|
add_string(json, "pos", pos);
|
|
|
+ //Ajoute coord explosion
|
|
|
+ add_integer(&coord, "x", x);
|
|
|
+ add_integer(&coord, "y", y);
|
|
|
+ add_array_object(&explosion, &coord);
|
|
|
+ clean_json_encoder(&coord);
|
|
|
//Calcul l'explosion non mine
|
|
|
if (g->map[x][y] != '2') {
|
|
|
g->map[x][y] = '_';
|
|
@@ -418,6 +425,11 @@ boolean bomb_explode(Game* g, int playerIndex, int x, int y, JsonEncoder* json)
|
|
|
add_array_object(&bonus, &object);
|
|
|
clean_json_encoder(&object);
|
|
|
}
|
|
|
+ //Ajoute coord explosion
|
|
|
+ add_integer(&coord, "x", x);
|
|
|
+ add_integer(&coord, "y", y - 1 - i);
|
|
|
+ add_array_object(&explosion, &coord);
|
|
|
+ clean_json_encoder(&coord);
|
|
|
break;
|
|
|
}
|
|
|
//Si un joueur
|
|
@@ -438,12 +450,17 @@ boolean bomb_explode(Game* g, int playerIndex, int x, int y, JsonEncoder* json)
|
|
|
//Si une bombe
|
|
|
if (g->map[x][y - 1 - i] == '1' || g->map[x][y - 1 - i] == '2' || g->map[x][y - 1 - i] == '3') {
|
|
|
cChain++;
|
|
|
- bomb_chain(g, playerIndex, x, y - 1 - i, &chain);
|
|
|
+ bomb_chain(g, playerIndex, x, y - 1 - i, &chain, &explosion);
|
|
|
}
|
|
|
//Si un mur solide
|
|
|
if (g->map[x][y - 1 - i] == '-') {
|
|
|
break;
|
|
|
}
|
|
|
+ //Ajoute coord explosion
|
|
|
+ add_integer(&coord, "x", x);
|
|
|
+ add_integer(&coord, "y", y - 1 - i);
|
|
|
+ add_array_object(&explosion, &coord);
|
|
|
+ clean_json_encoder(&coord);
|
|
|
} else {
|
|
|
break;
|
|
|
}
|
|
@@ -465,6 +482,11 @@ boolean bomb_explode(Game* g, int playerIndex, int x, int y, JsonEncoder* json)
|
|
|
add_array_object(&bonus, &object);
|
|
|
clean_json_encoder(&object);
|
|
|
}
|
|
|
+ //Ajoute coord explosion
|
|
|
+ add_integer(&coord, "x", x);
|
|
|
+ add_integer(&coord, "y", y + 1 + i);
|
|
|
+ add_array_object(&explosion, &coord);
|
|
|
+ clean_json_encoder(&coord);
|
|
|
break;
|
|
|
}
|
|
|
//Si un joueur
|
|
@@ -485,12 +507,17 @@ boolean bomb_explode(Game* g, int playerIndex, int x, int y, JsonEncoder* json)
|
|
|
//Si une bombe
|
|
|
if (g->map[x][y + 1 + i] == '1' || g->map[x][y + 1 + i] == '2' || g->map[x][y + 1 + i] == '3') {
|
|
|
cChain++;
|
|
|
- bomb_chain(g, playerIndex, x, y + 1 + i, &chain);
|
|
|
+ bomb_chain(g, playerIndex, x, y + 1 + i, &chain, &explosion);
|
|
|
}
|
|
|
//Si un mur solide
|
|
|
if (g->map[x][y + 1 + i] == '-') {
|
|
|
break;
|
|
|
}
|
|
|
+ //Ajoute coord explosion
|
|
|
+ add_integer(&coord, "x", x);
|
|
|
+ add_integer(&coord, "y", y + 1 + i);
|
|
|
+ add_array_object(&explosion, &coord);
|
|
|
+ clean_json_encoder(&coord);
|
|
|
} else {
|
|
|
break;
|
|
|
}
|
|
@@ -512,6 +539,11 @@ boolean bomb_explode(Game* g, int playerIndex, int x, int y, JsonEncoder* json)
|
|
|
add_array_object(&bonus, &object);
|
|
|
clean_json_encoder(&object);
|
|
|
}
|
|
|
+ //Ajoute coord explosion
|
|
|
+ add_integer(&coord, "x", x - 1 - i);
|
|
|
+ add_integer(&coord, "y", y);
|
|
|
+ add_array_object(&explosion, &coord);
|
|
|
+ clean_json_encoder(&coord);
|
|
|
break;
|
|
|
}
|
|
|
//Si un joueur
|
|
@@ -532,12 +564,17 @@ boolean bomb_explode(Game* g, int playerIndex, int x, int y, JsonEncoder* json)
|
|
|
//Si une bombe
|
|
|
if (g->map[x - 1 - i][y] == '1' || g->map[x - 1 - i][y] == '2' || g->map[x - 1 - i][y] == '3') {
|
|
|
cChain++;
|
|
|
- bomb_chain(g, playerIndex, x - 1 - i, y, &chain);
|
|
|
+ bomb_chain(g, playerIndex, x - 1 - i, y, &chain, &explosion);
|
|
|
}
|
|
|
//Si un mur solide
|
|
|
if (g->map[x - 1 - i][y] == '-') {
|
|
|
break;
|
|
|
}
|
|
|
+ //Ajoute coord explosion
|
|
|
+ add_integer(&coord, "x", x - 1 - i);
|
|
|
+ add_integer(&coord, "y", y);
|
|
|
+ add_array_object(&explosion, &coord);
|
|
|
+ clean_json_encoder(&coord);
|
|
|
} else {
|
|
|
break;
|
|
|
}
|
|
@@ -559,6 +596,11 @@ boolean bomb_explode(Game* g, int playerIndex, int x, int y, JsonEncoder* json)
|
|
|
add_array_object(&bonus, &object);
|
|
|
clean_json_encoder(&object);
|
|
|
}
|
|
|
+ //Ajoute coord explosion
|
|
|
+ add_integer(&coord, "x", x + 1 + i);
|
|
|
+ add_integer(&coord, "y", y);
|
|
|
+ add_array_object(&explosion, &coord);
|
|
|
+ clean_json_encoder(&coord);
|
|
|
break;
|
|
|
}
|
|
|
//Si un joueur
|
|
@@ -579,18 +621,22 @@ boolean bomb_explode(Game* g, int playerIndex, int x, int y, JsonEncoder* json)
|
|
|
//Si une bombe
|
|
|
if (g->map[x + 1 + i][y] == '1' || g->map[x + 1 + i][y] == '2' || g->map[x + 1 + i][y] == '3') {
|
|
|
cChain++;
|
|
|
- bomb_chain(g, playerIndex, x + 1 + i, y, &chain);
|
|
|
+ bomb_chain(g, playerIndex, x + 1 + i, y, &chain, &explosion);
|
|
|
}
|
|
|
//Si un mur solide
|
|
|
if (g->map[x + 1 + i][y] == '-') {
|
|
|
break;
|
|
|
}
|
|
|
+ //Ajoute coord explosion
|
|
|
+ add_integer(&coord, "x", x + 1 + i);
|
|
|
+ add_integer(&coord, "y", y);
|
|
|
+ add_array_object(&explosion, &coord);
|
|
|
+ clean_json_encoder(&coord);
|
|
|
} else {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- //Si c'est une mine
|
|
|
+ }//Si c'est une mine
|
|
|
else {
|
|
|
g->map[x][y] = '_';
|
|
|
//Calcul dommage
|
|
@@ -615,23 +661,26 @@ boolean bomb_explode(Game* g, int playerIndex, int x, int y, JsonEncoder* json)
|
|
|
add_array(json, "bomb", &bomb);
|
|
|
add_array(json, "bonusMalus", &bonus);
|
|
|
add_array(json, "chain", &chain);
|
|
|
+ add_array(json, "explosion", &explosion);
|
|
|
//Nettoyage
|
|
|
if (playerIndex >= 0) pthread_mutex_unlock(&playerMutex[(g->index * MAXPLAYER) + playerIndex]);
|
|
|
pthread_mutex_unlock(&gameMutex[g->index]);
|
|
|
clean_json_array(&bomb);
|
|
|
clean_json_array(&bonus);
|
|
|
clean_json_array(&chain);
|
|
|
+ clean_json_array(&explosion);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-void bomb_chain(Game* g, int playerIndex, int x, int y, JsonArray* chain) {
|
|
|
- JsonEncoder json, notif;
|
|
|
+void bomb_chain(Game* g, int playerIndex, int x, int y, JsonArray* chain, JsonArray* explosion) {
|
|
|
+ JsonEncoder json, notif, coord;
|
|
|
int index;
|
|
|
Player* p;
|
|
|
obj_node* objn = NULL;
|
|
|
//Inie json
|
|
|
ini_encoder(&json);
|
|
|
ini_encoder(¬if);
|
|
|
+ ini_encoder(&coord);
|
|
|
//Determine le type de la bombe
|
|
|
switch (g->map[x][y]) {
|
|
|
case '1':
|
|
@@ -682,6 +731,11 @@ void bomb_chain(Game* g, int playerIndex, int x, int y, JsonArray* chain) {
|
|
|
//Si un mur destructible
|
|
|
if (g->map[x][y - 1 - i] == '*') {
|
|
|
g->map[x][y - 1 - i] = '_';
|
|
|
+ //Ajoute coord explosion
|
|
|
+ add_integer(&coord, "x", x);
|
|
|
+ add_integer(&coord, "y", y - 1 - i);
|
|
|
+ add_array_object(explosion, &coord);
|
|
|
+ clean_json_encoder(&coord);
|
|
|
break;
|
|
|
}
|
|
|
//Si un joueur
|
|
@@ -701,12 +755,17 @@ void bomb_chain(Game* g, int playerIndex, int x, int y, JsonArray* chain) {
|
|
|
}
|
|
|
//Si une bombe
|
|
|
if (g->map[x][y - 1 - i] == '1' || g->map[x][y - 1 - i] == '2' || g->map[x][y - 1 - i] == '3') {
|
|
|
- bomb_chain(g, playerIndex, x, y - 1 - i, chain);
|
|
|
+ bomb_chain(g, playerIndex, x, y - 1 - i, chain, explosion);
|
|
|
}
|
|
|
//Si un mur solide
|
|
|
if (g->map[x][y - 1 - i] == '-') {
|
|
|
break;
|
|
|
}
|
|
|
+ //Ajoute coord explosion
|
|
|
+ add_integer(&coord, "x", x);
|
|
|
+ add_integer(&coord, "y", y - 1 - i);
|
|
|
+ add_array_object(explosion, &coord);
|
|
|
+ clean_json_encoder(&coord);
|
|
|
} else {
|
|
|
break;
|
|
|
}
|
|
@@ -718,6 +777,11 @@ void bomb_chain(Game* g, int playerIndex, int x, int y, JsonArray* chain) {
|
|
|
//Si un mur destructible
|
|
|
if (g->map[x][y + 1 + i] == '*') {
|
|
|
g->map[x][y + 1 + i] = '_';
|
|
|
+ //Ajoute coord explosion
|
|
|
+ add_integer(&coord, "x", x);
|
|
|
+ add_integer(&coord, "y", y + 1 + i);
|
|
|
+ add_array_object(explosion, &coord);
|
|
|
+ clean_json_encoder(&coord);
|
|
|
break;
|
|
|
}
|
|
|
//Si un joueur
|
|
@@ -737,12 +801,17 @@ void bomb_chain(Game* g, int playerIndex, int x, int y, JsonArray* chain) {
|
|
|
}
|
|
|
//Si une bombe
|
|
|
if (g->map[x][y + 1 + i] == '1' || g->map[x][y + 1 + i] == '2' || g->map[x][y + 1 + i] == '3') {
|
|
|
- bomb_chain(g, playerIndex, x, y + 1 + i, chain);
|
|
|
+ bomb_chain(g, playerIndex, x, y + 1 + i, chain, explosion);
|
|
|
}
|
|
|
//Si un mur solide
|
|
|
if (g->map[x][y + 1 + i] == '-') {
|
|
|
break;
|
|
|
}
|
|
|
+ //Ajoute coord explosion
|
|
|
+ add_integer(&coord, "x", x);
|
|
|
+ add_integer(&coord, "y", y + 1 + i);
|
|
|
+ add_array_object(explosion, &coord);
|
|
|
+ clean_json_encoder(&coord);
|
|
|
} else {
|
|
|
break;
|
|
|
}
|
|
@@ -754,6 +823,11 @@ void bomb_chain(Game* g, int playerIndex, int x, int y, JsonArray* chain) {
|
|
|
//Si un mur destructible
|
|
|
if (g->map[x - 1 - i][y] == '*') {
|
|
|
g->map[x - 1 - i][y] = '_';
|
|
|
+ //Ajoute coord explosion
|
|
|
+ add_integer(&coord, "x", x - 1 - i);
|
|
|
+ add_integer(&coord, "y", y);
|
|
|
+ add_array_object(explosion, &coord);
|
|
|
+ clean_json_encoder(&coord);
|
|
|
break;
|
|
|
}
|
|
|
//Si un joueur
|
|
@@ -773,12 +847,17 @@ void bomb_chain(Game* g, int playerIndex, int x, int y, JsonArray* chain) {
|
|
|
}
|
|
|
//Si une bombe
|
|
|
if (g->map[x - 1 - i][y] == '1' || g->map[x - 1 - i][y] == '2' || g->map[x - 1 - i][y] == '3') {
|
|
|
- bomb_chain(g, playerIndex, x - 1 - i, y, chain);
|
|
|
+ bomb_chain(g, playerIndex, x - 1 - i, y, chain, explosion);
|
|
|
}
|
|
|
//Si un mur solide
|
|
|
if (g->map[x - 1 - i][y] == '-') {
|
|
|
break;
|
|
|
}
|
|
|
+ //Ajoute coord explosion
|
|
|
+ add_integer(&coord, "x", x - 1 - i);
|
|
|
+ add_integer(&coord, "y", y);
|
|
|
+ add_array_object(explosion, &coord);
|
|
|
+ clean_json_encoder(&coord);
|
|
|
} else {
|
|
|
break;
|
|
|
}
|
|
@@ -790,6 +869,11 @@ void bomb_chain(Game* g, int playerIndex, int x, int y, JsonArray* chain) {
|
|
|
//Si un mur destructible
|
|
|
if (g->map[x + 1 + i][y] == '*') {
|
|
|
g->map[x + 1 + i][y] = '_';
|
|
|
+ //Ajoute coord explosion
|
|
|
+ add_integer(&coord, "x", x + 1 + i);
|
|
|
+ add_integer(&coord, "y", y);
|
|
|
+ add_array_object(explosion, &coord);
|
|
|
+ clean_json_encoder(&coord);
|
|
|
break;
|
|
|
}
|
|
|
//Si un joueur
|
|
@@ -809,12 +893,17 @@ void bomb_chain(Game* g, int playerIndex, int x, int y, JsonArray* chain) {
|
|
|
}
|
|
|
//Si une bombe
|
|
|
if (g->map[x + 1 + i][y] == '1' || g->map[x + 1 + i][y] == '2' || g->map[x + 1 + i][y] == '3') {
|
|
|
- bomb_chain(g, playerIndex, x + 1 + i, y, chain);
|
|
|
+ bomb_chain(g, playerIndex, x + 1 + i, y, chain, explosion);
|
|
|
}
|
|
|
//Si un mur solide
|
|
|
if (g->map[x + 1 + i][y] == '-') {
|
|
|
break;
|
|
|
}
|
|
|
+ //Ajoute coord explosion
|
|
|
+ add_integer(&coord, "x", x + 1 + i);
|
|
|
+ add_integer(&coord, "y", y);
|
|
|
+ add_array_object(explosion, &coord);
|
|
|
+ clean_json_encoder(&coord);
|
|
|
} else {
|
|
|
break;
|
|
|
}
|