-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.js
102 lines (87 loc) · 2.09 KB
/
game.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
let font;
const randomSeed = Math.random();
let gameBoard = new Board(); // Uses 'Tile'
let virtualBoard = new Board(); // Uses 'Virtual Tile'
function preload() {
font = loadFont('assets/Montserrat-ExtraBold.ttf');
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
function setup() {
createCanvas(windowWidth, windowHeight);
noStroke();
textFont(font);
rectMode(CENTER);
textAlign(CENTER, CENTER);
spawnRandomTile(gameBoard);
spawnRandomTile(gameBoard);
}
function draw() {
background(20);
drawBase();
drawTiles();
drawVisualization();
}
// Draw base. And show score of gameBoard.
function drawBase() {
push();
translate((width + (factor * (1 - matSize))) / 2, (height + (factor * (1 - matSize))) / 2);
fill(30);
for (let i = 0; i < matSize; i++) {
for (let j = 0; j < matSize; j++) {
square(i * factor, j * factor, factor * 0.95, factor * 0.95, roundedCorner);
}
}
pop();
}
// Drawing tiles on gameBoard.
function drawTiles() {
push();
translate((width + (factor * (1 - matSize))) / 2, (height + (factor * (1 - matSize))) / 2);
for (let i = 0; i < matSize; i++) {
for (let j = 0; j < matSize; j++) {
if (gameBoard.matrix[i][j]) {
gameBoard.matrix[i][j].draw();
}
}
}
pop();
}
function drawVisualization() {
push();
fill(255);
textSize(50);
translate(width / 2, 50);
text('2048 AI', 0, 0);
pop();
push();
fill(170);
textSize(25);
translate(width / 2, 135);
text('REWARDED POINTS : ' + rewardedPoints.toFixed(2), 0, 0);
pop();
push();
fill(255);
textSize(30);
translate(width / 2, 190);
text('SCORE : ' + gameBoard.score, 0, 0);
pop();
push();
fill(170);
textSize(25);
push();
translate(width / 2, height - 180);
text('MAX DEPTH : ' + maxDepth, 0, 0);
pop();
push();
translate(width / 2, height - 120);
text('TARGETED TILES : ' + targetTile1 + ' , ' + targetTile2, 0, 0);
pop();
push();
fill(255);
translate(width / 2, height - 50);
text('@smitbarmase', 0, 0);
pop();
pop();
}