Skip to content

Instantly share code, notes, and snippets.

@cxytomo
Last active December 16, 2015 02:29
Show Gist options
  • Save cxytomo/5362756 to your computer and use it in GitHub Desktop.
Save cxytomo/5362756 to your computer and use it in GitHub Desktop.
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