【问题标题】:wxWidgets: How to make a gui without passing control to it?wxWidgets:如何在不传递控制权的情况下制作 gui?
【发布时间】:2013-11-28 00:54:16
【问题描述】:

我做了一个简单的 score4 游戏。这是一个项目,所以我做了一个 CLI IO 系统。

想在未来升级,我在一个类中将整个 IO 接口(移动选择、板显示)做了一堆虚函数。所以我只是通过使用 iostream 实现这些功能来制作 CLI 接口。我像这样初始化这个接口:

IOInterface *ii = new IOConsoleInterface();

现在我想制作游戏的 wxWidgets 界面并使用 -gui 开关运行它。我很容易地制作了框架,但是现在我想最终连接各个部分,当我初始化 GUI 时,它会进入无限循环并且不会返回到 Score4 游戏循环。

游戏循环调用 ii 函数,因此我不需要 wxWidgets 中的控件。我希望它只是在那里,并按照游戏循环的命令去做。

提前谢谢你

编辑:Score4 不是 wx 应用程序。我只是想对它应用一些 wxGUI 类。

Edit2:游戏循环代码:

“ii”是InputInterface,一个接受信息的对象 喜欢移动和重玩答案

“oi”是OutpuInterface,一个绘制棋盘和 告诉玩家轮到他了

void Mechanics::gameLoop(){

bool newGame = true;
int gameCounter = 0;

while(newGame){

    short choice = 0;
    short turn;
    gameCounter++;

    currentPlayer = decideStart(gameCounter);
    board.clear();
    oi->refreshTable(board, p1,p2); 


    for (turn = 1; turn <= ROWS*COLS; turn++){

        oi->playerPrompt(currentPlayer);

        do{
            if (currentPlayer->isAI == 0)
                choice = ii->getPlayersMove(currentPlayer);
            else{
                GameInstance gi = exportGameInstance();
                choice = currentPlayer->chooseMove(gi);     // AI's movement
            }

        } while (!(board.checkMoveValidity(choice)));   //breaks when move is valid--> when condition is >0

        board.move(choice,currentPlayer);

        oi->moveAnimation(choice,currentPlayer);

        oi->refreshTable(board, p1,p2); 

        if (board.winConditionCheck(currentPlayer))
            break;

        changeCurrentPlayer();
    }

    if (turn > ROWS*COLS)       //draw
        oi->draw_conclusion();
    else
        oi->win_loss_conclusion(true,currentPlayer);


    newGame = ii->newGamePrompt();
}

    delete ii;
    delete oi;
                    // GAME ENDS HERE

}

【问题讨论】:

    标签: c++ user-interface wxwidgets


    【解决方案1】:

    您需要在 GUI 应用程序中运行事件循环,没有(合理的)解决方法。因此,虽然您可以在不进入事件循环的情况下使用例如初始化 wxWidgets wxEntryStart(),你还是需要稍后再运行。

    如果您想同时拥有控制台和 GUI 界面,最好在这两种情况下都运行事件循环,除非您在前一种情况下运行自己的事件循环,在后一种情况下运行 wx 一个。

    【讨论】:

    • 有一个(可能是不合理的)方法来解决它……将主机游戏的事件循环移动到一个单独的线程中,并使用一个套接字或一对管道(或等)来允许游戏逻辑的事件循环向 GUI 事件循环发送消息(并从其接收消息),就像现在使用标准输入和标准输出一样。这不是最简单的事情,但可能。
    猜你喜欢
    • 1970-01-01
    • 2021-03-08
    • 1970-01-01
    • 2019-09-10
    • 1970-01-01
    • 1970-01-01
    • 2018-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多