簡體   English   中英

我的井字游戲有問題嗎?

[英]I'm having trouble with tic tac toe?

如何不允許用戶輸入兩次相同的舉動? 例如,玩家X輸入1,然后玩家O輸入1,或者X在下一回合再次輸入1。 如何使他們重新輸入有效輸入? 我的密碼

使用數據結構(例如數組或向量)存儲已經進行的移動。 如果用戶嘗試輸入已進行的移動,請重新提示他們:

void getMove()
{
//Get move input from user through something like std::cin
    if (hasBeenPlayed()) //If the move (ex: 1) is already in the array or vector
    {
    getMove();
    }
    else
    {
    playedMoves.push_back(move); // Add the move to the vector (or an array)
    //Compute the move that was entered here
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM