LRESULT OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { switch(LOWORD(wParam)) { case ID_FILE_MENU: mode = 0; EnableMenuItem(GetMenu(hWnd), ID_TICTACTOE_X, MF_DISABLED); EnableMenuItem(GetMenu(hWnd), ID_TICTACTOE_O, MF_DISABLED); SetColors(); game.Reset(true); InvalidateRect(hWnd, NULL, true); break; case ID_FILE_EXIT: DestroyWindow(hWnd); break; case ID_NEW_PVP: mode = 1; EnableMenuItem(GetMenu(hWnd), ID_TICTACTOE_X, MF_ENABLED); EnableMenuItem(GetMenu(hWnd), ID_TICTACTOE_O, MF_ENABLED); SetColors(); game.AI(false); game.Reset(true); InvalidateRect(hWnd, NULL, true); break; case ID_NEW_PVAI: mode = 1; EnableMenuItem(GetMenu(hWnd), ID_COLORS_TICTACTOE, MF_ENABLED); EnableMenuItem(GetMenu(hWnd), ID_TICTACTOE_O, MF_ENABLED); SetColors(); game.AI(true); game.Reset(true); InvalidateRect(hWnd, NULL, true); break; case ID_LINESIZE_SMALL: width = 1.5f; InvalidateRect(hWnd, NULL, true); break; case ID_LINESIZE_MEDIUM: width = 3.5f; InvalidateRect(hWnd, NULL, true); break; case ID_LINESIZE_LARGE: width = 5.5f; InvalidateRect(hWnd, NULL, true); break; case ID_FLIP: if (mode == 1) { game.Cheater(0); cheats |= 8; InvalidateRect(hWnd, NULL, true); } break; case ID_ULT: if (mode == 1) { game.Cheater(1); cheats |= 16; InvalidateRect(hWnd, NULL, true); } break; case ID_FORGET: if (mode == 1) { game.Cheater(2); cheats |= 32; InvalidateRect(hWnd, NULL, true); } break; case ID_COLORS_BACKGROUND: { CHOOSECOLOR cc; ZeroMemory(&cc, sizeof(CHOOSECOLOR)); cc.lStructSize = sizeof(CHOOSECOLOR); cc.hwndOwner = hWnd; cc.Flags = CC_RGBINIT; cc.lpCustColors = clrarrCustom; // Invoke the Color Selection dialog. if(ChooseColorW(&cc)) { // NOTE: The selected color is stored in the cc.rgbResult variable. //col = D2D1::ColorF(cc.rgbResult); col[Background] = D2D1::ColorF(GetRValue(cc.rgbResult)/255.0f, GetGValue(cc.rgbResult)/255.0f, GetBValue(cc.rgbResult)/255.0f); // Repaint the screen. GradientChange(); InvalidateRect(hWnd, NULL, TRUE); } } break; case ID_GRIDLINES_COLOR: { CHOOSECOLOR cc; ZeroMemory(&cc, sizeof(CHOOSECOLOR)); cc.lStructSize = sizeof(CHOOSECOLOR); cc.hwndOwner = hWnd; cc.Flags = CC_RGBINIT; cc.lpCustColors = clrarrCustom; // Invoke the Color Selection dialog. if(ChooseColorW(&cc)) { // NOTE: The selected color is stored in the cc.rgbResult variable. //col = D2D1::ColorF(cc.rgbResult); col[Grid] = D2D1::ColorF(GetRValue(cc.rgbResult)/255.0f, GetGValue(cc.rgbResult)/255.0f, GetBValue(cc.rgbResult)/255.0f); // Repaint the screen. GradientChange(); InvalidateRect(hWnd, NULL, TRUE); } } break; case ID_COLORS_ALLRANDOM: { for(int x = 0; x < 6; x++) { float r = rand()%256/255.0f, g = rand()%256/255.0f, b = rand()%256/255.0f; col[x] = D2D1::ColorF(r, g, b); } // Repaint the screen. GradientChange(); InvalidateRect(hWnd, NULL, TRUE); } break; case ID_COLORS_FONT: { CHOOSECOLOR cc; ZeroMemory(&cc, sizeof(CHOOSECOLOR)); cc.lStructSize = sizeof(CHOOSECOLOR); cc.hwndOwner = hWnd; cc.Flags = CC_RGBINIT; cc.lpCustColors = clrarrCustom; // Invoke the Color Selection dialog. if(ChooseColorW(&cc)) { // NOTE: The selected color is stored in the cc.rgbResult variable. //col = D2D1::ColorF(cc.rgbResult); col[Font] = D2D1::ColorF(GetRValue(cc.rgbResult)/255.0f, GetGValue(cc.rgbResult)/255.0f, GetBValue(cc.rgbResult)/255.0f); // Repaint the screen. GradientChange(); InvalidateRect(hWnd, NULL, TRUE); } } break; case ID_TICTACTOE_X: { CHOOSECOLOR cc; ZeroMemory(&cc, sizeof(CHOOSECOLOR)); cc.lStructSize = sizeof(CHOOSECOLOR); cc.hwndOwner = hWnd; cc.Flags = CC_RGBINIT; cc.lpCustColors = clrarrCustom; // Invoke the Color Selection dialog. if(ChooseColorW(&cc)) { // NOTE: The selected color is stored in the cc.rgbResult variable. //col = D2D1::ColorF(cc.rgbResult); col[Xmark] = D2D1::ColorF(GetRValue(cc.rgbResult)/255.0f, GetGValue(cc.rgbResult)/255.0f, GetBValue(cc.rgbResult)/255.0f); // Repaint the screen. GradientChange(); InvalidateRect(hWnd, NULL, TRUE); } } break; case ID_TICTACTOE_O: { CHOOSECOLOR cc; ZeroMemory(&cc, sizeof(CHOOSECOLOR)); cc.lStructSize = sizeof(CHOOSECOLOR); cc.hwndOwner = hWnd; cc.Flags = CC_RGBINIT; cc.lpCustColors = clrarrCustom; // Invoke the Color Selection dialog. if(ChooseColorW(&cc)) { // NOTE: The selected color is stored in the cc.rgbResult variable. //col = D2D1::ColorF(cc.rgbResult); col[Omark] = D2D1::ColorF(GetRValue(cc.rgbResult)/255.0f, GetGValue(cc.rgbResult)/255.0f, GetBValue(cc.rgbResult)/255.0f); // Repaint the screen. GradientChange(); InvalidateRect(hWnd, NULL, TRUE); } } break; default: MessageBox(HWND_DESKTOP, std::to_wstring(LOWORD(wParam)).c_str(), L"Menu, not handled", MB_OK); break; } return 0; }
LRESULT OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(wParam); ptMouse.x = GET_X_LPARAM(lParam); ptMouse.y = GET_Y_LPARAM(lParam); #pragma region MenuLM if(mode == 0) { if(ptMouse.x >=300 && ptMouse.x < 500 && ptMouse.y > 125 && ptMouse.y < 575) { if(ptMouse.y > 125 && ptMouse.y < 175) { //TicTacToe mode = 1; EnableMenuItem(GetMenu(hWnd), ID_TICTACTOE_X, MF_ENABLED); EnableMenuItem(GetMenu(hWnd), ID_TICTACTOE_O, MF_ENABLED); SetColors(); game.AI(false); game.Reset(true); ptMouse.x = NULL; ptMouse.y = NULL; InvalidateRect(hWnd, NULL, true); } else if(ptMouse.y > 225 && ptMouse.y < 275) { //HangMan mode = 2; SetColors(); ptMouse.x = NULL; ptMouse.y = NULL; InvalidateRect(hWnd, NULL, true); } else if(ptMouse.y > 325 && ptMouse.y < 375) { // } else if(ptMouse.y > 425 && ptMouse.y < 475) { //Options mode = 4; SetColors(); ptMouse.x = NULL; ptMouse.y = NULL; InvalidateRect(hWnd, NULL, true); } else if(ptMouse.y > 525 && ptMouse.y < 575) { //Exit DestroyWindow(hWnd); } } } #pragma endregion #pragma region TicTacToeLM if (mode == 1) { short gridPosX = -1, gridPosY = -1; if(ptMouse.x >=100 && ptMouse.x < 700 && ptMouse.y > 100 && ptMouse.y < 700) { if(ptMouse.x > 100 && ptMouse.x < 300) gridPosX = 0; else if(ptMouse.x > 300 && ptMouse.x < 500) gridPosX = 1; else gridPosX = 2; if(ptMouse.y > 100 && ptMouse.y < 300) gridPosY = 0; else if(ptMouse.y > 300 && ptMouse.y < 500) gridPosY = 1; else gridPosY = 2; } if(game.CheckGrid(gridPosX, gridPosY)) { game.DrawMark(); InvalidateRect(hWnd, NULL, false); if(WinnerCheck(hWnd) == 0) { if(game.AITurn()) SetCursor(cur[0]); InvalidateRect(hWnd, NULL, false); WinnerCheck(hWnd); } } } #pragma endregion #pragma region OptionLM if(mode == 4) { if(ptMouse.x >=300 && ptMouse.x < 500 && ptMouse.y > 125 && ptMouse.y < 575) { if(ptMouse.y > 125 && ptMouse.y < 175) { //Instructions mode = 11; ptMouse.x = NULL; ptMouse.y = NULL; InvalidateRect(hWnd, NULL, true); } else if(ptMouse.y > 225 && ptMouse.y < 275) { //Cheats mode = 12; ptMouse.x = NULL; ptMouse.y = NULL; InvalidateRect(hWnd, NULL, true); } else if(ptMouse.y > 325 && ptMouse.y < 375) { //Credit mode = 13; ptMouse.x = NULL; ptMouse.y = NULL; InvalidateRect(hWnd, NULL, true); } else if(ptMouse.y > 425 && ptMouse.y < 475) { mode = 0; SetColors(); ptMouse.x = NULL; ptMouse.y = NULL; InvalidateRect(hWnd, NULL, true); //Back } } } #pragma endregion #pragma region WinnerLM if(mode == 99) { if(ptMouse.x >=100 && ptMouse.x < 750 && ptMouse.y > 600 && ptMouse.y < 700) { if(ptMouse.x < 350) { //Yes mode = 1; SetCursor(cur[0]); Reset(hWnd); } else if(ptMouse.x > 500) { //No/Exit DestroyWindow(hWnd); } } } #pragma endregion return 0; }