int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nCmdShow) { timeBeginPeriod(1); UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // TODO: 여기에 코드를 입력합니다. MSG msg; WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TCPFIGHTER)); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wcex.lpszMenuName = MAKEINTRESOURCE(IDC_TCPFIGHTER); wcex.lpszClassName = L"TCPFighter"; wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); RegisterClassEx(&wcex); hInst = hInstance; // 인스턴스 핸들을 전역 변수에 저장합니다. g_hWnd = CreateWindow(L"TCPFighter", L"TCPFighter", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL); if (!g_hWnd) { return FALSE; } ShowWindow(g_hWnd, nCmdShow); UpdateWindow(g_hWnd); //////////////////////////////////////////////////////////////////////////////// // 게임, 네트워크 초기화 //////////////////////////////////////////////////////////////////////////////// InitialGame(); InitialNetwork(&client_sock, &g_hWnd); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // 윈도우 사이즈 맞추기 /////////////////////////////////////////////////////////////////////////////////////////////////////////// SetFocus(g_hWnd); RECT WindowRect; WindowRect.top = 0; WindowRect.left = 0; WindowRect.right = 640; WindowRect.bottom = 480; AdjustWindowRectEx(&WindowRect, GetWindowStyle(g_hWnd), GetMenu(g_hWnd) != NULL, GetWindowExStyle(g_hWnd)); int iX = (GetSystemMetrics(SM_CXSCREEN) - 640) / 2; int iY = (GetSystemMetrics(SM_CYSCREEN) - 480) / 2; MoveWindow(g_hWnd, iX, iY, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, TRUE); /////////////////////////////////////////////////////////////////////////////////////////////////////////// // 기본 메시지 루프입니다. while (1) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } else { Update_Game(); } } return (int) msg.wParam; }
void Dialog::calcRead() { /*if (opAvatarPixmap.isNull()) { opAvatarPixmap.loadFromData(readWriteSocket->readAll()); sendUsername(); return; }*/ QString info; info = readWriteSocket->readAll(); qDebug() << "calcRead " << info; if (opUserName == "") { QStringList infoList2 = info.split("@"); opAvatarFileName = infoList2[0]; opUserName = infoList2[1]; opAvatarPixmap.load(opAvatarFileName); qDebug() << opAvatarFileName + " " + opUserName; prepareGameWidget(); return; } if (info == "start") { isOpBegin = true; if (isMeBegin) { isGameBegin = true; connect(timer, SIGNAL(timeout()), this, SLOT(onTimerOut())); update(); timer->start(); } return; } if (info == "requestQuit") { timer->stop(); QMessageBox::StandardButton b1 = QMessageBox::question(NULL, "Request", "对方请求退出游戏"); if (b1 == QMessageBox::Yes) { timer->start(); sendMessage("agreeQuit"); InitialGame(); //this->close(); }else { timer->start(); sendMessage("disagreeQuit"); } return; } if (info == "agreeQuit") { timer->start(); InitialGame(); //this->close(); return; } if (info == "disagreeQuit") { timer->start(); QMessageBox::about(NULL, "Result", "对方不同意退出游戏"); return; } if (info == "requestSave") { timer->stop(); QMessageBox::StandardButton b2 = QMessageBox::question(NULL, "Request", "对方请求保存残局"); if (b2 == QMessageBox::Yes) { timer->start(); QTime time = QTime::currentTime(); map->save(QString::number(time.hour()) + "_" + QString::number(time.minute()) + ".txt"); sendMessage("agreeSave"); }else { timer->start(); sendMessage("disagreeSave"); } return; } if (info == "agreeSave") { timer->start(); QTime time = QTime::currentTime(); map->save(QString::number(time.hour()) + "_" + QString::number(time.minute()) + ".txt"); return; } if (info == "disagreeSave") { timer->start(); QMessageBox::about(NULL, "Result", "对方不同意保存残局"); return; } if (info.contains("requestLoad")) { timer->stop(); QStringList list1 = info.split("#"); QMessageBox::StandardButton b3 = QMessageBox::question(NULL, "Request", "对方请求加载残局" + list1[(int)list1.size() - 1]); if (b3 == QMessageBox::Yes) { timer->start(); map->load(list1[(int)list1.size() - 1]); update(); sendMessage("agreeLoad#" + list1[(int)list1.size() - 1]); }else { timer->start(); sendMessage("disagreeLoad"); } return; } if (info == "disagreeLoad") { timer->start(); QMessageBox::about(NULL, "Result", "对方不同意加载残局"); return; } if (info.contains("agreeLoad")) { timer->start(); QStringList list2 = info.split("#"); map->load(list2[(int)list2.size() - 1]); update(); return; } if (info == "requestWithdraw") { timer->stop(); QMessageBox::StandardButton b4 = QMessageBox::question(NULL, "Request", "对方请求悔棋"); if (b4 == QMessageBox::Yes) { timer->start(); sendMessage("agreeWithdraw"); map->pop(player ^ 1); renewTime(); }else { timer->start(); sendMessage("disagreeWithdraw"); } return; } if (info == "agreeWithdraw") { timer->start(); ++withDrawTime; if (withDrawTime >= 2) { withdrawButton->setDisabled(true); } map->pop(player); if (checkNoMyChess()) { withdrawButton->setDisabled(true); } renewTime(); return; } if (info == "disagreeWithdraw") { timer->start(); QMessageBox::about(NULL, "Result", "对方不同意悔棋"); return; } QStringList infoList = info.split("_"); int x = infoList[0].toInt(); int y = infoList[1].toInt(); map->arr[x][y] = player ^ 1; map->place.push_back(QPoint(x, y)); changePlayer(); /*if (map->curPlayer == Map::Black) map->curPlayer = Map::White; else map->curPlayer = Map::Black;*/ update(); if (gameLogic->checkWin()) { gameOver(0); } }