xxxxxxxxxx
230
var kee
var khee
var ex = 0
var trys = 0
var button
var beenhere = 0
var tiemr = 0
var highscore = 0
var prevtime = 0
var see = 0
var transp = 255
var win = 0
// Some variables probably do nothing, I dont really know...
function setup() {
frameRate(60)
//for higher end computers we need to set the frame rate to 60 because the time counter really depends on the frame rate, though I will update that in a coming update
beenhere = getItem('beenhere')
beenhere++
storeItem('beenhere', beenhere)
if(beenhere < 2){
alert("Hello, welcome to the Letter Guesser Game! Your goal is to try to find the letter by tapping on letters on the keyboard. Click the blue area to start")
storeItem('tiem', 10000)
}
else if(beenhere>1){
alert("Welcome Back!😊")
}
//counts how many times you have been here so it doesnt show you instrctions every time
createCanvas(400, 400);
ex = floor(random(65, 90))
//chooses where the line will be, 65 is a's key code, 90 is z's key code
background(3, 169, 244)
stroke(0, 255, 0)
line(ex, 0, ex, 400)
//creates the line
strokeWeight(0.1)
stroke(0)
const help = `Hint: ${ex}`
text(help, 100, 10)
//tells you the key code for the current round
button = createButton('INSTRUCTIONS');
button.position(272, 10);
button.mousePressed(alrt)
//button to show instructions
button = createButton('CLEAR');
button.position(272, 40);
button.mousePressed(clr)
//button to show instructions
button = createButton('Reset variable: beenhere');
button.position(221, 400);
button.mousePressed(rest)
//button to reset the 'beenhere' counter
button = createButton('Reset variable: tiem');
button.position(221, 422);
button.mousePressed(highrest)
//button to reset high score
button = createButton('Show hint');
button.position(272, 30);
button.mousePressed(seee)
//shows hint
}
function highrest(){
tiemr = 10000
storeItem('tiem', tiemr)
//note that the high score when resetted is not 0 because the high score saver requires the current round time to be faster than the current hihg score. It it was 0 then we couldn't beat it
}
function rest(){
beenhere = beenhere - beenhere
storeItem('beenhere', beenhere)
//code for resetting 'beenhere' counter
}
function alrt(){
alert("How to play! Your goal is to try to find the letter by tapping on letters on the keyboard")
//alert that pops up when you click the INTRuCTIONS button
}
function strttiemr(){
tiemr = round(frameCount/60, 2)
return tiemr
//timer (please check if I used reurn correctly :)
}
function seee(){
see++
//sets transparency of rectangle to 0
}
function rectngle(){
noStroke()
fill(0, 0, 255, transp)
rect(100, 0, 50, 15)
fill(0)
//creates rectangle over hint text box
}
function keyPressed(){
trys++
//counts how many tries you have taken
kee = keyCode
//creates data for line() to draw a line
khee = key
//tells you the correct key when you win
line(kee, 0, kee, 400)
//draws a line
}
function clr(){
clear()
}
//-----------------------------------------
function maingame(){
strttiemr()
//initiates timer
rectngle()
if (see <= 0){
transp = 255
rectngle()
}
else if (see >= 1){
transp = 0
rectngle()
}
console.log(transp)
//for debug
strokeWeight(0.1)
prevtime = getItem('prevtime')
highscore = getItem('tiem')
//gets the variables stored on local browser
const hightxt = `Highscore: ${highscore} seconds!`
const hightxt2 = `Start playing to get a high score!`
const prev = `Your previous time was ${prevtime} seconds!`
text(prev, 100, 110)
//displays your previous time
if (highscore == 10000){
text (hightxt2, 100, 30)
//if the high score is 10000 (was reset or have never played before) it tells you to start playing to get a high score
}
else if (highscore != 10000){
text (hightxt, 100, 30)
//if there is a high score saved on browser then it shows you that
}
strokeWeight(1)
if (kee == ex){
//a.k.a when you win
const wintxt = `You won! The letter was ${khee}.`
const tries = `It took you ${trys} guess and ${tiemr} seconds to guess it
correctly. Refresh to try again.`
const tries2 = `It took you ${trys} guesses and ${tiemr} seconds to guess it
correctly. Refresh to try again.`
text(wintxt, 100, 50)
//shows you correct letter
if (trys == 1){
text(tries, 100, 75)
//shows 'guess' because it took you one guess
storeItem('prevtime', tiemr)
//saves as previous time
if (tiemr < highscore){
storeItem('tiem', tiemr)
//saves highscore
}
}
else if (trys != 1){
text(tries2, 100, 75)
//showes guesses because you took more than one guess
storeItem('prevtime', tiemr)
//shows as previous time
if (tiemr < highscore){
storeItem('tiem', tiemr)
//saves highscore
}
}
return tiemr
//check if I did this correctly :)
win++
//tells computer that you won
}
}
//this is pretty much the whole game squished into one function :)
function draw() {
if (win == 0){
maingame()
}
else if (win > 1){
win = win - win
maingame()
}
}