-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9342000
commit a452ff4
Showing
2 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
export default class Snake { | ||
// 蛇的容器 | ||
snakeEl: HTMLElement; | ||
// 蛇头 | ||
headEl: HTMLElement; | ||
// 蛇身,含蛇头 | ||
bodyListEl: HTMLCollection; | ||
|
||
constructor() { | ||
this.snakeEl = document.getElementById('snake')!; | ||
this.headEl = this.snakeEl.firstElementChild as HTMLElement; | ||
this.bodyListEl = this.snakeEl.children; | ||
} | ||
|
||
get headPointer(): {x: number, y: number} { | ||
return { | ||
x: this.headEl.offsetLeft, | ||
y: this.headEl.offsetTop, | ||
} | ||
} | ||
|
||
set headPointer(pointer) { | ||
// 设置蛇头 | ||
console.log('headPointer', pointer); | ||
} | ||
|
||
// 增加蛇的长度 | ||
increaseBody() { | ||
// The insertAdjacentHTML() method inserts a text as HTML, into a specified position. | ||
this.snakeEl.insertAdjacentHTML('beforeend', '<i></i>'); | ||
} | ||
|
||
// 移动蛇身 | ||
moveBody(): void { | ||
// | ||
} | ||
|
||
// 检查是否撞到自己 | ||
checkAccident() { | ||
// | ||
} | ||
} |