XNA - 骰子检查玩家是否掷出数字 6
XNA - Dice Check to see if player rolled the number 6
我正在用 c# XNA 制作 "simple game"。我有一个滚动按钮和两个玩家。
我想要发生的是,每次您按下滚动按钮时,生成的数字等于 6,同一玩家可以再次滚动。我已经尝试了所有形式的循环和 if-else 语句。
public void DiceCheck()
{
if (randomNum == 6)
{
if (playerTurn) //Intial value of bool playerTurn is equal to true: Which means player 1 turn
{
playerTurn = true; //Allow player 1 to roll again
}
else if (playerTurn == false) // Player 2 turn
{
playerTurn = false; //Allow player 2 to roll again
}
}
}
每次播放器滚动时我也有一些要添加的东西
player2turn++;
player1turn++;
当我为两个玩家插入它时,每次玩家获得 6 时,它都会将 2 添加到掷骰数。我希望它生成 6,然后让玩家点击再次掷骰。但它并没有按照我想要的方式工作。
public void GameLoop(Random dice)
{
int randomNum = 0;
int turn = 0;
while(true)
{
randomNum = dice.Next(1,7); //next turn roll
Console.WriteLine(string.Format("Player {0} rolled a {1}", turn%2 + 1, randomNum));
if(!CheckForReroll(randomNum)) // if it's a reroll don't change player's turns
{
turn++;
}
if(turn == 10) break; //made up rules to stop at turn 10 so we don't loop infinitely
}
}
public bool CheckForReroll(int randomNum)
{
return randomNum == 6;
}
我正在用 c# XNA 制作 "simple game"。我有一个滚动按钮和两个玩家。
我想要发生的是,每次您按下滚动按钮时,生成的数字等于 6,同一玩家可以再次滚动。我已经尝试了所有形式的循环和 if-else 语句。
public void DiceCheck()
{
if (randomNum == 6)
{
if (playerTurn) //Intial value of bool playerTurn is equal to true: Which means player 1 turn
{
playerTurn = true; //Allow player 1 to roll again
}
else if (playerTurn == false) // Player 2 turn
{
playerTurn = false; //Allow player 2 to roll again
}
}
}
每次播放器滚动时我也有一些要添加的东西
player2turn++;
player1turn++;
当我为两个玩家插入它时,每次玩家获得 6 时,它都会将 2 添加到掷骰数。我希望它生成 6,然后让玩家点击再次掷骰。但它并没有按照我想要的方式工作。
public void GameLoop(Random dice)
{
int randomNum = 0;
int turn = 0;
while(true)
{
randomNum = dice.Next(1,7); //next turn roll
Console.WriteLine(string.Format("Player {0} rolled a {1}", turn%2 + 1, randomNum));
if(!CheckForReroll(randomNum)) // if it's a reroll don't change player's turns
{
turn++;
}
if(turn == 10) break; //made up rules to stop at turn 10 so we don't loop infinitely
}
}
public bool CheckForReroll(int randomNum)
{
return randomNum == 6;
}