Moves flip dots. all tests pass. can play reversi local.

This commit is contained in:
Ticho Hidding
2025-10-11 00:51:46 +02:00
parent 5dda85248e
commit c1f7a093ef
6 changed files with 102 additions and 48 deletions

View File

@@ -104,7 +104,6 @@ public abstract class GameCanvas {
graphics.setFill(color);
graphics.fillOval(x, y, width, height);
IO.println("gothere");
}
public void resize(int width, int height) {

View File

@@ -8,7 +8,6 @@ import org.toop.game.Game;
import java.util.function.Consumer;
public class ReversiCanvas extends GameCanvas{
private Game.Move[] mostRecentLegalMoves;
public ReversiCanvas(Color color, int width, int height, Consumer<Integer> onCellClicked) {
super(color, width, height, 8, 8, 10, true, onCellClicked);
drawStartingDots();
@@ -20,18 +19,8 @@ public class ReversiCanvas extends GameCanvas{
drawDot(Color.WHITE,27);
}
public void drawLegalMoves(Game.Move[] moves){
mostRecentLegalMoves = moves;
for(Game.Move move : moves){
IO.println("Legal Moves:" + move.position());
drawDot(new Color(1f,0,0,0.25f),move.position());
}
}
public void removeLegalMoves(){
if (mostRecentLegalMoves != null){
for(Game.Move move : mostRecentLegalMoves){
drawDot(Color.GRAY,move.position()); //todo get current background color or make this redraw the entire board
}
}
mostRecentLegalMoves = null;
}
}

View File

@@ -7,6 +7,7 @@ import org.toop.app.layer.*;
import org.toop.app.layer.containers.HorizontalContainer;
import org.toop.app.layer.containers.VerticalContainer;
import org.toop.app.layer.layers.MainLayer;
import org.toop.game.Game;
import org.toop.game.reversi.Reversi;
import org.toop.game.reversi.ReversiAI;
import org.toop.local.AppContext;
@@ -19,7 +20,9 @@ public class ReversiLayer extends Layer{
super("bg-secondary"); //make reversiboard background dark green
canvas = new ReversiCanvas(Color.GREEN,(App.getHeight() / 100) * 75, (App.getHeight() / 100) * 75, (cell) -> {
IO.println("clicked reversi cell: "+cell);
reversi.play(new Game.Move(cell,reversi.getCurrentPlayer()));
reload();
canvas.drawLegalMoves(reversi.getLegalMoves());
});
reversi = new Reversi() ;
reversiAI = new ReversiAI();