Commit 325492b5 authored by Line Pernille Graulund's avatar Line Pernille Graulund
Browse files

changed the distance to be negative

parent 730f2e2d
......@@ -17,7 +17,7 @@ var mt = 0 //movement time
var width
var distance
var widths = [10, 30, 50]
var distances = [150, 150, 150, 300, 300, 300, 450, 450, 450]
var distances = [-200, 150, 150, 300, -300, 300, 450, -400, 450]
var startedAtresetBox = true //trial starts at left box
var completedCombinations = [] //array including all combinations completed
var counter = -1
......
var numberOfRounds = 0
var score = 0
var clickWindowEnabled
var testIsRunning
var moleClickTime = 2
function setClickWindowEnabled(boolean) {
if (testIsRunning) {
clickWindowEnabled = boolean
console.log("clickwindow enabled: " + clickWindowEnabled)
}
}
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max))
}
function generateVerticalMolePosition() {
let verticalPosition = 1
verticalPosition *= Math.random() < 0.5 ? -1 : 1
verticalPosition *= (Math.random() * 290 + 0)
if (verticalPosition < -235) {
verticalPosition = -235
}
return verticalPosition
}
function generateHorizontalMolePosition() {
let horizontalPosition = 1
horizontalPosition *= Math.random() < 0.5 ? -1 : 1
horizontalPosition *= (Math.random() * 500 + 0)
if (horizontalPosition > 430) {
horizontalPosition = 430
}
return horizontalPosition
}
function generateMoleButtonSize() {
let sizeArray = [10, 30, 50]
return sizeArray[getRandomInt(3)]
}
function showMoleButton() {
window.setTimeout("setClickWindowEnabled(false)", moleClickTime * 1000)
moleButton.style.visibility = "visible"
moleButton.style.top = generateVerticalMolePosition() + "px"
moleButton.style.left = generateHorizontalMolePosition() + "px"
moleButton.style.padding = generateMoleButtonSize() + "px"
console.log("v pos: " + moleButton.style.top)
console.log("h pos: " + moleButton.style.left)
}
function showStartButton() {
startButton.disabled = false
startButton.style.visibility = "visible"
}
function onStartButtonClicked() {
if (numberOfRounds > 60) {
stopGame()
}
else {
document.getElementById("round").innerHTML = "Round: " + (numberOfRounds += 1)
startButton.style.visibility = "hidden"
startButton.disabled = true
timeInSeconds = Math.random() * 2 + 0.7
testIsRunning = true
setClickWindowEnabled(true)
window.setTimeout("showMoleButton()", timeInSeconds * 1000)
if (moleButton.style.visibility == "visible" && timeleft > 2) {
setClickWindowEnabled(false)
testIsRunning = false
moleButton.style.visibility = "hidden"
showStartButton()
}
}
}
function onMoleButtonClicked() {
setClickWindowEnabled(false)
testIsRunning = false
showStartButton()
moleButton.style.visibility = "hidden"
document.getElementById("score").innerHTML = "Score: " + (score += 1)
}
function stopGame() {
}
function init() {
moleButton = document.querySelector("#mole-button")
moleButton.addEventListener("click", onMoleButtonClicked)
startButton = document.querySelector("#start-button")
startButton.addEventListener("click", onStartButtonClicked)
moleButton.style.visibility = "hidden"
}
init()
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment