Skip to content

Commit

Permalink
ex07 step 5 multiplayer done
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidouen committed Mar 24, 2024
1 parent 1f63d0e commit a2b9871
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion 07_jeu_des_allumettes/my_answer/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,29 @@ function validAnswer(matchesToRemove) {
return false;
}

function howManyPlayers() {
let players = 0;
while (players < 1) {
players = parseInt(prompt("How many players are you ?"));
if (isNaN(players)) {
alert("Error : Please a number of players");
}
else if (players < 1) {
alert("Error : at least 1 player is needed");
}
}
return players;
}

function launchGame() {
let matchesHeap = 50;
let player = 0;
let answer;
alert("Welcome to the Matches Game");
alert("The Matches Game starts with a heap of 50 matches. Each one his turn, 2 players remove between 1 to 6 matches from the heap. The one who removes the last match wins the game.");
let players = howManyPlayers();
while (matchesHeap > 0) {
if (player > 1) {
if (player >= players) {
player = 0;
}
answer = askPlayer(player + 1);
Expand Down

0 comments on commit a2b9871

Please sign in to comment.