-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
51 lines (48 loc) · 1.09 KB
/
main.ts
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
// game based on https://play2048.co/
import {
checkGameOver,
checkWin,
initBoard,
moveToBottom,
moveToLeft,
moveToRight,
moveToTop,
printBoard,
setNewNumber,
} from "./utils.ts";
function checkGame(board: Array<string | number>) {
checkWin(board);
checkGameOver(board);
}
let board: Array<string | number> = initBoard(Array(16).fill(""));
printBoard(board);
console.log("moveToBottom");
board = moveToBottom(board);
checkGame(board);
board = setNewNumber(board);
printBoard(board);
console.log("moveToLeft");
board = moveToLeft(board);
checkGame(board);
board = setNewNumber(board);
printBoard(board);
console.log("moveToRight");
board = moveToRight(board);
checkGame(board);
board = setNewNumber(board);
printBoard(board);
console.log("moveToTop");
board = moveToTop(board);
checkGame(board);
board = setNewNumber(board);
printBoard(board);
console.log("moveToBottom");
board = moveToBottom(board);
checkGame(board);
board = setNewNumber(board);
printBoard(board);
console.log("moveToLeft");
board = moveToLeft(board);
checkGame(board);
board = setNewNumber(board);
printBoard(board);