-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grid.java
100 lines (78 loc) · 1.65 KB
/
Grid.java
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
/**
* Created by Mushra on 2017-09-10.
*/
public class Grid {
public final int MAX_WIDTH = 500; // arbitrary
public final int MAX_HEIGHT = 500; // arbitrary
public final int TILE_WIDTH = 6;
public final int TILE_HEIGHT = 6;
protected int width;
protected int height;
protected Tile[][] map;
protected int sel_x = 0;
protected int sel_y = 0;
public Grid(int width, int height) {
construct(width, height);
}
public Grid() {
construct(1, 1);
}
private void construct(int width, int height) {
setWidth(width);
setHeight(height);
map = new Tile[width][height];
}
/*
capsules
*/
public void setTile(int x, int y, Tile newTile) {
map[x][y] = newTile;
}
public Tile getTile(int x, int y) {
return map[x][y];
}
public void setWidth(int width) {
if (width > 0 && width < MAX_WIDTH) {
this.width = width;
}
}
public void setHeight(int height) {
if (height > 0 && height < MAX_HEIGHT) {
this.height = height;
}
}
public int getHeight() {
return height;
}
public int getWidth() {
return width;
}
public int getHeightInPixels() {
return height * TILE_HEIGHT;
}
public int getWidthInPixels() {
return height * TILE_WIDTH;
}
public void selLeft() {
sel_x = (sel_x + width - 1) % width;
}
public void selRight() {
sel_x = (sel_x + width + 1) % width;
}
public void selUp() {
sel_y = (sel_y + height - 1) % height;
}
public void selDown() {
sel_y = (sel_y + height + 1) % height;
}
public void setSel(int x, int y) {
sel_x = (x + width) % width;
sel_y = (y + height) % height;
}
public int getSelX() {
return sel_x;
}
public int getSelY() {
return sel_y;
}
}