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