10th Jul 2024, 9:00 AM
LegendRexMC
LegendRexMC - avatar
3 Respostas
+ 7
what i would do is have a turn counter, turn direction, and a players array. // Some pseudo-code close to JS let players = []; let currentTurn = 0; // whose turn? let turnDirection = 1; // 1 = normal, -1 = reversed init() { players.push("player", "AI"); loop(); } loop() { while(gamerunning) { processTurn(players[currentTurn]); // Next turn let nextTurn = currentTurn + dir; // Keep in bounds if (nextTurn < 0 || nextTurn >= players.length) { // Consider turn direction // backwards? last player's turn if (dir == -1) currentTurn = players.length-1; else currentTurn = 0; } else currentTurn = nextTurn; } } processTurn(player) { // Current turn will increment here AND in loop() which skips the next player's turn if (player.played == "skip") ++currentTurn; // this will negate the current direction. // 1 * -1 = -1 the turn order is reversed // -1 * -1 = 1 the turn order is normal else if (player.played == "reverse") dir *= -1; }
10th Jul 2024, 4:40 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
0
what is the issue? describe it precisely.
10th Jul 2024, 9:05 AM
Lisa
Lisa - avatar
0
It is a game called UNO, I would like to skip the next players turn when the player or computers played a skip card, and reverse the turn if a reverse card is played.
10th Jul 2024, 9:06 AM
LegendRexMC
LegendRexMC - avatar