Esempio n. 1
0
static RET_CODE on_othello_board_select(control_t *p_ctrl, u16 msg,
  u32 para1, u32 para2)
{
  BOOL ret;
  
  if (do_move_chess(&chess_board,
                    (u16)((cur_row + 1) * 10 + (cur_col + 1)),
                    (u8)(~computer_side & 3), callback))
  {
    othello_game = OTHELLO_HAPPY;
    get_chess_score(&chess_board, &WhitePoint, &BlackPoint);
    othello_update_status();
    othello_draw_background(FALSE);
    /* computer round */
    ret = computer_play(&chess_board, callback);
    get_chess_score(&chess_board, &WhitePoint, &BlackPoint);
    othello_update_status();
    othello_draw_background(FALSE);
    
    if(!ret)
    {
      game_over(&chess_board, callback);
    }
  }  

  return SUCCESS;
}
Esempio n. 2
0
void othello_initial(BOOL BOW)
{
  control_t *p_mbox, *p_info;

  p_info = ui_game_get_ctrl(ROOT_ID_OTHELLO, GAME_INFO_ID);
  p_info = ctrl_get_child_by_id(p_info, 6);

  g_iGameLevel =
    (text_get_content(p_info) == IDS_GAME_EASY) ? OTHELLO_GAME_LEVEL_PRM :
    (text_get_content(p_info) ==
     IDS_GAME_NORMAL ? OTHELLO_GAME_LEVEL_JUR : OTHELLO_GAME_LEVEL_SER);

  p_info = ctrl_get_child_by_id(p_info->p_parent, 2);

  ctrl_default_proc(p_info, MSG_LOSTFOCUS, 0, 0);
  ctrl_paint_ctrl(p_info, TRUE);
  p_mbox = ui_game_get_ctrl(ROOT_ID_OTHELLO, GAME_BOARD_ID);
  ctrl_default_proc(p_mbox, MSG_GETFOCUS, 0, 0);

  cur_col = 3;
  cur_row = 2;
  BlackPoint = 2;
  WhitePoint = 2;

  if (!BOW) //if user is white, cpu first
  {
    init_board(&chess_board, FALSE);
    cpu_color = CHESS_BLACK;
    computer_play(&chess_board, callback);
    get_chess_score(&chess_board, &WhitePoint, &BlackPoint);
    othello_game = OTHELLO_HAPPY;
  }
  else
  {
    init_board(&chess_board, TRUE);
    cpu_color = CHESS_WHITE;
    othello_game = OTHELLO_HAPPY;
  }

  othello_update_status();
  othello_draw_background(TRUE);
}
Esempio n. 3
0
static void othello_start(void)
{
	UINT8 back_saved;
	//    othello_init();
	othello_draw_background();
	update_status(Class, BlackPoint, WhitePoint);

	win_compopup_init(WIN_POPUP_TYPE_OKNO);
	win_compopup_set_frame(GAME_MSG_LEFT, GAME_MSG_TOP, GAME_MSG_WIDTH, GAME_MSG_HEIGHT);
	win_compopup_set_msg_ext(NULL, NULL, RS_GAME_MSG_DO_YOU_BLACK);
	if (win_compopup_open_ext(&back_saved) == WIN_POP_CHOICE_NO)
	{
		computer_side = CHESS_BLACK;
		/* computer round */
		computer_play(&chess_board, callback);

		get_chess_score(&chess_board, &WhitePoint, &BlackPoint);
		update_status(Class, BlackPoint, WhitePoint);
	}
}
Esempio n. 4
0
void game_over(board_type *board_ptr, othello_callback callback)
{
    u16 wscore, bscore;
    u8 winner;
    get_chess_score(board_ptr, &wscore, &bscore);
    if(computer_side == CHESS_WHITE)
    {
        if(wscore > bscore)
            winner = COMPUTER_WIN;
        else if(wscore <bscore)
            winner = USER_WIN;
        else winner = DOGFALL;
    }
    else
    {
        if(wscore > bscore)
            winner = USER_WIN;
        else if(wscore <bscore)
            winner = COMPUTER_WIN;
        else winner = DOGFALL;
    }
    callback(GAME_OVER, (u32)winner, 0);
}
Esempio n. 5
0
static PRESULT othello_key_proc(UINT32 vkey, UINT8 key_repeat_cnt, UINT8 key_status)
{
	PRESULT ret = PROC_LOOP;
	UINT8 back_saved;
	if (key_status == PAN_KEY_PRESSED)
	{
		switch (vkey)
		{
			case V_KEY_UP:
			case V_KEY_DOWN:
			case V_KEY_LEFT:
			case V_KEY_RIGHT:
				draw_cursor(cur_row, cur_col, WSTL_GAME_BACKGROUND_IDX);
				if (vkey == V_KEY_UP)
				{
					cur_row = cur_row == 0 ? 7 : cur_row - 1;
				}
				else if (vkey == V_KEY_DOWN)
				{
					cur_row = cur_row == 7 ? 0 : cur_row + 1;
				}
				else if (vkey == V_KEY_LEFT)
				{
					cur_col = cur_col == 0 ? 7 : cur_col - 1;
				}
				else if (vkey == V_KEY_RIGHT)
				{
					cur_col = cur_col == 7 ? 0 : cur_col + 1;
				}
				draw_cursor(cur_row, cur_col, WSTL_GAME_CURSOR_IDX);
				break;

			case V_KEY_ENTER:
				if (do_move_chess(&chess_board, (cur_row + 1) *10+(cur_col + 1), ~computer_side &3, callback))
				{
					draw_cursor(cur_row, cur_col, WSTL_GAME_BACKGROUND_IDX);

					get_chess_score(&chess_board, &WhitePoint, &BlackPoint);
					update_status(Class, BlackPoint, WhitePoint);

					/* computer round */
					computer_play(&chess_board, callback);

					get_chess_score(&chess_board, &WhitePoint, &BlackPoint);
					update_status(Class, BlackPoint, WhitePoint);

					draw_cursor(cur_row, cur_col, WSTL_GAME_CURSOR_IDX);
				}
				break;

			case V_KEY_MENU:
			case V_KEY_EXIT:
				win_compopup_init(WIN_POPUP_TYPE_OKNO);
				win_compopup_set_frame(GAME_MSG_LEFT, GAME_MSG_TOP, GAME_MSG_WIDTH, GAME_MSG_HEIGHT);
				win_compopup_set_msg_ext(NULL, NULL, RS_GAME_MSG_DO_YOU_QUIT);
				if (win_compopup_open_ext(&back_saved) == WIN_POP_CHOICE_YES)
				{
					othello_init();
                    OSD_ObjOpen((POBJECT_HEAD)&game_con, 0xFFFFFFFF) ;  
					/*othello_init();
					othello_draw_background();
					update_status(Class, BlackPoint, WhitePoint,TRUE);
					OSD_SetAttr((POBJECT_HEAD) &txt_start, C_ATTR_ACTIVE);
					OSD_ChangeFocus((POBJECT_HEAD) &game_con, 1,  \
						C_UPDATE_FOCUS | C_DRAW_SIGN_EVN_FLG);*/
				}
				break;
			default:
				ret = PROC_PASS;
				break;
		}
	}

	return ret;
}