mirror of
https://github.com/FranP-code/Tic-Tac-Toe-Game.git
synced 2025-10-12 23:52:39 +00:00
Added some style logic
This commit is contained in:
6
script/game-functions/addStartButtonFunctionality.js
Normal file
6
script/game-functions/addStartButtonFunctionality.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export default function addStartButtonFunctionality(game) {
|
||||
|
||||
const button = document.getElementById('start')
|
||||
|
||||
button.addEventListener('click', game)
|
||||
}
|
||||
47
script/game-functions/checkInputs.js
Normal file
47
script/game-functions/checkInputs.js
Normal file
@@ -0,0 +1,47 @@
|
||||
export default function checkInputs() {
|
||||
|
||||
const player1 = document.getElementsByClassName('player player-1')[0]
|
||||
const player2 = document.getElementsByClassName('player player-2')[0]
|
||||
|
||||
const inputsPlayer1 = [player1.children[0], player1.children[1].children[1]]
|
||||
const inputsPlayer2 = [player2.children[0], player2.children[1].children[0]]
|
||||
|
||||
const inputsEmptys = []
|
||||
|
||||
inputsPlayer1.forEach(input => {
|
||||
|
||||
if (input.value === '') {
|
||||
|
||||
inputsEmptys.push(' ' + input.className + ' (player 1)')
|
||||
}
|
||||
})
|
||||
|
||||
inputsPlayer2.forEach(input => {
|
||||
|
||||
if (input.value === '') {
|
||||
|
||||
inputsEmptys.push(' ' + input.className + ' (player 2)')
|
||||
}
|
||||
})
|
||||
|
||||
if (inputsEmptys.length) {
|
||||
|
||||
alert('Please fill the inputs: ' + inputsEmptys)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
if (inputsPlayer1[0].value === inputsPlayer2[0].value) {
|
||||
|
||||
alert('Same usernames')
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
if (inputsPlayer1[1].value === inputsPlayer2[1].value) {
|
||||
|
||||
alert('Same symbol')
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
12
script/game-functions/hidePlayerSelection.js
Normal file
12
script/game-functions/hidePlayerSelection.js
Normal file
@@ -0,0 +1,12 @@
|
||||
export default function hidePlayerSelection() {
|
||||
|
||||
const playerSelection = document.getElementsByClassName('player-selection')[0]
|
||||
|
||||
playerSelection.classList.add('animate__fadeOutDown')
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
playerSelection.classList.add('hidden')
|
||||
|
||||
}, 1000)
|
||||
}
|
||||
11
script/game-functions/showTicTacToe.js
Normal file
11
script/game-functions/showTicTacToe.js
Normal file
@@ -0,0 +1,11 @@
|
||||
export default function showTicTacToe() {
|
||||
|
||||
const game = document.getElementsByClassName('game')[0]
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
game.classList.remove('hidden')
|
||||
game.classList.add('animate__fadeInDown')
|
||||
|
||||
}, 1000);
|
||||
}
|
||||
Reference in New Issue
Block a user