Skip to content

Commit c2b5140

Browse files
committed
Added "Last Move Highlight"
1 parent 32f4570 commit c2b5140

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

game/src/spaghetti/game/Board.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public Point copy() {
3939
protected final BoardController[] controllers = new BoardController[2];
4040
protected boolean turn = false;
4141
protected int moveCount = 0;
42+
protected Pair<Integer, Integer> lastMove = null;
4243
protected BoardState currentState = BoardState.PRE_START;
4344

4445
public Board(int width, int height) {
@@ -77,6 +78,10 @@ public int getMoveCount() {
7778
return moveCount;
7879
}
7980

81+
public Pair<Integer, Integer> getLastMove() {
82+
return lastMove;
83+
}
84+
8085
public boolean getTurn() {
8186
return turn;
8287
}
@@ -183,6 +188,7 @@ public void start(BoardListener startHandler, BoardController blue, BoardControl
183188
}
184189

185190
private void privateStart(BoardController blue, BoardController red) {
191+
lastMove = null;
186192
controllers[0] = blue;
187193
controllers[1] = red;
188194
if (!blue.isStartHandler()) blue.setSide(false);
@@ -216,6 +222,7 @@ public Move generatePreMove(Random rand) {
216222

217223
public void play(Move move, BoardListener player) {
218224
moveCount++;
225+
lastMove = new Pair<>(move.row, move.col);
219226
tiles[move.row][move.col].type = move.t;
220227

221228
Position[] pos4 = new Position[4];

swing/src/spaghetti/gui/swing/GraphicalBoard.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package spaghetti.gui.swing;
22

33
import spaghetti.game.*;
4+
import spaghetti.utils.Pair;
45

56
import javax.swing.*;
67
import javax.swing.event.MouseInputListener;
@@ -324,8 +325,9 @@ protected void drawTile(Graphics2D g2, int row, int col) {
324325
int x0 = x + gridLineWidth, y0 = y + gridLineWidth, s = tileSize - gridLineWidth * 2;
325326

326327
Point p = new Point(row, col);
328+
Pair<Integer, Integer> pos = new Pair<>(row, col);
327329
if (type != '\0') {
328-
drawTileType(g2, type, x0, y0, s, color0, color1, parent.colorPalette.get(-1));
330+
drawTileType(g2, type, x0, y0, s, color0, color1, parent.colorPalette.get(pos.equals(board.getLastMove())? 7: -1));
329331
} else if (p.equals(highlight)) {
330332
g2.setColor(parent.colorPalette.get(6));
331333
g2.fillRect(x, y, s + gridLineWidth * 2, s + gridLineWidth * 2);

swing/src/spaghetti/gui/swing/PlayerSelectionPage.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import spaghetti.game.Board;
44
import spaghetti.game.BoardController;
5-
import spaghetti.game.BoardListener;
6-
import spaghetti.utils.Pair;
75

86
import javax.swing.*;
97
import java.awt.*;
@@ -128,7 +126,7 @@ private void onSubmit(ActionEvent actionEvent) {
128126
boolean human = selectors[0].isLocalHuman() && selectors[1].isLocalHuman();
129127
if (human) {
130128
try {
131-
board = new Board(Math.min(Integer.parseInt(boardWidthField.getText()), 50), Math.min(Integer.parseInt(boardHeightField.getText()), 50));
129+
board = new Board(Math.min(Integer.parseInt(boardWidthField.getText()), 26), Math.min(Integer.parseInt(boardHeightField.getText()), 26));
132130
} catch (Exception exception) {
133131
board = new Board(7, 9);
134132
}

swing/src/spaghetti/gui/swing/SpaghettiInterface.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package spaghetti.gui.swing;
22

3-
import spaghetti.game.Board;
4-
53
import javax.swing.*;
6-
import javax.swing.plaf.ColorUIResource;
74
import java.awt.*;
85
import java.util.HashMap;
96
import java.util.Map;
@@ -22,7 +19,7 @@ public class SpaghettiInterface extends JFrame {
2219
put(4, new Color(221, 136, 136));
2320
put(5, Color.GRAY);
2421
put(6, new Color(255, 255, 237)); // HIGHLIGHTED
25-
put(7, new Color(170,238,170)); // TARGET HIGHLIGHTED
22+
put(7, new Color(250, 250, 250)); // LAST MOVE HIGHLIGHT
2623
put(8, new Color(160, 160, 160)); // SAMPLE BACKGROUND 1
2724
put(9, new Color(170, 170, 170)); // SAMPLE BACKGROUND 2
2825
}};
@@ -36,7 +33,7 @@ public class SpaghettiInterface extends JFrame {
3633
put(4, new Color(221, 136, 136));
3734
put(5, Color.GRAY);
3835
put(6, new Color(200, 200, 205)); // HIGHLIGHTED
39-
put(7, new Color(170,238,170)); // TARGET HIGHLIGHTED
36+
put(7, new Color(150, 150, 150)); // LAST MOVE HIGHLIGHT
4037
put(8, new Color(43, 43, 44)); // SAMPLE BACKGROUND 1
4138
put(9, new Color(60, 63, 65)); // SAMPLE BACKGROUND 2
4239
}};

0 commit comments

Comments
 (0)