Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 90 lines (76 sloc) 2.16 kB
9f494f5 board stuffs
Andrew Tribone authored
1 class Grid {
2 List<List<GridElement>> cells;
3 HTMLCanvasElement canvas;
d4666ed background is there, and they movegit statusgit status
Andrew Tribone authored
4 HTMLImageElement img;
5 HTMLAudioElement audio;
9f494f5 board stuffs
Andrew Tribone authored
6 CanvasRenderingContext2D ctx;
7
8 Grid() {
9 cells = new List<List<GridElement>>();
10 HTMLDocument doc = window.document;
11 canvas = doc.getElementById('canvas');
12 ctx = canvas.getContext('2d');
13
d4666ed background is there, and they movegit statusgit status
Andrew Tribone authored
14 img = doc.createElement('img');
15 img.src = 'images/background.png';
16 img.onload = (e) {
17 ctx.drawImage(img, 0, 0, 750, 750);
18 };
066e8ec intro music
Andrew Tribone authored
19
9f494f5 board stuffs
Andrew Tribone authored
20 //generate map
21 for (int i = 0; i < Constants.SIZE; i++) {
22 cells.add(new List<GridElement>());
23 }
24
25 for (int i = 0; i < Constants.SIZE; i++) {
b02171e revamped
Andrew Tribone authored
26 cells[0].add(new GridElement(0, i, true, false, Constants.DOWN, false));
9f494f5 board stuffs
Andrew Tribone authored
27 }
5343b1a @iph HI
iph authored
28 print((Constants.SIZE * .8).floor());
b02171e revamped
Andrew Tribone authored
29 for (int i = 1; i < (Constants.SIZE * .8).floor(); i++) {
9f494f5 board stuffs
Andrew Tribone authored
30 for (int j = 0; j < Constants.SIZE; j++) {
b02171e revamped
Andrew Tribone authored
31 cells[i].add(new GridElement(i, j, false, false, Constants.DOWN, false));
9f494f5 board stuffs
Andrew Tribone authored
32 }
33 }
34
b02171e revamped
Andrew Tribone authored
35 for (int i = (Constants.SIZE *.8).floor(); i < Constants.SIZE; i++) {
9f494f5 board stuffs
Andrew Tribone authored
36 for (int j = 0; j < Constants.SIZE; j++) {
b02171e revamped
Andrew Tribone authored
37 cells[i].add(new GridElement(i, j, false, false, Constants.DOWN, true));
9f494f5 board stuffs
Andrew Tribone authored
38 }
39 }
40
41 //draw map
b02171e revamped
Andrew Tribone authored
42 draw();
43 }
44
45 void draw() {
d4666ed background is there, and they movegit statusgit status
Andrew Tribone authored
46 ctx.drawImage(img, 0, 0, 750, 750);
9f494f5 board stuffs
Andrew Tribone authored
47 }
48 }
49
50 class GridElement {
b02171e revamped
Andrew Tribone authored
51 final int X;
52 final int Y;
9f494f5 board stuffs
Andrew Tribone authored
53 final bool s; //start
54 final bool e; //end
55 final int direction;
56 final bool c; //castle
57 int t; //tower
58
b02171e revamped
Andrew Tribone authored
59 GridElement(int this.X, int this.Y, bool this.s, bool this.e, int this.direction, bool this.c) {
9f494f5 board stuffs
Andrew Tribone authored
60 t = Constants.TOWERLESS;
61 }
62
63 //getters
b02171e revamped
Andrew Tribone authored
64 int get x() => X;
65 int get y() => Y;
9f494f5 board stuffs
Andrew Tribone authored
66 int get tower() => t;
67 int get dir() => direction;
68 bool get start() => s;
69 bool get end() => e;
70 bool get castle() => c;
71
72 //setters
73 int set tower(int type) => t = type;
74 }
75
76 class Constants {
b02171e revamped
Andrew Tribone authored
77 static final int SIZE = 150;
9f494f5 board stuffs
Andrew Tribone authored
78 static final UP = 1;
79 static final DOWN = 2;
80 static final LEFT = 3;
81 static final RIGHT = 4;
82 static final START = 5;
83 static final END = 6;
84 static final CASTLE = 7;
85 static final TOWERLESS = 8;
86 static final LONELYTOWER = 9;
87
88 Constants() {}
89 }
Something went wrong with that request. Please try again.