-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (33 loc) · 1.34 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
$(document).ready(function () {
// Get references to the game container and dice roll result elements
const gameContainer = $("#game-container");
const diceRollResult = $("#dice-roll-result");
// Create a new GameBoard instance with 100 squares and set up dice rolling display
const gameBoard = new GameBoard(gameContainer, 100, diceRollResult);
// Retrieve the game mode from the URL parameters, default to "singlePlayer" if not provided
const urlParams = new URLSearchParams(window.location.search);
const gameMode = urlParams.get("mode") || "singlePlayer";
setupGame(gameBoard, gameMode);
$("#onePlayerBtn, #playerVsPlayerBtn").click(function () {
gameBoard.diceRoller.performRoll();
});
// Function to set up the game based on the game mode
function setupGame(board, mode) {
addCatsBasedOnGameMode(board, mode);
if (mode === "computerVScomputer") {
board.runComputerPlayer();
}
}
// Function to add cats based on the game mode
function addCatsBasedOnGameMode(board, mode) {
if (mode === "playerVsPlayer") {
board.addCatToBoard("blue", 1);
board.addCatToBoard("grey", 2);
} else if (mode === "onePlayer") {
board.addCatToBoard("purple", 1);
} else if (mode === "computerVScomputer") {
board.addCatToBoard("orange", 1);
board.addCatToBoard("black", 2);
}
}
});