wxWidgets:如何制作一个没有控制权的gui?

时间:2013-11-14 20:10:11

标签: c++ user-interface wxwidgets

我做了一个简单的得分4游戏。这是一个项目,所以我制作了一个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

}

1 个答案:

答案 0 :(得分:0)

您需要在GUI应用程序中运行事件循环,没有(合理的)方法。因此,虽然您可以初始化wxWidgets而无需使用例如输入事件循环wxEntryStart(),您仍然需要稍后运行它。

如果你想同时拥有控制台和GUI接口,那么最好是在两种情况下运行事件循环,除非你在前一种情况下运行自己的事件循环,而在后一种情况下运行一次。

相关问题