Last active
December 16, 2015 02:29
-
-
Save cxytomo/5362756 to your computer and use it in GitHub Desktop.
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
function keyPressed(e){ | |
if(!game && guess>0){ | |
var keyPressed = String.fromCharCode(e.keyCode)//获得按下的键的值 | |
, keyPressedIndex; | |
keyPressed = keyPressed.toLowerCase(); | |
lettersGuessed.push(keyPressed); | |
keyPressedIndex = letters.indexOf(keyPressed); | |
if(keyPressedIndex >= 0){ | |
guess = guess - 1; | |
if(keyPressedIndex === index) { | |
game = true;//用户获胜,game的值为true | |
LowerOrHigher = "You win!"; | |
letterToGArray.push(letterToGuess); | |
} else { | |
if(guess > 0) { | |
if(keyPressedIndex > index) { | |
LowerOrHigher = "Lower"; | |
} | |
if(keyPressedIndex < index) { | |
LowerOrHigher = "Higher"; | |
} | |
} | |
if(guess == 0 && game == false) { | |
letterToGArray.push(letterToGuess); | |
LowerOrHigher = "game over!"; | |
} | |
} | |
} else{ | |
LowerOrHigher = "That is not a letter"; | |
if(guess == 0) { | |
letterToGArray.push(letterToGuess); | |
} | |
} | |
} | |
canv.height = "300";//重新绘制 | |
drawScreen(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment