我似乎找不到能具体回答我问题的东西。我正在寻找解决我的问题的方法。Connect4Player和player似乎只是要求第一个玩家放下,然后第二个玩家退出,但是第一个if语句不再正确,所以它继续要求第二个玩家删除。我使用eclipse的mac,虽然游戏是为ASCII字符集编程。
display();
int hold;
int hold2 = 0;
int charsPlaced = 0;
bool gamewon = false;
char player = 15;
string r;
while (!gamewon)
{
if (hold2 != -1)
{
if (player == 15)
{
cout << ax << " what column would you like to drop in?";
player = 178;
}
else
{
cout << bx << " what column would you like to drop in?";
player = 176;
}
}发布于 2014-06-10 18:10:42
您需要在每次动作之后切换玩家的回合。如果P1采取了一个操作,您需要更新“转向”,以便下次在代码循环时向P2请求循环。然后,在您完成了需要为P2做的事情之后,您需要更新“转身”,以便下次循环时将请求P1操作。
下面是一种通过使用enum对代码进行处理的不同方法。您可以使用bool类型变量,它是false表示P1,true表示P2,或者int是1或2,但是从outisde中很难理解。
// omitted code
enum PlayerTurn { ePlayer1 = 0, ePlayer2 };
// omitted code
PlayerTurn plTurn = ePlayer1;
while (!gamewon)
{
if (pTurn == ePlayer1)
{
cout << ax << " what column would you like to drop in?";
// TODO: stuff to do for Player #1
}
else
{
cout << bx << " what column would you like to drop in?";
// TODO: stuff to do for Player #2
}
// TODO: decide if game has been won, mechanics etc.
// move to the next player without overflowing the 2 possible values (0 and 1)
plTurn = (plTurn + 1) % 2;
}然后,在您的display()函数上,您可以显示任何您想要的ASCII字符。
https://stackoverflow.com/questions/24144043
复制相似问题