Created
March 8, 2017 04:11
-
-
Save bmoren/d18013179c1873c2ced7a7420b3a0f05 to your computer and use it in GitHub Desktop.
basic p5js high low with keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var currentNumber = 0 | |
var previousNumber = 0 | |
var score = 0 | |
function setup() { | |
createCanvas(windowWidth,windowHeight) | |
} | |
function draw() { | |
} | |
function keyPressed(){ | |
if(key == 'H' || key == 'L'){ | |
previousNumber = currentNumber //save the current number as the previous before getting a new one! | |
currentNumber = int( random(1,6) ) | |
}else{ | |
console.log('choose higher or lower with the h or l keys'); | |
} | |
if(key == 'H'){ | |
if(currentNumber >= previousNumber){ | |
//we won | |
score++ | |
}else{ | |
// we lost | |
score = 0 | |
} | |
} | |
if(key == 'L'){ | |
if(currentNumber <= previousNumber){ | |
//we won | |
score++ | |
}else{ | |
// we lost | |
score = 0 | |
} | |
} | |
console.log('~~~~'); | |
console.log(previousNumber); | |
console.log(currentNumber); | |
console.log(score); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment