FX My Life XIII: Then Again, Maybe I AM Dyslexic

public void addPiece(String piece, int x, int y) throws Exception {
if (state[y][x] != null) {
throw new Exception("Attempt to add piece illegally!");
}
state[y][x] = piece;
checkGameState();
}
public void handleOnDragOver(DragEvent event) {
int column = getCoord(board.getWidth(), event.getX(), board.getRowCount());
int row = getCoord(board.getHeight(), event.getY(), board.getColumnCount());

if (game.get(row, column) == null) {
if (event.getGestureSource() != board && event.getDragboard().hasString()) {
event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
}
}
event.consume();
}
public String turn;
turn = "X"; //X always goes first
public void addPiece(String piece, int x, int y) throws Exception {
if (state[y][x] != null || !turn.equals(piece)) {
throw new Exception("Attempt to add piece illegally!");
}
state[y][x] = piece;
checkGameState();
if (turn.equals("X")) {
turn = "O";
} else {
turn = "X";
}
}
java.lang.Exception: Attempt to add piece illegally!
at fxgames.TicTacToe.addPiece(TicTacToe.java:83)
at fxgames.TttController.handleOnDrop(TttController.java:204)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:76)
at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)

Boundaries

When the board Grid is encased in a Group.
And when it’s not.
@FXML
public BorderPane outerGroup;
@FXML
public Node outerGroup;
public void handleOnDragDetected(MouseEvent event) {
String piece = ((ImageView) event.getSource()).getId();
message.setText(piece + " is being dragged!");
Dragboard db = X.startDragAndDrop(TransferMode.ANY);

ClipboardContent content = new ClipboardContent();
content.putString(piece);
db.setContent(content);
}
public void handleOnDragDetected(MouseEvent event) {
String piece = ((ImageView) event.getSource()).getId();
if (!game.winner.equals("")) {
message.setText("The game is over. Press NEW for a new game.");
} else {
if (!piece.equals(game.turn)) {
message.setText("You can't move " + piece + " when it's " + game.turn + "'s turn!");
} else {
message.setText(piece + " is being dragged!");
Dragboard db = X.startDragAndDrop(TransferMode.ANY);

ClipboardContent content = new ClipboardContent();
content.putString(piece);
db.setContent(content);
}
}
}
public void drawVictorySlash() {
if (!game.winner.equals("")) {
message.setText("Game over! " + game.winner + " wins!");
var bw = board.getWidth();
...

--

--

--

I am a poor, wayfaring stranger, traveling through this world of woe.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Configure your Teamcity Pipeline for Database Deployments

Py in 5: List Comprehensions

HOW TO RECOVER FILES DELETED FROM YOUR HARD DRIVE (OR EXTERNAL STORAGE)

Let’s learn about — Being a team player (and how it benefits you)

How to: Secrets Mapping on GitHub

Building A Custom Staff Scheduling Model- ‘A beginner’s journey using simple Python’

How To Get Flight Data In Ruby With An API.

Using Virtual Reality to Brand Interiors

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Blake

Blake

I am a poor, wayfaring stranger, traveling through this world of woe.

More from Medium

Sweet Night’s Christmas Tree

Protect Your Communications During the Most Fraudulent Time of the Year

#JustStart

screenshot of book

LibraryLife.NYC #2