-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
48 lines (38 loc) · 1.49 KB
/
script.js
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
import { verifiatePlayerCombination } from "./javascript/combinationVerification.mjs"
import { gameSettings, inputArea, tryResultPgraph, secretCombination, validateButton } from "./javascript/data.mjs"
import { displayNumberOfTries, displayTryResult } from "./javascript/display.mjs"
import { verfiatePlayerInput } from "./javascript/inputVerification.mjs"
function getPlayerCombination() {
const playerInput = inputArea.value
return playerInput
}
function combinationToArray(myString) {
const myArray = myString.split(`,`) //later remplaced with buttons so we do not worry about bad player input for now
return myArray
}
function gameTurn() {
console.log(`secret combination`, secretCombination)
let playerCombination = getPlayerCombination()
console.log(playerCombination)
playerCombination = combinationToArray(playerCombination)
console.log(playerCombination)
if (!verfiatePlayerInput(playerCombination)) {
return
}
gameSettings.playerNumberOfTries += 1
displayNumberOfTries()
if (verifiatePlayerCombination(playerCombination)) {
tryResultPgraph.innerText = `you win`
validateButton.disabled = true
console.log("you win")
return
} else if (gameSettings.playerNumberOfTries >= gameSettings.maxNumberOfTries) {
tryResultPgraph.innerText = `you lose`
validateButton.disabled = true
return
}
displayTryResult()
}
validateButton.addEventListener(`click`, ()=> {
gameTurn()
})