0
UNO code: how to make Skip & Reverse?
https://sololearn.com/compiler-playground/WiOfI8saLSC5/?ref=app
3 Antworten
+ 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;
}
0
what is the issue? describe it precisely.
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.