-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move my file out of the folder in order for the index.html to be reco…
…gnized
- Loading branch information
1 parent
2418690
commit 94b710f
Showing
14 changed files
with
840 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<link rel="stylesheet" href="style.css" /> | ||
<title>Pig Game</title> | ||
</head> | ||
<body> | ||
<main> | ||
<section class="player player--0 player--active"> | ||
<h2 class="name" id="name--0">Player 1</h2> | ||
<p class="score" id="score--0">43</p> | ||
<div class="current"> | ||
<p class="current-label">Current</p> | ||
<p class="current-score" id="current--0">0</p> | ||
</div> | ||
</section> | ||
<section class="player player--1"> | ||
<h2 class="name" id="name--1">Player 2</h2> | ||
<p class="score" id="score--1">24</p> | ||
<div class="current"> | ||
<p class="current-label">Current</p> | ||
<p class="current-score" id="current--1">0</p> | ||
</div> | ||
</section> | ||
|
||
<img src="/dice-game-main/image/dice-5.png" alt="Playing dice" class="dice" /> | ||
<button class="btn btn--new">🔄 New game</button> | ||
<button class="btn btn--roll">🎲 Roll dice</button> | ||
<button class="btn btn--hold">📥 Hold</button> | ||
</main> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
'use strict'; | ||
|
||
|
||
// Selecting elements | ||
const player0El = document.querySelector('.player--0'); | ||
const player1El = document.querySelector('.player--1'); | ||
const score0El = document.getElementById('score--0'); | ||
const score1El = document.getElementById('score--1'); | ||
const current0El = document.getElementById('current--0'); | ||
const current1El = document.getElementById('current--1'); | ||
|
||
const diceEl = document.querySelector('.dice'); | ||
const btnNew = document.querySelector('.btn--new'); | ||
const btnRoll = document.querySelector('.btn--roll'); | ||
const btnHold = document.querySelector('.btn--hold'); | ||
|
||
let scores, currentScore, activePlayer, playing; | ||
|
||
// Start conditions | ||
const init = function () { | ||
scores = [0, 0]; | ||
currentScore = 0; | ||
activePlayer = 0; | ||
playing = true; | ||
|
||
score0El.textContent = 0; | ||
score1El.textContent = 0; | ||
current0El.textContent = 0; | ||
current1El.textContent = 0; | ||
|
||
diceEl.classList.add('hidden'); | ||
player0El.classList.remove('player--winner'); | ||
player1El.classList.remove('player--winner'); | ||
player0El.classList.add('player--active'); | ||
player1El.classList.remove('player--active'); | ||
}; | ||
init(); | ||
|
||
const switchPlayer = function () { | ||
document.getElementById(`current--${activePlayer}`).textContent = 0; | ||
currentScore = 0; | ||
activePlayer = activePlayer === 0 ? 1 : 0; | ||
player0El.classList.toggle('player--active'); | ||
player1El.classList.toggle('player--active'); | ||
}; | ||
|
||
// Rolling dice functions | ||
btnRoll.addEventListener('click', function () { | ||
if (playing) { | ||
|
||
const dice = Math.trunc(Math.random() * 6) + 1; | ||
|
||
|
||
diceEl.classList.remove('dice'); | ||
diceEl.src = `dice-${dice}.png`; | ||
|
||
if (dice !== 1) { | ||
// Add dice to current score | ||
currentScore += dice; | ||
document.getElementById( | ||
`current--${activePlayer}` | ||
).textContent = currentScore; | ||
} else { | ||
// next player | ||
switchPlayer(); | ||
} | ||
} | ||
}); | ||
|
||
btnHold.addEventListener('click', function () { | ||
if (playing) { | ||
scores[activePlayer] += currentScore; | ||
|
||
document.getElementById(`score--${activePlayer}`).textContent = | ||
scores[activePlayer]; | ||
|
||
if (scores[activePlayer] >= 100) { | ||
// end game | ||
playing = false; | ||
diceEl.classList.add('hidden'); | ||
|
||
document | ||
.querySelector(`.player--${activePlayer}`) | ||
.classList.add('player--winner'); | ||
document | ||
.querySelector(`.player--${activePlayer}`) | ||
.classList.remove('player--active'); | ||
} else { | ||
// next player | ||
switchPlayer(); | ||
} | ||
} | ||
}); | ||
|
||
btnNew.addEventListener('click', init); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
'use strict'; | ||
|
||
|
||
// Selecting elements | ||
const player0El = document.querySelector('.player--0'); | ||
const player1El = document.querySelector('.player--1'); | ||
const score0El = document.getElementById('score--0'); | ||
const score1El = document.getElementById('score--1'); | ||
const current0El = document.getElementById('current--0'); | ||
const current1El = document.getElementById('current--1'); | ||
|
||
const diceEl = document.querySelector('.dice'); | ||
const btnNew = document.querySelector('.btn--new'); | ||
const btnRoll = document.querySelector('.btn--roll'); | ||
const btnHold = document.querySelector('.btn--hold'); | ||
|
||
let scores, currentScore, activePlayer, playing; | ||
|
||
// Start conditions | ||
const init = function () { | ||
scores = [0, 0]; | ||
currentScore = 0; | ||
activePlayer = 0; | ||
playing = true; | ||
|
||
score0El.textContent = 0; | ||
score1El.textContent = 0; | ||
current0El.textContent = 0; | ||
current1El.textContent = 0; | ||
|
||
diceEl.classList.add('hidden'); | ||
player0El.classList.remove('player--winner'); | ||
player1El.classList.remove('player--winner'); | ||
player0El.classList.add('player--active'); | ||
player1El.classList.remove('player--active'); | ||
}; | ||
init(); | ||
|
||
const switchPlayer = function () { | ||
document.getElementById(`current--${activePlayer}`).textContent = 0; | ||
currentScore = 0; | ||
activePlayer = activePlayer === 0 ? 1 : 0; | ||
player0El.classList.toggle('player--active'); | ||
player1El.classList.toggle('player--active'); | ||
}; | ||
|
||
// Rolling dice functions | ||
btnRoll.addEventListener('click', function () { | ||
if (playing) { | ||
|
||
const dice = Math.trunc(Math.random() * 6) + 1; | ||
|
||
|
||
diceEl.classList.remove('dice--hidden'); | ||
diceEl.src = `dice-${dice}.png`; | ||
|
||
if (dice !== 1) { | ||
// Add dice to current score | ||
currentScore += dice; | ||
document.getElementById( | ||
`current--${activePlayer}` | ||
).textContent = currentScore; | ||
} else { | ||
// next player | ||
switchPlayer(); | ||
} | ||
} | ||
}); | ||
|
||
btnHold.addEventListener('click', function () { | ||
if (playing) { | ||
scores[activePlayer] += currentScore; | ||
|
||
document.getElementById(`score--${activePlayer}`).textContent = | ||
scores[activePlayer]; | ||
|
||
if (scores[activePlayer] >= 100) { | ||
// end game | ||
playing = false; | ||
diceEl.classList.add('hidden'); | ||
|
||
document | ||
.querySelector(`.player--${activePlayer}`) | ||
.classList.add('player--winner'); | ||
document | ||
.querySelector(`.player--${activePlayer}`) | ||
.classList.remove('player--active'); | ||
} else { | ||
// next player | ||
switchPlayer(); | ||
} | ||
} | ||
}); | ||
|
||
btnNew.addEventListener('click', init); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
'use strict'; | ||
|
||
|
||
// Selecting elements | ||
const player0El = document.querySelector('.player--0'); | ||
const player1El = document.querySelector('.player--1'); | ||
const score0El = document.getElementById('score--0'); | ||
const score1El = document.getElementById('score--1'); | ||
const current0El = document.getElementById('current--0'); | ||
const current1El = document.getElementById('current--1'); | ||
|
||
const diceEl = document.querySelector('.dice'); | ||
const btnNew = document.querySelector('.btn--new'); | ||
const btnRoll = document.querySelector('.btn--roll'); | ||
const btnHold = document.querySelector('.btn--hold'); | ||
|
||
let scores, currentScore, activePlayer, playing; | ||
|
||
// Start conditions | ||
const init = function () { | ||
scores = [0, 0]; | ||
currentScore = 0; | ||
activePlayer = 0; | ||
playing = true; | ||
|
||
score0El.textContent = 0; | ||
score1El.textContent = 0; | ||
current0El.textContent = 0; | ||
current1El.textContent = 0; | ||
|
||
diceEl.classList.add('hidden'); | ||
player0El.classList.remove('player--winner'); | ||
player1El.classList.remove('player--winner'); | ||
player0El.classList.add('player--active'); | ||
player1El.classList.remove('player--active'); | ||
}; | ||
init(); | ||
|
||
const switchPlayer = function () { | ||
document.getElementById(`current--${activePlayer}`).textContent = 0; | ||
currentScore = 0; | ||
activePlayer = activePlayer === 0 ? 1 : 0; | ||
player0El.classList.toggle('player--active'); | ||
player1El.classList.toggle('player--active'); | ||
}; | ||
|
||
// Rolling dice functions | ||
btnRoll.addEventListener('click', function () { | ||
if (playing) { | ||
|
||
const dice = Math.trunc(Math.random() * 6) + 1; | ||
|
||
|
||
// diceEl.classList.remove('dice--hidden'); | ||
diceEl.src = `dice-${dice}.png`; | ||
|
||
if (dice !== 1) { | ||
// Add dice to current score | ||
currentScore += dice; | ||
document.getElementById( | ||
`current--${activePlayer}` | ||
).textContent = currentScore; | ||
} else { | ||
// next player | ||
switchPlayer(); | ||
} | ||
} | ||
}); | ||
|
||
btnHold.addEventListener('click', function () { | ||
if (playing) { | ||
scores[activePlayer] += currentScore; | ||
|
||
document.getElementById(`score--${activePlayer}`).textContent = | ||
scores[activePlayer]; | ||
|
||
if (scores[activePlayer] >= 100) { | ||
// end game | ||
playing = false; | ||
// diceEl.classList.add('hidden'); | ||
|
||
document | ||
.querySelector(`.player--${activePlayer}`) | ||
.classList.add('player--winner'); | ||
document | ||
.querySelector(`.player--${activePlayer}`) | ||
.classList.remove('player--active'); | ||
} else { | ||
// next player | ||
switchPlayer(); | ||
} | ||
} | ||
}); | ||
|
||
btnNew.addEventListener('click', init); | ||
|
Oops, something went wrong.