mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
Changes by bas
This commit is contained in:
5
app/src/main/java/org/toop/app/canvas/Drawable.java
Normal file
5
app/src/main/java/org/toop/app/canvas/Drawable.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package org.toop.app.canvas;
|
||||
|
||||
public interface Drawable {
|
||||
void draw();
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.input.MouseButton;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.util.Duration;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@@ -143,6 +144,18 @@ public abstract class GameCanvas {
|
||||
}
|
||||
}
|
||||
|
||||
public void drawChar(char chr, Color color, int cell) {
|
||||
final float x = cells[cell].x() + gapSize;
|
||||
final float y = cells[cell].y() + gapSize;
|
||||
|
||||
final float width = cells[cell].width() - gapSize * 2;
|
||||
final float height = cells[cell].height() - gapSize * 2;
|
||||
|
||||
graphics.setFill(color);
|
||||
graphics.setFont(Font.font("Arial", 40)); // TODO different font and size
|
||||
graphics.fillText(String.valueOf(chr), x + width, y + height);
|
||||
}
|
||||
|
||||
public void drawDot(Color color, int cell) {
|
||||
final float x = cells[cell].x() + gapSize;
|
||||
final float y = cells[cell].y() + gapSize;
|
||||
|
||||
@@ -147,9 +147,9 @@ public final class TicTacToeGame {
|
||||
final GameState state = game.play(move);
|
||||
|
||||
if (move.value() == 'X') {
|
||||
canvas.drawX(Color.INDIANRED, move.position());
|
||||
canvas.drawPlayer('X', Color.INDIANRED, move.position());
|
||||
} else if (move.value() == 'O') {
|
||||
canvas.drawO(Color.ROYALBLUE, move.position());
|
||||
canvas.drawPlayer('O', Color.ROYALBLUE, move.position());
|
||||
}
|
||||
|
||||
if (state != GameState.NORMAL) {
|
||||
@@ -198,9 +198,9 @@ public final class TicTacToeGame {
|
||||
}
|
||||
|
||||
if (move.value() == 'X') {
|
||||
canvas.drawX(Color.RED, move.position());
|
||||
canvas.drawPlayer('X', Color.RED, move.position());
|
||||
} else if (move.value() == 'O') {
|
||||
canvas.drawO(Color.BLUE, move.position());
|
||||
canvas.drawPlayer('O', Color.BLUE, move.position());
|
||||
}
|
||||
|
||||
setGameLabels(game.getCurrentTurn() == myTurn);
|
||||
|
||||
@@ -49,8 +49,8 @@ public final class TicTacToeGameThread extends BaseGameThread<TicTacToe, TicTacT
|
||||
}
|
||||
|
||||
private void drawMove(Move move) {
|
||||
if (move.value() == 'X') canvas.drawX(Color.RED, move.position());
|
||||
else canvas.drawO(Color.BLUE, move.position());
|
||||
if (move.value() == 'X') canvas.drawPlayer('X', Color.RED, move.position());
|
||||
else canvas.drawPlayer('O', Color.BLUE, move.position());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user