mirror of
https://github.com/FranP-code/Tic-Tac-Toe-Game.git
synced 2025-10-12 23:52:39 +00:00
Victory actions done
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
export default function checkVictory(combinations, boxes) {
|
||||
|
||||
const boxesSorted = boxes.sort()
|
||||
|
||||
const result = []
|
||||
|
||||
combinations.forEach(combination => {
|
||||
|
||||
if (boxesSorted[0] === combination[0] && boxesSorted[1] === combination[1] && boxesSorted[2] === combination[2]) {
|
||||
if (boxes.includes(combination[0]) && boxes.includes(combination[1]) && boxes.includes(combination[2])) {
|
||||
|
||||
alert('Win')
|
||||
console.log('WIN')
|
||||
result.push('WIN')
|
||||
result.push(combination)
|
||||
}
|
||||
});
|
||||
|
||||
return result
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import accessToCombinations from "./accessToCombinations.js"
|
||||
import checkVictory from "./checkVictory.js"
|
||||
import victoryActions from "./victoryActions.js"
|
||||
|
||||
export default function gameLogic(checkInputsResult) {
|
||||
|
||||
@@ -38,7 +39,14 @@ export default function gameLogic(checkInputsResult) {
|
||||
|
||||
actualPlayer.markedBoxes.push(box.id)
|
||||
|
||||
checkVictory(combinations, actualPlayer.markedBoxes)
|
||||
const checkVictoryResult = checkVictory(combinations, actualPlayer.markedBoxes)
|
||||
console.log(checkVictoryResult)
|
||||
|
||||
if (checkVictoryResult[0] === 'WIN') {
|
||||
|
||||
victoryActions(checkVictoryResult[1], actualPlayer.name)
|
||||
|
||||
}
|
||||
|
||||
if (players.indexOf(actualPlayer) === 0) {
|
||||
|
||||
|
||||
48
script/game-functions/victoryActions.js
Normal file
48
script/game-functions/victoryActions.js
Normal file
@@ -0,0 +1,48 @@
|
||||
export default function victoryActions(combination, playerName) {
|
||||
|
||||
const stylesActions = (() => {
|
||||
|
||||
let victoryMessage = document.getElementsByClassName('victory-message')[0]
|
||||
victoryMessage.classList.remove('hidden')
|
||||
victoryMessage.classList.add('animate__fadeInDown')
|
||||
|
||||
let victoryBackground = document.getElementsByClassName('background-winner-div')[0]
|
||||
victoryBackground.classList.add('show')
|
||||
|
||||
let victoryName = document.getElementById('victory-name')
|
||||
victoryName.innerText = playerName
|
||||
|
||||
let game = document.getElementsByClassName('tic-tac-toe')[0]
|
||||
game.classList.add('completed')
|
||||
|
||||
combination.forEach(element => {
|
||||
|
||||
const box = document.getElementById(element)
|
||||
|
||||
box.classList.add('winner-box')
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
box.classList.add('black-letters')
|
||||
|
||||
}, 350);
|
||||
});
|
||||
})()
|
||||
|
||||
const button = document.getElementById('play-again-button')
|
||||
|
||||
button.addEventListener('click', (e) => {
|
||||
|
||||
e.preventDefault()
|
||||
|
||||
const game = document.getElementsByClassName('game')[0]
|
||||
|
||||
game.classList.add('animate__fadeOutDown')
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
game.classList.add('hidden')
|
||||
|
||||
}, 1000)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user