-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grid.java
54 lines (47 loc) · 1.16 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
package round;
import java.awt.Color;
public class Grid
{
public static final Color[] COLORS = {Color.RED, Color.ORANGE,
Color.YELLOW, Color.GREEN,
Color.BLUE, Color.MAGENTA};
public static final Color DEFAULT_COLOR = Color.GRAY;
private Tile[][] tiles;
private int[] selection;
private void setTilesColor()
{
for(int tileColumn = 0; tileColumn < this.tiles[0].length; tileColumn++) // all rows have same number of columns including row index 0
{
for(int tileRow = 0; tileRow < this.tiles.length; tileRow++)
{
if(tileRow == selection[tileColumn])
{
tiles[tileRow][tileColumn] = new Tile(COLORS[tileRow]);
}
else
{
tiles[tileRow][tileColumn] = new Tile(DEFAULT_COLOR);
}
}
}
}
public Grid(int row, int column, int[] selection)
{
this.tiles = new Tile[row][column];
this.selection = selection;
setTilesColor();
}
public Tile[][] getTileColor()
{
return tiles;
}
public String toString()
{
String toString = "";
for(int index = 0; index < selection.length; index++)
{
toString += selection[index];
}
return toString;
}
}