| 
					
				 | 
			
			
				@@ -175,7 +175,7 @@ int create_game(char* name, char* map) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         game[index].player[i] = malloc(sizeof (Player)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         game[index].player[i]->ini = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    game[index].object = malloc(sizeof(Object)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    game[index].object = malloc(sizeof (Object)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     object_ini(game[index].object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     //object_add(game[index].object, OBJ_MAJOR, 1, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     pthread_mutex_unlock(&gameMutex[index]); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -299,6 +299,491 @@ boolean player_collision(Game* g, int x, int y) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+boolean player_collision_index(Game* g, int x, int y, int* index) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for (int i = 0; i < MAXPLAYER; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (g->player[i]->ini) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (g->player[i]->x == x && g->player[i]->y == y) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                *index = i; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+boolean bomb_explode(Game* g, int playerIndex, int x, int y, JsonEncoder* json) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    printf("Explode\n"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    JsonEncoder object, notif; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    JsonArray bomb, bonus, chain; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    int res, index, cBomb = 0, cBonus = 0, cChain = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Inie json 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ini_encoder(&object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ini_encoder(¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ini_array_encoder(&bomb); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ini_array_encoder(&bonus); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ini_array_encoder(&chain); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Mutex 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    pthread_mutex_lock(&gameMutex[g->index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    pthread_mutex_lock(&playerMutex[(g->index * MAXPLAYER) + playerIndex]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Determine le type de la bombe 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    switch (g->map[x][y]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case '1': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            add_string(json, "type", "classic"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case '2': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            add_string(json, "type", "mine"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case '3': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            add_string(json, "type", "remote"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        default: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            pthread_mutex_unlock(&playerMutex[(g->index * MAXPLAYER) + playerIndex]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            pthread_mutex_unlock(&gameMutex[g->index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Determine la position de la bombe 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    char pos[20]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    memset(pos, 0, 20); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    snprintf(pos, 20, "%d,%d", x, y); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    add_string(json, "pos", pos); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Si le joueur à un bonus 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (g->player[playerIndex]->firePower > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        add_boolean(json, "bonus", true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        add_boolean(json, "bonus", false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Calcul l'explosion non mine 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (g->map[x][y] != '2') { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        g->map[x][y] = '_'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //Vers le haut 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < 2 + g->player[playerIndex]->firePower; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //Si on est dans la map 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (y - 1 - i >= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Si un mur destructible 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (g->map[x][y - 1 - i] == '*') { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    g->map[x][y - 1 - i] = '_'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    res = spawn_object(g, x, y - 1 - i, &object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (res == 1) { //Bombe 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        cBomb++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        add_array_object(&bomb, &object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        clean_json_encoder(&object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } else if (res == 2) { //Bonus Malus 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        cBonus++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        add_array_object(&bonus, &object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        clean_json_encoder(&object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Si un joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (player_collision_index(g, x, y - 1 - i, &index)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (index != playerIndex) pthread_mutex_lock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (g->player[index]->major == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //Baisse la vie 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        g->player[index]->life = g->player[index]->life - (g->player[index]->maxLife * (DAMAGEBOMB - (0.1 * i))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //Notification du joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        describe_player(g->player[index], ¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        if (!notify_client(g->player[index]->cli, "POST", "attack/affect", ¬if)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            adderror("Impossible de notifer le client"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        clean_json_encoder(¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (index != playerIndex) pthread_mutex_unlock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //Vers le bas 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < 2 + g->player[playerIndex]->firePower; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //Si on est dans la map 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (y + 1 + i <= g->height) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Si un mur destructible 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (g->map[x][y + 1 + i] == '*') { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    g->map[x][y + 1 + i] = '_'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    res = spawn_object(g, x, y + 1 + i, &object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (res == 1) { //Bombe 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        cBomb++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        add_array_object(&bomb, &object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        clean_json_encoder(&object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } else if (res == 2) { //Bonus Malus 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        cBonus++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        add_array_object(&bonus, &object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        clean_json_encoder(&object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Si un joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (player_collision_index(g, x, y + 1 + i, &index)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (index != playerIndex) pthread_mutex_lock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (g->player[index]->major == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //Baisse la vie 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        g->player[index]->life = g->player[index]->life - (g->player[index]->maxLife * (DAMAGEBOMB - (0.1 * i))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //Notification du joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        describe_player(g->player[index], ¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        if (!notify_client(g->player[index]->cli, "POST", "attack/affect", ¬if)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            adderror("Impossible de notifer le client"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        clean_json_encoder(¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (index != playerIndex) pthread_mutex_unlock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //Vers la gauche 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < 2 + g->player[playerIndex]->firePower; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //Si on est dans la map 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (x - 1 - i >= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Si un mur destructible 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (g->map[x - 1 - i][y] == '*') { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    g->map[x - 1 - i][y] = '_'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    res = spawn_object(g, x - 1 - i, y, &object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (res == 1) { //Bombe 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        cBomb++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        add_array_object(&bomb, &object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        clean_json_encoder(&object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } else if (res == 2) { //Bonus Malus 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        cBonus++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        add_array_object(&bonus, &object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        clean_json_encoder(&object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Si un joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (player_collision_index(g, x - 1 - i, y, &index)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (index != playerIndex) pthread_mutex_lock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (g->player[index]->major == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //Baisse la vie 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        g->player[index]->life = g->player[index]->life - (g->player[index]->maxLife * (DAMAGEBOMB - (0.1 * i))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //Notification du joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        describe_player(g->player[index], ¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        if (!notify_client(g->player[index]->cli, "POST", "attack/affect", ¬if)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            adderror("Impossible de notifer le client"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        clean_json_encoder(¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (index != playerIndex) pthread_mutex_unlock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //Vers la droite 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < 2 + g->player[playerIndex]->firePower; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //Si on est dans la map 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (x + 1 + i >= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Si un mur destructible 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (g->map[x + 1 + i][y] == '*') { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    g->map[x + 1 + i][y] = '_'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    res = spawn_object(g, x + 1 + i, y, &object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (res == 1) { //Bombe 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        cBomb++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        add_array_object(&bomb, &object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        clean_json_encoder(&object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } else if (res == 2) { //Bonus Malus 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        cBonus++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        add_array_object(&bonus, &object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        clean_json_encoder(&object); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Si un joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (player_collision_index(g, x + 1 + i, y, &index)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (index != playerIndex) pthread_mutex_lock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (g->player[index]->major == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //Baisse la vie 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        g->player[index]->life = g->player[index]->life - (g->player[index]->maxLife * (DAMAGEBOMB - (0.1 * i))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //Notification du joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        describe_player(g->player[index], ¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        if (!notify_client(g->player[index]->cli, "POST", "attack/affect", ¬if)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            adderror("Impossible de notifer le client"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        clean_json_encoder(¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (index != playerIndex) pthread_mutex_unlock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }         
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Si c'est une mine 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        g->map[x][y] = '_'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //Recup le joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (player_collision_index(g, x, y, &index)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (index != playerIndex) pthread_mutex_lock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (g->player[index]->major == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Baisse la vie 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                g->player[index]->life = g->player[index]->life - (g->player[index]->maxLife * DAMAGEMINE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Notification du joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                describe_player(g->player[index], ¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (!notify_client(g->player[index]->cli, "POST", "attack/affect", ¬if)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    adderror("Impossible de notifer le client"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                clean_json_encoder(¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (index != playerIndex) pthread_mutex_unlock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Affichage de la map 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Ajout des json 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    add_array(json, "bomb", &bomb); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    add_array(json, "bonusMalus", &bonus); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    add_array(json, "chain", &chain); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Nettoyage 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    pthread_mutex_unlock(&playerMutex[(g->index * MAXPLAYER) + playerIndex]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    pthread_mutex_unlock(&gameMutex[g->index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+void bomb_chain(Game* g, int playerIndex, int x, int y, JsonArray* chain) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    JsonEncoder json, notif; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    int index; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Inie json 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ini_encoder(&json); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ini_encoder(¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Determine le type de la bombe 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    switch (g->map[x][y]) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case '1': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            add_string(&json, "type", "classic"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case '2': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            add_string(&json, "type", "mine"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case '3': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            add_string(&json, "type", "remote"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        default: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Determine la position de la bombe 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    char pos[20]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    memset(pos, 0, 20); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    snprintf(pos, 20, "%d,%d", x, y); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    add_string(&json, "pos", pos); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Calcul l'explosion non mine 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (g->map[x][y] != '2') { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        g->map[x][y] = '_'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //Vers le haut 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < 2; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //Si on est dans la map 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (y - 1 - i >= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Si un mur destructible 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (g->map[x][y - 1 - i] == '*') { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    g->map[x][y - 1 - i] = '_'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Si un joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (player_collision_index(g, x, y - 1 - i, &index)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (index != playerIndex) pthread_mutex_lock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (g->player[index]->major == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //Baisse la vie 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        g->player[index]->life = g->player[index]->life - (g->player[index]->maxLife * (DAMAGEBOMB - (0.1 * i))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //Notification du joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        describe_player(g->player[index], ¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        if (!notify_client(g->player[index]->cli, "POST", "attack/affect", ¬if)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            adderror("Impossible de notifer le client"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        clean_json_encoder(¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (index != playerIndex) pthread_mutex_unlock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //Vers le bas 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < 2 + g->player[playerIndex]->firePower; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //Si on est dans la map 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (y + 1 + i <= g->height) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Si un mur destructible 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (g->map[x][y + 1 + i] == '*') { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    g->map[x][y + 1 + i] = '_'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Si un joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (player_collision_index(g, x, y + 1 + i, &index)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (index != playerIndex) pthread_mutex_lock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (g->player[index]->major == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //Baisse la vie 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        g->player[index]->life = g->player[index]->life - (g->player[index]->maxLife * (DAMAGEBOMB - (0.1 * i))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //Notification du joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        describe_player(g->player[index], ¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        if (!notify_client(g->player[index]->cli, "POST", "attack/affect", ¬if)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            adderror("Impossible de notifer le client"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        clean_json_encoder(¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (index != playerIndex) pthread_mutex_unlock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //Vers la gauche 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < 2 + g->player[playerIndex]->firePower; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //Si on est dans la map 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (x - 1 - i >= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Si un mur destructible 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (g->map[x - 1 - i][y] == '*') { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    g->map[x - 1 - i][y] = '_'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Si un joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (player_collision_index(g, x - 1 - i, y, &index)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (index != playerIndex) pthread_mutex_lock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (g->player[index]->major == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //Baisse la vie 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        g->player[index]->life = g->player[index]->life - (g->player[index]->maxLife * (DAMAGEBOMB - (0.1 * i))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //Notification du joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        describe_player(g->player[index], ¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        if (!notify_client(g->player[index]->cli, "POST", "attack/affect", ¬if)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            adderror("Impossible de notifer le client"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        clean_json_encoder(¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (index != playerIndex) pthread_mutex_unlock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //Vers la droite 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < 2 + g->player[playerIndex]->firePower; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //Si on est dans la map 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (x + 1 + i >= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Si un mur destructible 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (g->map[x + 1 + i][y] == '*') { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    g->map[x + 1 + i][y] = '_'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Si un joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (player_collision_index(g, x + 1 + i, y, &index)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (index != playerIndex) pthread_mutex_lock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (g->player[index]->major == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //Baisse la vie 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        g->player[index]->life = g->player[index]->life - (g->player[index]->maxLife * (DAMAGEBOMB - (0.1 * i))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //Notification du joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        describe_player(g->player[index], ¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        if (!notify_client(g->player[index]->cli, "POST", "attack/affect", ¬if)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            adderror("Impossible de notifer le client"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        clean_json_encoder(¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (index != playerIndex) pthread_mutex_unlock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }         
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Si c'est une mine 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        g->map[x][y] = '_'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //Recup le joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (player_collision_index(g, x, y, &index)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (index != playerIndex) pthread_mutex_lock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (g->player[index]->major == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Baisse la vie 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                g->player[index]->life = g->player[index]->life - (g->player[index]->maxLife * DAMAGEMINE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //Notification du joueur 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                describe_player(g->player[index], ¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (!notify_client(g->player[index]->cli, "POST", "attack/affect", ¬if)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    adderror("Impossible de notifer le client"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                clean_json_encoder(¬if); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (index != playerIndex) pthread_mutex_unlock(&playerMutex[(g->index * MAXPLAYER) + index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Ajoute json dans le tableau 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    add_array_object(chain, &json); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Nettoyage 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    clean_json_encoder(&json); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+int spawn_object(Game* g, int x, int y, JsonEncoder* json) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    int random, res = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Generation random si spawn ou non 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    srand(time(NULL)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    random = rand() % 100 + 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (random > SPAWNRATE) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return 0; //Pas de spawn 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Choisit l'objet 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    random = rand() % 11; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    switch (random) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case OBJ_BCLASSIC: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            res = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            add_string(json, "type", "classic"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case OBJ_BMINE: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            res = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            add_string(json, "type", "mine"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case OBJ_BREMOTE: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            res = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            add_string(json, "type", "remote"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case OBJ_BOMBUP: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            res = 2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            add_string(json, "type", "bomb_up"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case OBJ_BOMBDOWN: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            res = 2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            add_string(json, "type", "bomb_down"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case OBJ_FIREPOWER: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            res = 2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            add_string(json, "type", "fire_power"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case OBJ_SCOOTER: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            res = 2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            add_string(json, "type", "scooter"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case OBJ_BROKENLEG: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            res = 2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            add_string(json, "type", "broken_legs"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case OBJ_LIFEUP: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            res = 2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            add_string(json, "type", "life_up"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case OBJ_LIFEMAX: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            res = 2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            add_string(json, "type", "life_max"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        case OBJ_MAJOR: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            res = 2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            add_string(json, "type", "major"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Ajoute l'objet dans la partie 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    object_add(g->object, random, x, y); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Ajoute postion au json 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    char pos[20]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    memset(pos, 0, 20); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    snprintf(pos, 20, "%d,%d", x, y); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    add_string(json, "pos", pos); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //Retourne type d'ajout 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return res; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 void remove_player(Game* g, int playerIndex) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     pthread_mutex_lock(&gameMutex[g->index]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     pthread_mutex_lock(&playerMutex[(g->index * MAXPLAYER) + playerIndex]); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -314,12 +799,12 @@ void stop_game(Game* g) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     g->active = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     //Suppr les joueurs 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     for (int i = 0; i < MAXPLAYER; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        pthread_mutex_lock(&playerMutex[(g->index * MAXPLAYER) + i]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //pthread_mutex_lock(&playerMutex[(g->index * MAXPLAYER) + i]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (g->player[i]->ini) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             delete_player(g->player[i]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         free(g->player[i]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        pthread_mutex_unlock(&playerMutex[(g->index * MAXPLAYER) + i]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //pthread_mutex_unlock(&playerMutex[(g->index * MAXPLAYER) + i]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     //Libere la memoire 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     object_clean(g->object); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -338,6 +823,7 @@ void stop_game(Game* g) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 void clean_games() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     for (int i = 0; i < MAXGAME; i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (game[i].active) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            pthread_mutex_unlock(&gameMutex[i]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             stop_game(&game[i]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 |