-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
61 lines (50 loc) · 2.52 KB
/
script.js
File metadata and controls
61 lines (50 loc) · 2.52 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
let player1Points = parseInt(localStorage.getItem('player1Points')) || 0; // Get Player 1 points
document.getElementById('player1-points').innerText = player1Points; // Update Points display
// Apply the skin when returning from the shop
window.onload = function() {
const selectedSkin = localStorage.getItem('player1Skin');
if (selectedSkin) {
document.getElementById('player1-dice-1').style.backgroundColor = selectedSkin;
document.getElementById('player1-dice-2').style.backgroundColor = selectedSkin;
}
};
document.getElementById('roll-btn').addEventListener('click', function() {
let player1Dice1 = Math.floor(Math.random() * 6) + 1;
let player1Dice2 = Math.floor(Math.random() * 6) + 1;
let player2Dice1 = Math.floor(Math.random() * 6) + 1;
let player2Dice2 = Math.floor(Math.random() * 6) + 1;
document.getElementById('player1-dice-1').innerHTML = player1Dice1;
document.getElementById('player1-dice-2').innerHTML = player1Dice2;
document.getElementById('player2-dice-1').innerHTML = player2Dice1;
document.getElementById('player2-dice-2').innerHTML = player2Dice2;
const player1Dice1El = document.getElementById('player1-dice-1');
const player1Dice2El = document.getElementById('player1-dice-2');
const player2Dice1El = document.getElementById('player2-dice-1');
const player2Dice2El = document.getElementById('player2-dice-2');
player1Dice1El.classList.remove('rolling');
player1Dice2El.classList.remove('rolling');
player2Dice1El.classList.remove('rolling');
player2Dice2El.classList.remove('rolling');
void player1Dice1El.offsetWidth;
void player1Dice2El.offsetWidth;
void player2Dice1El.offsetWidth;
void player2Dice2El.offsetWidth;
player1Dice1El.classList.add('rolling');
player1Dice2El.classList.add('rolling');
player2Dice1El.classList.add('rolling');
player2Dice2El.classList.add('rolling');
let player1Total = player1Dice1 + player1Dice2;
let player2Total = player2Dice1 + player2Dice2;
let resultText = '';
if (player1Total > player2Total) {
resultText = 'Player 1 Wins!';
player1Points += 10; // Reward points for winning
} else if (player2Total > player1Total) {
resultText = 'Player 2 Wins!';
} else {
resultText = 'It\'s a Draw! Roll again.';
}
document.getElementById('result').innerText = resultText;
document.getElementById('player1-points').innerText = player1Points; // Update points after game
localStorage.setItem('player1Points', player1Points); // Store updated points
});