Redraw only damaged portions of the board.
-Need to parse commands coming through the command entry box. This is
-so that a command like NEW can trigger a SHOW and a board update.
-
Animate robot movement.
Leave trails behind moving robots.
GdkEventButton *event)
{
grr_board_view_t *view;
- const char *dir;
- const char *robot;
+ rr_direction_t dir;
int x, y;
int robot_x, robot_y;
int dx, dy;
if (abs(dx) > abs(dy))
if (x > robot_x)
- dir = "east";
+ dir = RR_DIRECTION_EAST;
else
- dir = "west";
+ dir = RR_DIRECTION_WEST;
else
if (y > robot_y)
- dir = "south";
+ dir = RR_DIRECTION_SOUTH;
else
- dir = "north";
+ dir = RR_DIRECTION_NORTH;
- switch (view->drag_robot) {
- case RR_ROBOT_BLUE:
- robot = "blue";
- break;
- case RR_ROBOT_GREEN:
- robot = "green";
- break;
- case RR_ROBOT_RED:
- robot = "RED";
- break;
- case RR_ROBOT_YELLOW:
- robot = "YELLOW";
- break;
- default:
- return FALSE;
- }
-
- if (view->client) {
- char *move_str;
-
- grr_sprintf_alloc (&move_str, "%s %s", robot, dir);
- if (move_str == NULL)
- return FALSE;
- rr_client_move (view->client, move_str);
- free (move_str);
- }
+ if (view->client)
+ rr_client_move (view->client, view->drag_robot, dir);
return FALSE;
}
grr_game_printf (game, "\nGame state changed to: %s.",
rr_gamestate_str (notice->u.gamestate));
break;
+ case RR_NOTICE_TURN:
+ grr_game_print (game, "\nNew round!");
+ rr_board_set_goal_target (board, notice->u.target);
+ gtk_widget_queue_draw (GTK_WIDGET (game->window));
+ break;
+ case RR_NOTICE_GAMEOVER:
+ {
+ char *diagram;
+ grr_game_printf (game, "\nGame over. New game will begin now.");
+ /* XXX: Can drop this when the BOARD NOTICE is added in the server */
+ rr_client_show (game->client, &diagram);
+ rr_board_parse (board, diagram);
+ free (diagram);
+ gtk_widget_queue_draw (GTK_WIDGET (game->window));
+ }
+ break;
case RR_NOTICE_JOIN:
grr_game_printf (game, "\nUser %s has joined the game.",
notice->u.string);
notice->u.position.x, notice->u.position.y);
gtk_widget_queue_draw (GTK_WIDGET (game->window));
break;
- case RR_NOTICE_TURN:
- grr_game_print (game, "\nNew round!");
- rr_board_set_goal_target (board, notice->u.target);
- gtk_widget_queue_draw (GTK_WIDGET (game->window));
- break;
}
free (notice);
}