hWnd = $hWnd; $ctrl->newGame(); echo "海贼王 · 斗地主 已启动(Win32 / TypePHP)\n"; echo "提示:拖拽手牌选牌,底部按钮出牌/不出/提示/技能/托管,右上角切换音效。\n"; while (true) { // 1) 处理所有待处理消息 while (true) { $m = win_peek_message(); if (\count($m) === 0) { break; } $type = $m[0] ?? MSG_OTHER; if ($type === MSG_MOUSE_DOWN) { $ctrl->onMouse((object) ['x' => $m[1], 'y' => $m[2], 'down' => 1, 'up' => 0, 'held' => 0]); } elseif ($type === MSG_MOUSE_UP) { $ctrl->onMouse((object) ['x' => $m[1], 'y' => $m[2], 'down' => 0, 'up' => 1, 'held' => 0]); } elseif ($type === MSG_MOUSE_MOVE) { $ctrl->onMouse((object) ['x' => $m[1], 'y' => $m[2], 'down' => 0, 'up' => 0, 'held' => $m[3]]); } elseif ($type === MSG_KEY_DOWN) { $ctrl->onKey((int) $m[1]); } // MSG_OTHER (例如 WM_PAINT) 已在 WndProc 中 ValidateRect,此处忽略 } if (win_quit_requested()) { break; } // 2) 触发到期的定时器(AI 走子 / 叫分 / 托管自动出牌) $ctrl->tick(); // 3) 渲染当前帧(双缓冲,整窗重绘) $ctrl->render(); // 4) 简单节流到 ~60 FPS \usleep(16000); } Sound::instance()->unload(); echo "游戏结束,bye!\n"; }