-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
61 lines (54 loc) · 1.92 KB
/
Copy pathindex.ts
File metadata and controls
61 lines (54 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { SETTINGS } from "./Settings"
import { Board } from "./Board"
import { Travel } from "./Travel"
import { ValuesBoard } from "./ValuesBoard"
import { StartGame } from "./StartGame"
import { timeout } from "./functions"
import { MovingObjects } from "./MovingObjects"
console.table(SETTINGS.board);
type Position = { i: number, j: number }
let board: Board;
let travel: Travel;
let valuesBoard: ValuesBoard;
let startGame: StartGame;
let movingObjects: MovingObjects;
let keyup: (e: KeyboardEvent) => void;
let keydown: (e: KeyboardEvent) => void;
const gameStart = async () => {
startGame = new StartGame();
await timeout(5000)
valuesBoard = new ValuesBoard();
board = new Board();
movingObjects = new MovingObjects();
keydown = (e: KeyboardEvent) => {
//is being held
document.removeEventListener("keydown", keydown)
travel = new Travel(e);
document.addEventListener("keyup", keyup)
}
keyup = (e: KeyboardEvent) => {
document.removeEventListener("keyup", keyup)
travel.isBeingHeld = false
// console.log(travel.checkTime());
document.addEventListener("keydown", keydown)
}
document.addEventListener("keydown", keydown)
}
window.onload = async () => {
const startGameFunction = async (e: KeyboardEvent) => {
if (e.key == "Enter") {
const moveLegendDiv = document.getElementById("moveLegend") as HTMLElement
moveLegendDiv.style.display = "none"
gameStart()
window.removeEventListener("keydown", startGameFunction)
}
}
window.addEventListener("keydown", startGameFunction)
}
const changeTravel = (newTravel: Travel) => {
travel = newTravel
}
const changeMovingObjects = (newMovingObjects: MovingObjects) => {
movingObjects = newMovingObjects
}
export { board, travel, valuesBoard, movingObjects, Position, changeTravel, keydown, keyup, gameStart,changeMovingObjects }