Continuing gradual process of collecting state from various GUI components and handlers and aggregating it in PlayerController.
Removed references to Refree from some handlers, replacing them with direct use of PlayerController (Law of Demeter).
This commit is contained in:
54
src/controller/BoardPanelMouseListener.java
Normal file
54
src/controller/BoardPanelMouseListener.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package controller;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
|
||||
public class BoardPanelMouseListener implements MouseListener, MouseWheelListener {
|
||||
|
||||
private final int col;
|
||||
private final int row;
|
||||
private final PlayerController pc;
|
||||
|
||||
public BoardPanelMouseListener(int row, int col, PlayerController pc) {
|
||||
this.row = row;
|
||||
this.col = col;
|
||||
this.pc = pc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
pc.setCell(row, col);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent arg0) {
|
||||
// Nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent arg0) {
|
||||
// Nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent arg0) {
|
||||
// Nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent arg0) {
|
||||
// Nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseWheelMoved(MouseWheelEvent e) {
|
||||
if (e.getWheelRotation() > 0) {
|
||||
pc.incrementColor();
|
||||
} else if (e.getWheelRotation() < 0) {
|
||||
pc.decrementColor();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,17 @@
|
||||
package controller;
|
||||
|
||||
import model.Board.TileColor;
|
||||
import model.Board;
|
||||
import model.CellPointer;
|
||||
import model.Move;
|
||||
|
||||
public class PlayerController {
|
||||
private final CellPointer cell = new CellPointer(0, 0);
|
||||
private TileColor color = TileColor.BLUE;
|
||||
|
||||
private boolean current = true;
|
||||
private boolean ready = false;
|
||||
|
||||
private TileColor color = TileColor.BLUE;
|
||||
|
||||
public void denyMove() {
|
||||
ready = false;
|
||||
}
|
||||
@@ -23,6 +26,50 @@ public class PlayerController {
|
||||
|
||||
}
|
||||
|
||||
public void decrementColor() {
|
||||
TileColor[] colors = Board.TileColor.values();
|
||||
int currentColor = -1;
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
if (colors[i] == color) {
|
||||
currentColor = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (currentColor == -1) {
|
||||
throw new RuntimeException("Color not found: " + color + "!");
|
||||
}
|
||||
currentColor = (currentColor + colors.length -1) % colors.length;
|
||||
if (colors[currentColor] == TileColor.NONE) {
|
||||
currentColor = (currentColor + colors.length -1) % colors.length;
|
||||
}
|
||||
color = colors[currentColor];
|
||||
setCurrent(false);
|
||||
}
|
||||
|
||||
public void incrementColor() {
|
||||
TileColor[] colors = Board.TileColor.values();
|
||||
int currentColor = -1;
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
if (colors[i] == color) {
|
||||
currentColor = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (currentColor == -1) {
|
||||
throw new RuntimeException("Color not found: " + color + "!");
|
||||
}
|
||||
currentColor = (currentColor+1) % colors.length;
|
||||
if (colors[currentColor] == TileColor.NONE) {
|
||||
currentColor = (currentColor+1) % colors.length;
|
||||
}
|
||||
color = colors[currentColor];
|
||||
setCurrent(false);
|
||||
}
|
||||
|
||||
public boolean isCurrent() {
|
||||
return current;
|
||||
}
|
||||
|
||||
public boolean isReady() {
|
||||
return ready;
|
||||
}
|
||||
@@ -37,4 +84,8 @@ public class PlayerController {
|
||||
public void setColor(TileColor clr) {
|
||||
color = clr;
|
||||
}
|
||||
|
||||
public void setCurrent(boolean current) {
|
||||
this.current = current;
|
||||
}
|
||||
}
|
||||
|
||||
42
src/controller/TSPMouseListener.java
Normal file
42
src/controller/TSPMouseListener.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package controller;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
import view.TileSelectionPanel;
|
||||
|
||||
import model.Board.TileColor;
|
||||
|
||||
public class TSPMouseListener implements MouseListener{
|
||||
private PlayerController pc;
|
||||
private TileColor tileColor;
|
||||
private TileSelectionPanel tsp;
|
||||
|
||||
public TSPMouseListener(PlayerController pc, TileSelectionPanel tsp, TileColor tileColor) {
|
||||
this.pc = pc;
|
||||
this.tileColor = tileColor;
|
||||
this.tsp = tsp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent arg0) {
|
||||
pc.setColor(tileColor);
|
||||
tsp.setCurrent(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent arg0) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user