Skip to content
Snippets Groups Projects
Commit 6fd6857f authored by YANG TIANYI's avatar YANG TIANYI
Browse files

Resoudre un problem de regle de jeux

parent 18f5c499
Branches
No related merge requests found
......@@ -26,6 +26,8 @@ enum CaseType{
BOX = '$',
PLAYER = '@',
GOAL = '.',
BOX_ON = '*',
PLAYER_ON = '/',
NONE = ' '
};
......
......@@ -40,16 +40,35 @@ void move_player(struct Grid *g, enum Direction d)
}
if (g->game_grid[next_x][next_y] == NONE)
{ // si prochaine position est ' ' on remplir prochaine et reset player position
g->game_grid[next_x][next_y] = PLAYER;
g->game_grid[g->position.x][g->position.y] = NONE;
g->position.x = next_x;
g->position.y = next_y;
if (g->game_grid[g->position.x][g->position.y] == PLAYER_ON)
{
g->game_grid[next_x][next_y] = PLAYER;
g->game_grid[g->position.x][g->position.y] = GOAL;
g->position.x = next_x;
g->position.y = next_y;
}
else
{
g->game_grid[next_x][next_y] = PLAYER;
g->game_grid[g->position.x][g->position.y] = NONE;
g->position.x = next_x;
g->position.y = next_y;
}
}
if (g->game_grid[next_x][next_y] == BOX)
{
int box_x = (next_x - g->position.x) * 2 + g->position.x;
int box_y = (next_y - g->position.y) * 2 + g->position.y;
if (g->game_grid[g->position.x][g->position.y] == PLAYER_ON)
{
g->game_grid[box_x][box_y] = BOX;
g->game_grid[next_x][next_y] = PLAYER;
g->game_grid[g->position.x][g->position.y] = GOAL;
g->position.x = next_x;
g->position.y = next_y;
}
if (g->game_grid[box_x][box_y] == NONE)
{
g->game_grid[box_x][box_y] = BOX;
......@@ -58,14 +77,39 @@ void move_player(struct Grid *g, enum Direction d)
g->position.x = next_x;
g->position.y = next_y;
}
if (g->game_grid[box_x][box_y] == GOAL)
{
g->game_grid[box_x][box_y] = BOX;
g->game_grid[box_x][box_y] = BOX_ON;
g->game_grid[next_x][next_y] = PLAYER;
g->game_grid[g->position.x][g->position.y] = NONE;
g->position.x = next_x;
g->position.y = next_y;
g->box_goal_number++;
}
}
if (g->game_grid[next_x][next_y] == GOAL)
{
g->game_grid[next_x][next_y] = PLAYER_ON;
g->game_grid[g->position.x][g->position.y] = NONE;
g->position.x = next_x;
g->position.y = next_y;
}
if (g->game_grid[next_x][next_y] == BOX_ON)
{
int boxon_x = (next_x - g->position.x) * 2 + g->position.x;
int boxon_y = (next_y - g->position.y) * 2 + g->position.y;
if (g->game_grid[boxon_x][boxon_y] == NONE)
{
g->game_grid[boxon_x][boxon_y] = BOX;
g->game_grid[next_x][next_y] = PLAYER_ON;
g->game_grid[g->position.x][g->position.y] = NONE;
g->position.x = next_x;
g->position.y = next_y;
g->box_goal_number--;
}
}
}
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