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

:sparkles: NEW: Add move_player func and its tests

Added new function to move the player and some tests to go along.
parent 6b111f0a
Branches
Tags
No related merge requests found
player.c 0 → 100644
#include "player.h"
#include "grid.h"
void move_player(grid* G, enum Direction D) {
int target_row = G->player.y, target_column = G->player.x;
switch (D) {
case LEFT:
target_column--;
break;
case BOTTOM:
target_row++;
break;
case TOP:
target_row--;
break;
case RIGHT:
target_column++;
}
enum CaseType target = G->game_grid[target_row][target_column];
if (target == WALL || target == BOX || target == GOAL) {
return;
}
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;
}
......@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include "grid.h"
#include "player.h"
int main01()
{
......@@ -38,15 +39,25 @@ int main02() {
}
int main03() {
// Test de la fonction display_stdio() et display_ncurses() dans grid.c
// Test de la fonction display() dans grid.c
grid* level = init_level("level1.txt");
// display_stdio(level);
display_ncurses(level);
display(level);
free_grid(level);
return 0;
}
int main() {
// Test de la fonction move_player() dans player.c
grid* level = init_level("level1.txt");
char quitCar = '\0';
while (quitCar != 'q') {
printf("Appuyez sur \"q\" pour quitter\n");
printf("Appuyez sur \"h, j, k, l\" pour vous déplacer\n\n");
display(level);
printf("Votre choix : ");
scanf(" %c", &quitCar);
move_player(level, quitCar);
}
free_grid(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