修复开始时立即结束的bug

master
fantasticbin 2 years ago
parent 9c1e2c0597
commit 7ff8021d5f

@ -49,6 +49,7 @@ class GameController
{
const horizontal = ["ArrowLeft", "Left", "ArrowRight", "Right"];
const vertical = ["ArrowUp", "Up", "ArrowDown", "Down"];
const beginBan = ["ArrowUp", "Up", "ArrowLeft", "Left"];
// 防止水平调头
if (horizontal.includes(this.lastKeyDown) && horizontal.includes(event.key)) {
@ -60,6 +61,11 @@ class GameController
return;
}
// 防止游戏开始即结束
if (this.snake.nowDirection === "" && beginBan.includes(event.key)) {
return;
}
// 设置当前蛇的行走方向
this.snake.nowDirection = event.key;
// 记录此次键盘操作

@ -78,6 +78,14 @@ class Snake
this.direction = value;
}
/**
*
*/
get nowDirection() : string
{
return this.direction
}
/**
*
*/

Loading…
Cancel
Save