-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
59 lines (44 loc) · 1.6 KB
/
main.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
"use strict"
$(function () {
var army = new Army();
$("#game").addClass("clicked");
$("#start").click(function () {
army.addedUnits.forEach(function (unit) {
unit.ui = army.ui;
});
army.ui.startGame();
});
$(".item").click(function () {
army.ui.showItemMenu(this.id);
});
$("body").on("click", "canvas", function (clicked) {
army.clickedX = clicked.offsetX;
army.clickedY = clicked.offsetY;
army.ui.showCellMenu(clicked);
});
$("body").on("mouseenter", ".units", function () {
army.ui.showHoverMenu($(this).attr("class"), this.id);
});
$("body").on("mouseenter", ".abilities", function () {
army.ui.showHoverMenu($(this).attr("class"), this.id);
});
$("body").on("mouseenter", ".spells", function () {
army.ui.showHoverMenu($(this).attr("class"), this.id);
});
$("body").on("click", ".units", function () {
var x = parseInt(army.clickedX / army.field.cellSize),
y = parseInt(army.clickedY / army.field.cellSize);
var index = army.field.convertToIndex(x, y);
var unit = army.factory.units[this.id]();
var image = army.factory.images[this.id]();
image.setCoordinates(x, y);
army.ui.addImageOfUnit(image);
army.field.addUnit(unit, index);
army.addedUnits.add(unit);
$("#addUnitMenu").css({
"visibility": "hidden",
"opacity": 0,
"transition-delay": "visibility 0s linear 0.1s, opacity 0.2s linear"
});
});
});