Skip to content

Commit

Permalink
Change line color from black to playerColor
Browse files Browse the repository at this point in the history
  • Loading branch information
adithya321 committed Jun 22, 2016
1 parent c1fdb37 commit 4e8b216
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
24 changes: 18 additions & 6 deletions app/src/main/java/com/zduo/dotsandboxes/model/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class Game extends Observable {
private int width;
private int height;
private Player[][] occupied;
private boolean[][] horizontalLines;
private boolean[][] verticalLines;
private int[][] horizontalLines;
private int[][] verticalLines;
private Line latestLine;

public Game(int width, int height, Player[] players) {
Expand All @@ -18,8 +18,8 @@ public Game(int width, int height, Player[] players) {
this.players = players;

occupied = new Player[height][width];
horizontalLines = new boolean[height + 1][width];
verticalLines = new boolean[height][width + 1];
horizontalLines = new int[height + 1][width];
verticalLines = new int[height][width + 1];

addPlayersToGame(players);
currentPlayerIndex = 0;
Expand Down Expand Up @@ -76,6 +76,18 @@ public boolean isLineOccupied(Direction direction, int row, int column) {
}

public boolean isLineOccupied(Line line) {
switch (line.direction()) {
case HORIZONTAL:
return (horizontalLines[line.row()][line.column()] == 1
|| horizontalLines[line.row()][line.column()] == 2);
case VERTICAL:
return (verticalLines[line.row()][line.column()] == 1
|| verticalLines[line.row()][line.column()] == 2);
}
throw new IllegalArgumentException(line.direction().toString());
}

public int getLineOccupier(Line line) {
switch (line.direction()) {
case HORIZONTAL:
return horizontalLines[line.row()][line.column()];
Expand Down Expand Up @@ -111,10 +123,10 @@ private boolean tryToOccupyBox(Line move) {
private void setLineOccupied(Line line) {
switch (line.direction()) {
case HORIZONTAL:
horizontalLines[line.row()][line.column()] = true;
horizontalLines[line.row()][line.column()] = currentPlayerIndex + 1;
break;
case VERTICAL:
verticalLines[line.row()][line.column()] = true;
verticalLines[line.row()][line.column()] = currentPlayerIndex + 1;
break;
}
}
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/zduo/dotsandboxes/view/GameView.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ protected void onDraw(Canvas canvas) {
if (horizontal.equals(game.getLatestLine())) {
paint.setColor(0xFFFF7700);
} else if (game.isLineOccupied(horizontal)) {
paint.setColor(0xFF000000);
if (game.getLineOccupier(horizontal) == 1)
paint.setColor(playerColors[0]);
else
paint.setColor(playerColors[1]);
} else {
paint.setColor(0xFFFFFFFF);
}
Expand All @@ -103,7 +106,10 @@ protected void onDraw(Canvas canvas) {
if (vertical.equals(game.getLatestLine())) {
paint.setColor(0xFFFF7700);
} else if (game.isLineOccupied(vertical)) {
paint.setColor(0xFF000000);
if (game.getLineOccupier(vertical) == 1)
paint.setColor(playerColors[0]);
else
paint.setColor(playerColors[1]);
} else {
paint.setColor(0xFFFFFFFF);
}
Expand Down

0 comments on commit 4e8b216

Please sign in to comment.