-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
35 lines (35 loc) · 1.37 KB
/
script.js
File metadata and controls
35 lines (35 loc) · 1.37 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
console.log("Hello world!");
var CellType;
(function (CellType) {
CellType[CellType["Empty"] = 0] = "Empty";
CellType[CellType["SnakeBody"] = 1] = "SnakeBody";
CellType[CellType["Food"] = 2] = "Food";
})(CellType || (CellType = {}));
var Render = /** @class */ (function () {
function Render(context, cellSizePx, fieldSize) {
this.context = context;
this.cellSizePx = cellSizePx;
this.fieldSize = fieldSize;
}
Render.prototype.drawEmpty = function (coord) {
this.context.fillStyle = "gray";
this.context.fillRect(coord.x * this.cellSizePx, coord.y * this.cellSizePx, this.cellSizePx, this.cellSizePx);
};
Render.prototype.drawSnake = function (coord) {
this.context.fillStyle = "green";
this.context.fillRect(coord.x * this.cellSizePx, coord.y * this.cellSizePx, this.cellSizePx, this.cellSizePx);
};
Render.prototype.drawFood = function (coord) {
this.context.fillStyle = "yellow";
this.context.fillRect(coord.x * this.cellSizePx, coord.y * this.cellSizePx, this.cellSizePx, this.cellSizePx);
};
return Render;
}());
var canvas = document.getElementById("field");
var ctx = canvas.getContext("2d");
if (ctx) {
var randy = new Render(ctx, 20, { height: 10, width: 10 });
randy.drawEmpty({ x: 0, y: 0 });
randy.drawSnake({ x: 1, y: 1 });
randy.drawFood({ x: 0, y: 1 });
}