void one_player(char **grid, int line, int col) { int token; int i; i = who_begin(); while (++i < line * col) { if (i == 0) display(grid); i % 2 == 1 ? (token = ai(grid, col)) : (token = get_token(ft_strlen(grid[0]) + 1, 'X')); if (token > -1) { grid = place_token(grid, token, i); display(grid); if (test_win(grid, token) == 1) { victory(grid, token); return ; } } else i--; } ft_putendl("\n\nMatch nul\n"); }
void on_attack(int pos) { int x; int y; y = pos / 8; x = pos % 8; if (GAME.navy_positions[y][x] >= '1' && GAME.navy_positions[y][x] <= '8') { GAME.navy_positions[y][x] = 'x'; on_attack_hit(pos, 0); send_packet(CS_ATTACK_HIT, pos); } else { if (GAME.navy_positions[y][x] != 'x') GAME.navy_positions[y][x] = 'o'; on_attack_miss(pos, 0); send_packet(CS_ATTACK_MISS, pos); } test_win(); player_turn(); }
static gboolean piece_button_press (GooCanvasItem *item, GooCanvasItem *target, GdkEventButton *event, gpointer data) { GooCanvas *canvas; GooCanvasItem **board; GooCanvasItem *text; int num, pos, newpos; int x, y; double dx = 0.0, dy = 0.0; int move; canvas = goo_canvas_item_get_canvas (item); board = g_object_get_data (G_OBJECT (canvas), "board"); num = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "piece_num")); pos = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "piece_pos")); text = g_object_get_data (G_OBJECT (item), "text"); #if 0 g_print ("In piece_event pos: %i,%i num: %i\n", pos % 4, pos / 4, num + 1); #endif y = pos / 4; x = pos % 4; move = TRUE; if ((y > 0) && (board[(y - 1) * 4 + x] == NULL)) { dx = 0.0; dy = -1.0; y--; } else if ((y < 3) && (board[(y + 1) * 4 + x] == NULL)) { dx = 0.0; dy = 1.0; y++; } else if ((x > 0) && (board[y * 4 + x - 1] == NULL)) { dx = -1.0; dy = 0.0; x--; } else if ((x < 3) && (board[y * 4 + x + 1] == NULL)) { dx = 1.0; dy = 0.0; x++; } else move = FALSE; if (move) { newpos = y * 4 + x; board[pos] = NULL; board[newpos] = item; g_object_set_data (G_OBJECT (item), "piece_pos", GINT_TO_POINTER (newpos)); goo_canvas_item_translate (item, dx * PIECE_SIZE, dy * PIECE_SIZE); test_win (board); } return FALSE; }
static gint piece_event (MateCanvasItem *item, GdkEvent *event, gpointer data) { MateCanvas *canvas; MateCanvasItem **board; MateCanvasItem *text; int pos, newpos; int x, y; double dx = 0.0, dy = 0.0; int move; canvas = item->canvas; board = g_object_get_data (G_OBJECT (canvas), "board"); pos = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "piece_pos")); text = g_object_get_data (G_OBJECT (item), "text"); switch (event->type) { case GDK_ENTER_NOTIFY: mate_canvas_item_set (text, "fill_color", "white", NULL); break; case GDK_LEAVE_NOTIFY: mate_canvas_item_set (text, "fill_color", "black", NULL); break; case GDK_BUTTON_PRESS: y = pos / 4; x = pos % 4; move = TRUE; if ((y > 0) && (board[(y - 1) * 4 + x] == NULL)) { dx = 0.0; dy = -1.0; y--; } else if ((y < 3) && (board[(y + 1) * 4 + x] == NULL)) { dx = 0.0; dy = 1.0; y++; } else if ((x > 0) && (board[y * 4 + x - 1] == NULL)) { dx = -1.0; dy = 0.0; x--; } else if ((x < 3) && (board[y * 4 + x + 1] == NULL)) { dx = 1.0; dy = 0.0; x++; } else move = FALSE; if (move) { newpos = y * 4 + x; board[pos] = NULL; board[newpos] = item; g_object_set_data (G_OBJECT (item), "piece_pos", GINT_TO_POINTER (newpos)); mate_canvas_item_move (item, dx * PIECE_SIZE, dy * PIECE_SIZE); test_win (board); } break; default: break; } return FALSE; }