forked from att14/OSGCC---TD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
board.dart
89 lines (76 loc) · 2.11 KB
/
board.dart
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
class Grid {
List<List<GridElement>> cells;
HTMLCanvasElement canvas;
HTMLImageElement img;
HTMLAudioElement audio;
CanvasRenderingContext2D ctx;
Grid() {
cells = new List<List<GridElement>>();
HTMLDocument doc = window.document;
canvas = doc.getElementById('canvas');
ctx = canvas.getContext('2d');
img = doc.createElement('img');
img.src = 'images/background.png';
img.onload = (e) {
ctx.drawImage(img, 0, 0, 750, 750);
};
//generate map
for (int i = 0; i < Constants.SIZE; i++) {
cells.add(new List<GridElement>());
}
for (int i = 0; i < Constants.SIZE; i++) {
cells[0].add(new GridElement(0, i, true, false, Constants.DOWN, false));
}
print((Constants.SIZE * .8).floor());
for (int i = 1; i < (Constants.SIZE * .8).floor(); i++) {
for (int j = 0; j < Constants.SIZE; j++) {
cells[i].add(new GridElement(i, j, false, false, Constants.DOWN, false));
}
}
for (int i = (Constants.SIZE *.8).floor(); i < Constants.SIZE; i++) {
for (int j = 0; j < Constants.SIZE; j++) {
cells[i].add(new GridElement(i, j, false, false, Constants.DOWN, true));
}
}
//draw map
draw();
}
void draw() {
ctx.drawImage(img, 0, 0, 750, 750);
}
}
class GridElement {
final int X;
final int Y;
final bool s; //start
final bool e; //end
final int direction;
final bool c; //castle
int t; //tower
GridElement(int this.X, int this.Y, bool this.s, bool this.e, int this.direction, bool this.c) {
t = Constants.TOWERLESS;
}
//getters
int get x() => X;
int get y() => Y;
int get tower() => t;
int get dir() => direction;
bool get start() => s;
bool get end() => e;
bool get castle() => c;
//setters
int set tower(int type) => t = type;
}
class Constants {
static final int SIZE = 150;
static final UP = 1;
static final DOWN = 2;
static final LEFT = 3;
static final RIGHT = 4;
static final START = 5;
static final END = 6;
static final CASTLE = 7;
static final TOWERLESS = 8;
static final LONELYTOWER = 9;
Constants() {}
}