static void menu_select_callback(MenuLayer *menu_layer, MenuIndex *cell_index, void *data) {
  if (cell_index->row == GAME_INDEX) {
    chess_init();
  } else if (cell_index->row == INSTRUCTION_INDEX) {
    text_init(CHESS);
  } else if (cell_index->row == SETTINGS_INDEX) {
    settings_init();
  } else if (cell_index->row == ABOUT_INDEX) {
    text_init(ABOUT);
  }
}
Esempio n. 2
0
void handle_init(AppContextRef ctx) {
  (void)ctx;

  window_init(&window, "Chess");
  window_stack_push(&window, true /* Animated */);
  window_set_background_color(&window, GColorWhite);

  resource_init_current_app(&APP_RESOURCES);

  bmp_init_container(RESOURCE_ID_IMAGE_BOARD, &img_board_container);
  bmp_init_container(RESOURCE_ID_IMAGE_SELECT, &img_select);
  bmp_init_container(RESOURCE_ID_IMAGE_B_PAWN, &img_b_pawn);
  bmp_init_container(RESOURCE_ID_IMAGE_B_BISHOP, &img_b_bishop);
  bmp_init_container(RESOURCE_ID_IMAGE_B_KNIGHT, &img_b_knight);
  bmp_init_container(RESOURCE_ID_IMAGE_B_QUEEN, &img_b_queen);
  bmp_init_container(RESOURCE_ID_IMAGE_B_KING, &img_b_king);
  bmp_init_container(RESOURCE_ID_IMAGE_B_ROOK, &img_b_rook);
  bmp_init_container(RESOURCE_ID_IMAGE_W_PAWN, &img_w_pawn);
  bmp_init_container(RESOURCE_ID_IMAGE_W_BISHOP, &img_w_bishop);
  bmp_init_container(RESOURCE_ID_IMAGE_W_KNIGHT, &img_w_knight);
  bmp_init_container(RESOURCE_ID_IMAGE_W_QUEEN, &img_w_queen);
  bmp_init_container(RESOURCE_ID_IMAGE_W_KING, &img_w_king);
  bmp_init_container(RESOURCE_ID_IMAGE_W_ROOK, &img_w_rook);
  
  layer_add_child(&window.layer, &img_board_container.layer.layer);

  layer_init(&input_layer, GRect(0,0, 144, 168));
  input_layer.update_proc = input_layer_update_callback;
  layer_add_child(&img_board_container.layer.layer, &input_layer);

  layer_init(&board_layer, GRect(0,0, 144, 168));
  board_layer.update_proc = board_layer_update_callback;
  layer_add_child(&input_layer, &board_layer);

  text_layer_init(&strBoardLayer, GRect(0, 0, 144/* width */, 11/* height */));
  text_layer_set_text_color(&strBoardLayer, GColorWhite);
  text_layer_set_background_color(&strBoardLayer, GColorBlack);
  //text_layer_set_font(&strBoardLayer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD));
  layer_add_child(&img_board_container.layer.layer, &strBoardLayer.layer);
  // Attach our desired button functionality
  window_set_click_config_provider(&window, (ClickConfigProvider) click_config_provider);

  board = chess_init();
  print_board();
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
    struct chess_t chess;
    SDL_Event event;
    int ret;

    ret = chess_init(&chess);
    ERRP(ret != TRUE, goto ERR1, 1, "sdl_init failed!\n");

    if (argc > 1)
        chess.eth_id = atoi(argv[1]);

    ret = chess_menu(&chess);
    ERRP(ret == EXIT, goto ERR2, 0);

    while (1)
    {
        if (SDL_WaitEvent(&event)) 
        {
            if (event.type == SDL_QUIT)
                break;
            if (event.type == SDL_KEYDOWN && 
                key_handle(&chess, event.key.keysym.sym) == EXIT)
                break;
            if (event.type == SDL_MOUSEBUTTONDOWN && 
                event.button.button == SDL_BUTTON_LEFT &&
                !pos_op(event.button.x, event.button.y, &chess) &&
                chess_handle(&chess) == EXIT)
                break;
        }
    }

ERR2:
    chess_exit(&chess);
ERR1:
    return 0;
}