Java 在纸牌游戏中,玩家总是少收一张牌?
我正试图做一个纸牌游戏,但当我发牌时,每个玩家总是比他们应该得到的少一张。例如,如果我有4名玩家,他们每人将得到12张而不是13张牌。 这是我的密码Java 在纸牌游戏中,玩家总是少收一张牌?,java,Java,我正试图做一个纸牌游戏,但当我发牌时,每个玩家总是比他们应该得到的少一张。例如,如果我有4名玩家,他们每人将得到12张而不是13张牌。 这是我的密码 for (int j = 0; j < 52; j=j + numberOfPlayers){ for (int i=0; i < numberOfPlayers; i++){ playerspiles[i].bottom(deck[x]); } } for(int j=0;j
for (int j = 0; j < 52; j=j + numberOfPlayers){
for (int i=0; i < numberOfPlayers; i++){
playerspiles[i].bottom(deck[x]);
}
}
for(int j=0;j<52;j=j+numberOfPlayers){
for(int i=0;i
使用更好的方法:
for(int j=0;j<52;j++){
playerspiles[j%numOfPlayers].addToBottom(deck[j]);
}
对于(int j=0;j使用更好的方法:
for(int j=0;j<52;j++){
playerspiles[j%numOfPlayers].addToBottom(deck[j]);
}
for(int j=0;j你在发牌,而不是玩家
// First recipient
int playerId = 0;
// Deal from the deck, until you run out of cards.
for (int i = 0; i < 52; i++)
{
playerspiles[playerId].addToBottom(deck[i]);
// Next recipient (playerId is between 0 and numberOfPlayers-1)
playerId = (playerId + 1) % numberOfPlayers;
}
// Print each player's hand
for (int p = 0; p < numberOfPlayers; p++)
{
PrintHand(playerspiles[p]);
}
//第一个收件人
int playerId=0;
//从牌组开始交易,直到你的牌用完。
对于(int i=0;i<52;i++)
{
playerspiles[playerId].addToBottom(甲板[i]);
//下一个收件人(playerId介于0和numberOfPlayers-1之间)
playerId=(playerId+1)%numberOfPlayers;
}
//打印每个玩家的手牌
对于(int p=0;p
你在发牌,而不是玩家
// First recipient
int playerId = 0;
// Deal from the deck, until you run out of cards.
for (int i = 0; i < 52; i++)
{
playerspiles[playerId].addToBottom(deck[i]);
// Next recipient (playerId is between 0 and numberOfPlayers-1)
playerId = (playerId + 1) % numberOfPlayers;
}
// Print each player's hand
for (int p = 0; p < numberOfPlayers; p++)
{
PrintHand(playerspiles[p]);
}
//第一个收件人
int playerId=0;
//从牌组开始交易,直到你的牌用完。
对于(int i=0;i<52;i++)
{
playerspiles[playerId].addToBottom(甲板[i]);
//下一个收件人(playerId介于0和numberOfPlayers-1之间)
playerId=(playerId+1)%numberOfPlayers;
}
//打印每个玩家的手牌
对于(int p=0;p
这很好用,但请你解释一下你是如何得出这个结论的好吗?谢谢你的高谈阔论!我理解模运算符的作用。我只是有点不知所措,它可以用一行代码来替换我的所有代码!这很好用,但你介意解释一下你是如何得出这个结论的吗?th谢谢你的夸奖!我理解模运算符的作用,我只是有点不知所措,它能用一行替换我的所有代码!你的编辑没有意义;j`.`现在增加
2*numoplayers``了。你的编辑没有意义;j`.`现在增加
2*numoplayers`。