mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
canvas changes
This commit is contained in:
@@ -6,6 +6,6 @@ import java.util.function.Consumer;
|
||||
|
||||
public class Connect4Canvas extends GameCanvas {
|
||||
public Connect4Canvas(Color color, int width, int height, Consumer<Integer> onCellClicked) {
|
||||
super(color, width, height, 7, 6, 10, true, onCellClicked);
|
||||
super(color, Color.TRANSPARENT, width, height, 7, 6, 10, true, onCellClicked);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ public abstract class GameCanvas {
|
||||
protected final GraphicsContext graphics;
|
||||
|
||||
protected final Color color;
|
||||
protected final Color backgroundColor;
|
||||
|
||||
protected final int width;
|
||||
protected final int height;
|
||||
@@ -34,11 +35,12 @@ public abstract class GameCanvas {
|
||||
|
||||
protected final Cell[] cells;
|
||||
|
||||
protected GameCanvas(Color color, int width, int height, int rowSize, int columnSize, int gapSize, boolean edges, Consumer<Integer> onCellClicked) {
|
||||
protected GameCanvas(Color color, Color backgroundColor, int width, int height, int rowSize, int columnSize, int gapSize, boolean edges, Consumer<Integer> onCellClicked) {
|
||||
canvas = new Canvas(width, height);
|
||||
graphics = canvas.getGraphicsContext2D();
|
||||
|
||||
this.color = color;
|
||||
this.backgroundColor = backgroundColor;
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
@@ -83,6 +85,9 @@ public abstract class GameCanvas {
|
||||
}
|
||||
|
||||
private void render() {
|
||||
graphics.setFill(backgroundColor);
|
||||
graphics.fillRect(0, 0, width, height);
|
||||
|
||||
graphics.setFill(color);
|
||||
|
||||
for (int x = 0; x < rowSize - 1; x++) {
|
||||
@@ -123,6 +128,9 @@ public abstract class GameCanvas {
|
||||
final float height = cells[cell].height();
|
||||
|
||||
graphics.clearRect(x, y, width, height);
|
||||
|
||||
graphics.setFill(backgroundColor);
|
||||
graphics.fillRect(x, y, width, height);
|
||||
}
|
||||
|
||||
public void clearAll() {
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.function.Consumer;
|
||||
|
||||
public final class ReversiCanvas extends GameCanvas {
|
||||
public ReversiCanvas(Color color, int width, int height, Consumer<Integer> onCellClicked) {
|
||||
super(color, width, height, 8, 8, 10, true, onCellClicked);
|
||||
super(color, Color.GREEN, width, height, 8, 8, 5, true, onCellClicked);
|
||||
drawStartingDots();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.function.Consumer;
|
||||
|
||||
public final class TicTacToeCanvas extends GameCanvas {
|
||||
public TicTacToeCanvas(Color color, int width, int height, Consumer<Integer> onCellClicked) {
|
||||
super(color, width, height, 3, 3, 30, false, onCellClicked);
|
||||
super(color, Color.TRANSPARENT, width, height, 3, 3, 30, false, onCellClicked);
|
||||
}
|
||||
|
||||
public void drawX(Color color, int cell) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.toop.app.game;
|
||||
|
||||
import javafx.animation.SequentialTransition;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.util.Duration;
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.GameInformation;
|
||||
import org.toop.app.canvas.ReversiCanvas;
|
||||
@@ -64,7 +62,7 @@ public final class ReversiGame {
|
||||
}, onMessage);
|
||||
}
|
||||
|
||||
canvas = new ReversiCanvas(Color.GRAY,
|
||||
canvas = new ReversiCanvas(Color.BLACK,
|
||||
(App.getHeight() / 4) * 3, (App.getHeight() / 4) * 3,
|
||||
(cell) -> {
|
||||
if (onForfeit == null || onExit == null) {
|
||||
|
||||
Reference in New Issue
Block a user