|
@@ -66,6 +66,27 @@ char* unparse_map(char** map, int width, int height) {
|
|
|
return mapContent;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Cherche le joueur à qui appartient un objet
|
|
|
+ * @param Game* La game du joueur
|
|
|
+ * @param int Le type de l'objet
|
|
|
+ * @param int X de l'objet
|
|
|
+ * @param int Y de l'objet
|
|
|
+ * @return Player* Le joueur trouvé ou NULL
|
|
|
+ */
|
|
|
+Player* search_player_object(Game* g, int type, int x, int y){
|
|
|
+ obj_node* objn;
|
|
|
+ for(int i = 0; i < MAXPLAYER; i++){
|
|
|
+ if(g->player[i]->ini){
|
|
|
+ objn = object_search(g->player[i]->bomb, type, x, y);
|
|
|
+ if(objn != NULL){
|
|
|
+ return g->player[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return NULL;
|
|
|
+}
|
|
|
+
|
|
|
/* --- Fonctions publiques --- */
|
|
|
boolean ini_games() {
|
|
|
//Ini les games
|
|
@@ -350,14 +371,17 @@ boolean bomb_explode(Game* g, int playerIndex, int x, int y, JsonEncoder* json)
|
|
|
case '1':
|
|
|
add_string(json, "type", "classic");
|
|
|
g->player[playerIndex]->classicBomb++;
|
|
|
+ g->player[playerIndex]->nbBomb--;
|
|
|
break;
|
|
|
case '2':
|
|
|
add_string(json, "type", "mine");
|
|
|
g->player[playerIndex]->mine++;
|
|
|
+ g->player[playerIndex]->nbBomb--;
|
|
|
break;
|
|
|
case '3':
|
|
|
add_string(json, "type", "remote");
|
|
|
g->player[playerIndex]->remoteBomb++;
|
|
|
+ g->player[playerIndex]->nbBomb--;
|
|
|
break;
|
|
|
default:
|
|
|
if(playerIndex >= 0) pthread_mutex_unlock(&playerMutex[(g->index * MAXPLAYER) + playerIndex]);
|
|
@@ -605,6 +629,8 @@ boolean bomb_explode(Game* g, int playerIndex, int x, int y, JsonEncoder* json)
|
|
|
void bomb_chain(Game* g, int playerIndex, int x, int y, JsonArray* chain) {
|
|
|
JsonEncoder json, notif;
|
|
|
int index;
|
|
|
+ Player* p;
|
|
|
+ obj_node* objn = NULL;
|
|
|
//Inie json
|
|
|
ini_encoder(&json);
|
|
|
ini_encoder(¬if);
|
|
@@ -612,12 +638,33 @@ void bomb_chain(Game* g, int playerIndex, int x, int y, JsonArray* chain) {
|
|
|
switch (g->map[x][y]) {
|
|
|
case '1':
|
|
|
add_string(&json, "type", "classic");
|
|
|
+ p = search_player_object(g, OBJ_BCLASSIC, x, y);
|
|
|
+ if(p != NULL){
|
|
|
+ p->classicBomb++;
|
|
|
+ p->nbBomb--;
|
|
|
+ objn = object_search(p->bomb, OBJ_BCLASSIC, x, y);
|
|
|
+ object_delete(p->bomb, objn);
|
|
|
+ }
|
|
|
break;
|
|
|
case '2':
|
|
|
add_string(&json, "type", "mine");
|
|
|
+ p = search_player_object(g, OBJ_BMINE, x, y);
|
|
|
+ if(p != NULL){
|
|
|
+ p->mine++;
|
|
|
+ p->nbBomb--;
|
|
|
+ objn = object_search(p->bomb, OBJ_BMINE, x, y);
|
|
|
+ object_delete(p->bomb, objn);
|
|
|
+ }
|
|
|
break;
|
|
|
case '3':
|
|
|
add_string(&json, "type", "remote");
|
|
|
+ p = search_player_object(g, OBJ_BREMOTE, x, y);
|
|
|
+ if(p != NULL){
|
|
|
+ p->remoteBomb++;
|
|
|
+ p->nbBomb--;
|
|
|
+ objn = object_search(p->bomb, OBJ_BREMOTE, x, y);
|
|
|
+ object_delete(p->bomb, objn);
|
|
|
+ }
|
|
|
break;
|
|
|
default:
|
|
|
return;
|