⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reversi.c

📁 ucgui3.90a
💻 C
📖 第 1 页 / 共 4 页
字号:
  _AddMenuItem(hMenu, hMenuHelp,    "Help",    0, 0);
  /* Attach menu to framewin */
  FRAMEWIN_AddMenu(hWin, hMenu);
}

/*******************************************************************
*
*       _CalcBoardDimensions
*/
static void _CalcBoardDimensions(void) {
  GUI_RECT r;
  WM_GetClientRectEx(WM_GetClientWindow(_hFrame), &r);
  _CellSize  = ((r.x1 > r.y1) ? r.y1 : r.x1) >> 3;
  _BoardX0   = (r.x1 - (_CellSize << 3)) >> 1;
  _BoardY0   = (r.y1 - (_CellSize << 3)) >> 1;
}

/*******************************************************************
*
*       _InvalidateBoard
*/
static void _InvalidateBoard(void) {
  WM_InvalidateWindow(WM_GetClientWindow(_hFrame));
}

/*******************************************************************
*
*       _InvalidateCell
*/
static void _InvalidateCell(int x, int y) {
  GUI_RECT r;
  r.x0 = _BoardX0 + (x * _CellSize);
  r.y0 = _BoardY0 + (y * _CellSize);
  r.x1 = r.x0 + _CellSize - 1;
  r.y1 = r.y0 + _CellSize - 1;
  WM_InvalidateRect(WM_GetClientWindow(_hFrame), &r);
  //WM_InvalidateWindow(WM_GetClientWindow(_hFrame));
}

/*********************************************************************
*
*       _SetCapture
*/
static void _SetCapture(void) {
#if (GUI_SUPPORT_MOUSE & GUI_SUPPORT_CURSOR)
  WM_HWIN hWin;
  hWin = WM_GetClientWindow(_hFrame);
  if (WM_HasCaptured(hWin) == 0) {
    WM_SetCapture(hWin, 0);
    GUI_CURSOR_Select(&GUI_CursorCrossS);
  }
#endif
}

/*********************************************************************
*
*       _ReleaseCapture
*/
static void _ReleaseCapture(void) {
#if (GUI_SUPPORT_MOUSE & GUI_SUPPORT_CURSOR)
  WM_HWIN hWin;
  hWin = WM_GetClientWindow(_hFrame);
  if (WM_HasCaptured(hWin)) {
    WM_ReleaseCapture();
    GUI_CURSOR_Select(&GUI_CursorArrowM);
  }
#endif
}

/*******************************************************************
*
*       _GetStone
*/
static char _GetStone(int x, int y) {
  char r = 0;
  if ((x >= 0) && (y >= 0) && (x < 8) && (y < 8)) {
    r = _Board[x][y] & 0xFF;
  }
  return r;
}

/*******************************************************************
*
*       _SetStone
*/
static void _SetStone(int x, int y) {
  if ((x >= 0) && (y >= 0) && (x < 8) && (y < 8)) {
    _Board[x][y] &= 0xFF00;
    _Board[x][y] |= _ActPlayer & 0xFF;
    _InvalidateCell(x, y);
  }
}

/*******************************************************************
*
*       _IsValidMove
*/
static char _IsValidMove(int x, int y) {
  return ((_Board[x][y] >> 8) ? 1 : 0);
}

/*********************************************************************
*
*       Static code, about box
*
**********************************************************************
*/
/*******************************************************************
*
*       _cbAboutBox
*/
static void _cbAboutBox(WM_MESSAGE* pMsg) {
  WM_HWIN hWin = pMsg->hWin;
  switch (pMsg->MsgId) {
  case WM_PAINT:
    {
      char acText[16] = "V";
      strcat(acText, GUI_GetVersionString());
      GUI_SetColor(GUI_BLACK);
      GUI_SetFont(&GUI_Font10_1);
      GUI_SetTextMode(GUI_TM_TRANS);
      GUI_DrawBitmap(&_Logo, 4, 4);
      GUI_DispStringHCenterAt("Reversi V1.0", 49, 48);
      GUI_DispStringHCenterAt("emWin", 138, 38);
      GUI_DispStringHCenterAt(acText,  138, 48);
      GUI_DispStringHCenterAt("Compiled " __DATE__ " "__TIME__, 88, 68);
      GUI_DispStringHCenterAt("(c) 1998-2004 Segger", 88, 87);
      GUI_DispStringHCenterAt("Microcontroller Systeme GmbH", 88, 97);
      GUI_DispStringHCenterAt("www.segger.com", 88, 107);
      GUI_DispStringHCenterAt("Programmed by Tobias Quecke", 88, 126);
    }
    break;
  case WM_NOTIFY_PARENT:
    if (pMsg->Data.v == WM_NOTIFICATION_RELEASED) {
      GUI_EndDialog(hWin, 1);
    }
    break;
  default:
    WM_DefaultProc(pMsg);
  }
}

/*********************************************************************
*
*       _ShowAboutBox
*/
static void _ShowAboutBox(void) {
  WM_HWIN hFrame, hItem;
  /* Create framewin */
  hFrame = FRAMEWIN_CreateEx(70, 40, 180, 160, WM_HBKWIN, WM_CF_SHOW, FRAMEWIN_CF_MOVEABLE, 0, "About Reversi", &_cbAboutBox);
  FRAMEWIN_SetClientColor   (hFrame, GUI_WHITE);
  FRAMEWIN_SetFont          (hFrame, &GUI_Font10_1);
  FRAMEWIN_SetTextAlign     (hFrame, GUI_TA_HCENTER);
  /* Create dialog items */
  hItem = BUTTON_CreateEx(111, 7, 55, 18, WM_GetClientWindow(hFrame), WM_CF_SHOW, 0, GUI_ID_OK);
  BUTTON_SetText         (hItem, "Ok");
  /* Exec modal dialog */
  WM_SetFocus(hFrame);
  WM_MakeModal(hFrame);
  GUI_ExecCreatedDialog(hFrame);
  WM_SetFocus(_hFrame);
}

/*********************************************************************
*
*       Static code, message box
*
**********************************************************************
*/
/*******************************************************************
*
*       _cbMessageBox
*/
static void _cbMessageBox(WM_MESSAGE* pMsg) {
  WM_HWIN hWin = pMsg->hWin;
  switch (pMsg->MsgId) {
  case WM_NOTIFY_PARENT:
    if (pMsg->Data.v == WM_NOTIFICATION_RELEASED) {
      int Id = WM_GetId(pMsg->hWinSrc);
      GUI_EndDialog(hWin, (Id == GUI_ID_OK) ? 1 : 0);
    }
    break;
  default:
    WM_DefaultProc(pMsg);
  }
}

/*********************************************************************
*
*       _ShowMessageBox
*/
static int _ShowMessageBox(const char* pTitle, const char* pText, int YesNo) {
  WM_HWIN hFrame, hClient, hBut;
  int r;
  /* Create framewin */
  hFrame = FRAMEWIN_CreateEx(65, 75, 190, 90, WM_HBKWIN, WM_CF_SHOW, FRAMEWIN_CF_MOVEABLE, 0, pTitle, &_cbMessageBox);
  FRAMEWIN_SetClientColor   (hFrame, GUI_WHITE);
  FRAMEWIN_SetFont          (hFrame, &GUI_Font10_1);
  FRAMEWIN_SetTextAlign     (hFrame, GUI_TA_HCENTER);
  /* Create dialog items */
  hClient = WM_GetClientWindow(hFrame);
  TEXT_CreateEx(10, 7, 170, 30, hClient, WM_CF_SHOW, GUI_TA_HCENTER, 0, pText);
  if (YesNo) {
    hBut = BUTTON_CreateEx(97, 45, 55, 18, hClient, WM_CF_SHOW, 0, GUI_ID_CANCEL);
    BUTTON_SetText        (hBut, "No");
    hBut = BUTTON_CreateEx(32, 45, 55, 18, hClient, WM_CF_SHOW, 0, GUI_ID_OK);
    BUTTON_SetText        (hBut, "Yes");
  } else {
    hBut = BUTTON_CreateEx(64, 45, 55, 18, hClient, WM_CF_SHOW, 0, GUI_ID_OK);
    BUTTON_SetText        (hBut, "Ok");
  }
  /* Exec modal dialog */
  WM_SetFocus(hFrame);
  WM_MakeModal(hFrame);
  r = GUI_ExecCreatedDialog(hFrame);
  WM_SetFocus(_hFrame);
  return r;
}

/*********************************************************************
*
*       Static code, dialog settings
*
**********************************************************************
*/
/*******************************************************************
*
*       _cbDialogSettings
*/
static void _cbDialogSettings(WM_MESSAGE* pMsg) {
  WM_HWIN hWin = pMsg->hWin;
  switch (pMsg->MsgId) {
  case WM_NOTIFY_PARENT:
    if (pMsg->Data.v == WM_NOTIFICATION_RELEASED) {
      WM_HWIN hItem = pMsg->hWinSrc;
      switch (WM_GetId(hItem)) {
      case GUI_ID_OK:
        GUI_EndDialog(hWin, 1);
        break;
      case GUI_ID_CHECK0:
        _ShowPossibleMoves = CHECKBOX_GetState(hItem);
        _InvalidateBoard();
        break;
      }
    }
    break;
  default:
    WM_DefaultProc(pMsg);
  }
}

/*********************************************************************
*
*       _ShowDialogSettings
*/
static void _ShowDialogSettings(void) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -