Skip to content
Snippets Groups Projects
Commit 65a98a2e authored by ERKEN EFE's avatar ERKEN EFE
Browse files

:wrench: UPDATE: Add functionality to move_player

Added functionality to the move_player function and fixed its test.
parent c2bdc1d4
Branches
Tags
No related merge requests found
#include <stdio.h>
#include <stdlib.h>
#include "player.h"
#include "grid.h"
......@@ -17,11 +19,29 @@ void move_player(grid* G, enum Direction D) {
target_column++;
}
enum CaseType target = G->game_grid[target_row][target_column];
if (target == WALL || target == BOX || target == GOAL) {
enum CaseType player = G->game_grid[G->player.y][G->player.x];
if (target == WALL || target == BOX) {
return;
} else if (target == GOAL) {
if (player == PLAYER) {
G->game_grid[target_row][target_column] = PLAYER_GOAL;
G->game_grid[G->player.y][G->player.x] = NONE;
} else if (player == PLAYER_GOAL) {
G->game_grid[target_row][target_column] = PLAYER_GOAL;
G->game_grid[G->player.y][G->player.x] = GOAL;
}
} else if (target == NONE) {
if (player == PLAYER) {
G->game_grid[target_row][target_column] = PLAYER;
G->game_grid[G->player.y][G->player.x] = NONE;
} else if (player == PLAYER_GOAL) {
G->game_grid[target_row][target_column] = PLAYER;
G->game_grid[G->player.y][G->player.x] = GOAL;
}
} else {
fprintf(stderr, "Error this level map has features unmanaged by the game\n");
exit(-1);
}
G->game_grid[target_row][target_column] = G->game_grid[G->player.y][G->player.x];
G->game_grid[G->player.y][G->player.x] = target;
G->player.x = target_column;
G->player.y = target_row;
}
......@@ -56,7 +56,9 @@ int main() {
display(level);
printf("Votre choix : ");
scanf(" %c", &quitCar);
move_player(level, quitCar);
if (quitCar == 'h' || quitCar == 'j' || quitCar == 'k' || quitCar == 'l') {
move_player(level, quitCar);
}
}
free_level(level);
return 0;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment