mirror of
https://github.com/FranP-code/Tic-Tac-Toe-Game.git
synced 2025-10-12 23:52:39 +00:00
Local storage for play again done
This commit is contained in:
@@ -2,12 +2,23 @@ import accessToCombinations from "./accessToCombinations.js"
|
||||
import checkVictory from "./checkVictory.js"
|
||||
import victoryActions from "./victoryActions.js"
|
||||
|
||||
export default function gameLogic(checkInputsResult) {
|
||||
export default function gameLogic(checkInputsResult, replay) {
|
||||
|
||||
function Player(position) {
|
||||
|
||||
this.name = checkInputsResult[position][0].value
|
||||
this.symbol = checkInputsResult[position][1].value
|
||||
console.log(replay)
|
||||
|
||||
if (replay) {
|
||||
|
||||
this.name = checkInputsResult[position].name
|
||||
this.symbol = checkInputsResult[position].symbol
|
||||
|
||||
} else {
|
||||
|
||||
this.name = checkInputsResult[position][0].value
|
||||
this.symbol = checkInputsResult[position][1].value
|
||||
}
|
||||
|
||||
this.markedBoxes = []
|
||||
}
|
||||
|
||||
@@ -42,10 +53,15 @@ export default function gameLogic(checkInputsResult) {
|
||||
const checkVictoryResult = checkVictory(combinations, actualPlayer.markedBoxes)
|
||||
console.log(checkVictoryResult)
|
||||
|
||||
const data = {
|
||||
|
||||
player1: player1,
|
||||
player2: player2,
|
||||
}
|
||||
|
||||
if (checkVictoryResult[0] === 'WIN') {
|
||||
|
||||
victoryActions(checkVictoryResult[1], actualPlayer.name)
|
||||
|
||||
victoryActions(checkVictoryResult[1], actualPlayer.name, data)
|
||||
}
|
||||
|
||||
if (players.indexOf(actualPlayer) === 0) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export default function victoryActions(combination, playerName) {
|
||||
export default function victoryActions(combination, playerName, data) {
|
||||
|
||||
const stylesActions = (() => {
|
||||
|
||||
@@ -39,10 +39,16 @@ export default function victoryActions(combination, playerName) {
|
||||
|
||||
game.classList.add('animate__fadeOutDown')
|
||||
|
||||
console.log(data)
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
game.classList.add('hidden')
|
||||
|
||||
|
||||
localStorage.setItem('data', JSON.stringify(data))
|
||||
|
||||
location.reload();
|
||||
|
||||
}, 1000)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user