mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Removed Generics, pray nothing breaks.
This commit is contained in:
@@ -214,15 +214,15 @@ public final class Server {
|
||||
|
||||
switch (type) {
|
||||
case TICTACTOE ->{
|
||||
Player<BitboardTicTacToe>[] players = new Player[2];
|
||||
players[(myTurn + 1) % 2] = new OnlinePlayer<>(response.opponent());
|
||||
players[myTurn] = new ArtificialPlayer<>(new RandomAI<BitboardTicTacToe>(), user);
|
||||
Player[] players = new Player[2];
|
||||
players[(myTurn + 1) % 2] = new OnlinePlayer(response.opponent());
|
||||
players[myTurn] = new ArtificialPlayer(new RandomAI(), user);
|
||||
gameController = new TicTacToeBitController(players);
|
||||
}
|
||||
case REVERSI -> {
|
||||
Player<BitboardReversi>[] players = new Player[2];
|
||||
players[(myTurn + 1) % 2] = new OnlinePlayer<>(response.opponent());
|
||||
players[myTurn] = new ArtificialPlayer<>(new RandomAI<BitboardReversi>(), user);
|
||||
Player[] players = new Player[2];
|
||||
players[(myTurn + 1) % 2] = new OnlinePlayer(response.opponent());
|
||||
players[myTurn] = new ArtificialPlayer(new RandomAI(), user);
|
||||
gameController = new ReversiBitController(players);}
|
||||
default -> new ErrorPopup("Unsupported game type.");
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.toop.framework.gameFramework.view.GUIEvents;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class BitGameCanvas<T extends TurnBasedGame<T>> implements GameCanvas<T> {
|
||||
public abstract class BitGameCanvas<T extends TurnBasedGame> implements GameCanvas {
|
||||
protected record Cell(float x, float y, float width, float height) {
|
||||
public boolean isInside(double x, double y) {
|
||||
return x >= this.x && x <= this.x + width &&
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package org.toop.app.canvas;
|
||||
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import org.toop.framework.gameFramework.model.game.TurnBasedGame;
|
||||
|
||||
public interface GameCanvas<T extends TurnBasedGame<T>> extends GameDrawer<T>{
|
||||
public interface GameCanvas extends GameDrawer{
|
||||
Canvas getCanvas();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,6 @@ package org.toop.app.canvas;
|
||||
|
||||
import org.toop.framework.gameFramework.model.game.TurnBasedGame;
|
||||
|
||||
public interface GameDrawer<T extends TurnBasedGame<T>> {
|
||||
void redraw(T gameCopy);
|
||||
public interface GameDrawer {
|
||||
void redraw(TurnBasedGame gameCopy);
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@ package org.toop.app.canvas;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
import org.toop.app.App;
|
||||
import org.toop.framework.gameFramework.model.game.TurnBasedGame;
|
||||
import org.toop.game.games.reversi.BitboardReversi;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ReversiBitCanvas extends BitGameCanvas<BitboardReversi> {
|
||||
public class ReversiBitCanvas extends BitGameCanvas {
|
||||
public ReversiBitCanvas() {
|
||||
super(Color.GRAY, new Color(0f, 0.4f, 0.2f, 1f), (App.getHeight() / 4) * 3, (App.getHeight() / 4) * 3, 8, 8, 5, true);
|
||||
canvas.setOnMouseMoved(event -> {
|
||||
@@ -33,10 +34,10 @@ public class ReversiBitCanvas extends BitGameCanvas<BitboardReversi> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redraw(BitboardReversi gameCopy) {
|
||||
public void redraw(TurnBasedGame gameCopy) {
|
||||
clearAll();
|
||||
long[] board = gameCopy.getBoard();
|
||||
loopOverBoard(board[0], (i) -> drawDot(Color.WHITE, i));
|
||||
loopOverBoard(board[1], (i) -> drawDot(Color.BLACK, i));
|
||||
loopOverBoard(board[0], (i) -> drawDot(Color.WHITE, (int)i));
|
||||
loopOverBoard(board[1], (i) -> drawDot(Color.BLACK, (int)i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@ package org.toop.app.canvas;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
import org.toop.app.App;
|
||||
import org.toop.framework.gameFramework.model.game.TurnBasedGame;
|
||||
import org.toop.game.games.tictactoe.BitboardTicTacToe;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class TicTacToeBitCanvas extends BitGameCanvas<BitboardTicTacToe>{
|
||||
public class TicTacToeBitCanvas extends BitGameCanvas{
|
||||
public TicTacToeBitCanvas() {
|
||||
super(
|
||||
Color.GRAY,
|
||||
@@ -22,14 +23,14 @@ public class TicTacToeBitCanvas extends BitGameCanvas<BitboardTicTacToe>{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redraw(BitboardTicTacToe gameCopy) {
|
||||
public void redraw(TurnBasedGame gameCopy) {
|
||||
clearAll();
|
||||
drawMoves(gameCopy.getBoard());
|
||||
}
|
||||
|
||||
private void drawMoves(long[] gameBoard){
|
||||
loopOverBoard(gameBoard[0], (i) -> drawX(Color.RED, i));
|
||||
loopOverBoard(gameBoard[1], (i) -> drawO(Color.BLUE, i));
|
||||
loopOverBoard(gameBoard[0], (i) -> drawX(Color.RED, (int)i));
|
||||
loopOverBoard(gameBoard[1], (i) -> drawO(Color.BLUE, (Integer) i));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import org.toop.framework.gameFramework.view.GUIEvents;
|
||||
import org.toop.framework.networking.events.NetworkEvents;
|
||||
import org.toop.game.players.LocalPlayer;
|
||||
|
||||
public class GenericGameController<T extends TurnBasedGame<T>> implements GameController {
|
||||
public class GenericGameController implements GameController {
|
||||
protected final EventFlow eventFlow = new EventFlow();
|
||||
|
||||
// Logger for logging
|
||||
@@ -28,13 +28,13 @@ public class GenericGameController<T extends TurnBasedGame<T>> implements GameCo
|
||||
protected final GameView gameView;
|
||||
|
||||
// Reference to game canvas
|
||||
protected final GameCanvas<T> canvas;
|
||||
protected final GameCanvas canvas;
|
||||
|
||||
protected final TurnBasedGame<T> game; // Reference to game instance
|
||||
protected final TurnBasedGame game; // Reference to game instance
|
||||
private final ThreadBehaviour gameThreadBehaviour;
|
||||
|
||||
// TODO: Change gameType to automatically happen with either dependency injection or something else.
|
||||
public GenericGameController(GameCanvas<T> canvas, T game, ThreadBehaviour gameThreadBehaviour, String gameType) {
|
||||
public GenericGameController(GameCanvas canvas, TurnBasedGame game, ThreadBehaviour gameThreadBehaviour, String gameType) {
|
||||
logger.info("Creating: " + this.getClass());
|
||||
|
||||
this.canvas = canvas;
|
||||
@@ -55,7 +55,9 @@ public class GenericGameController<T extends TurnBasedGame<T>> implements GameCo
|
||||
// Listen to updates
|
||||
eventFlow
|
||||
.listen(GUIEvents.GameEnded.class, this::onGameFinish, false)
|
||||
.listen(GUIEvents.PlayerAttemptedMove.class, event -> {if (getCurrentPlayer() instanceof LocalPlayer<T> lp){lp.setMove(event.move());}}, false);
|
||||
.listen(GUIEvents.PlayerAttemptedMove.class, event -> {
|
||||
if (getCurrentPlayer() instanceof LocalPlayer lp){lp.setMove(event.move());}
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void start(){
|
||||
@@ -70,7 +72,7 @@ public class GenericGameController<T extends TurnBasedGame<T>> implements GameCo
|
||||
gameThreadBehaviour.stop();
|
||||
}
|
||||
|
||||
public Player<T> getCurrentPlayer(){
|
||||
public Player getCurrentPlayer(){
|
||||
return game.getPlayer(getCurrentPlayerIndex());
|
||||
}
|
||||
|
||||
@@ -97,7 +99,7 @@ public class GenericGameController<T extends TurnBasedGame<T>> implements GameCo
|
||||
stop();
|
||||
}
|
||||
|
||||
public Player<T> getPlayer(int player){
|
||||
public Player getPlayer(int player){
|
||||
if (player < 0 || player >= 2){ // TODO: Make game turn player count
|
||||
logger.error("Invalid player index");
|
||||
throw new IllegalArgumentException("player out of range");
|
||||
|
||||
@@ -8,13 +8,13 @@ import org.toop.game.gameThreads.OnlineThreadBehaviour;
|
||||
import org.toop.game.games.reversi.BitboardReversi;
|
||||
import org.toop.game.players.OnlinePlayer;
|
||||
|
||||
public class ReversiBitController extends GenericGameController<BitboardReversi> {
|
||||
public ReversiBitController(Player<BitboardReversi>[] players) {
|
||||
public class ReversiBitController extends GenericGameController {
|
||||
public ReversiBitController(Player[] players) {
|
||||
BitboardReversi game = new BitboardReversi(players);
|
||||
ThreadBehaviour thread = new LocalThreadBehaviour<>(game);
|
||||
for (Player<BitboardReversi> player : players) {
|
||||
if (player instanceof OnlinePlayer<BitboardReversi>){
|
||||
thread = new OnlineThreadBehaviour<>(game);
|
||||
ThreadBehaviour thread = new LocalThreadBehaviour(game);
|
||||
for (Player player : players) {
|
||||
if (player instanceof OnlinePlayer){
|
||||
thread = new OnlineThreadBehaviour(game);
|
||||
}
|
||||
}
|
||||
super(new ReversiBitCanvas(), game, thread, "Reversi");
|
||||
|
||||
@@ -9,13 +9,13 @@ import org.toop.game.gameThreads.OnlineThreadBehaviour;
|
||||
import org.toop.game.games.tictactoe.BitboardTicTacToe;
|
||||
import org.toop.game.players.OnlinePlayer;
|
||||
|
||||
public class TicTacToeBitController extends GenericGameController<BitboardTicTacToe> {
|
||||
public TicTacToeBitController(Player<BitboardTicTacToe>[] players) {
|
||||
public class TicTacToeBitController extends GenericGameController {
|
||||
public TicTacToeBitController(Player[] players) {
|
||||
BitboardTicTacToe game = new BitboardTicTacToe(players);
|
||||
ThreadBehaviour thread = new LocalThreadBehaviour<>(game);
|
||||
for (Player<BitboardTicTacToe> player : players) {
|
||||
if (player instanceof OnlinePlayer<BitboardTicTacToe>){
|
||||
thread = new OnlineThreadBehaviour<>(game);
|
||||
ThreadBehaviour thread = new LocalThreadBehaviour(game);
|
||||
for (Player player : players) {
|
||||
if (player instanceof OnlinePlayer){
|
||||
thread = new OnlineThreadBehaviour(game);
|
||||
}
|
||||
}
|
||||
super(new TicTacToeBitCanvas(), game, thread , "TicTacToe");
|
||||
|
||||
@@ -58,14 +58,14 @@ public class LocalMultiplayerView extends ViewWidget {
|
||||
switch (information.type) {
|
||||
case TICTACTOE:
|
||||
if (information.players[0].isHuman) {
|
||||
players[0] = new LocalPlayer<>(information.players[0].name);
|
||||
players[0] = new LocalPlayer(information.players[0].name);
|
||||
} else {
|
||||
players[0] = new ArtificialPlayer<>(new RandomAI<BitboardTicTacToe>(), "Random AI");
|
||||
players[0] = new ArtificialPlayer(new RandomAI(), "Random AI");
|
||||
}
|
||||
if (information.players[1].isHuman) {
|
||||
players[1] = new LocalPlayer<>(information.players[1].name);
|
||||
players[1] = new LocalPlayer(information.players[1].name);
|
||||
} else {
|
||||
players[1] = new ArtificialPlayer<>(new MiniMaxAI<BitboardTicTacToe>(9), "MiniMax AI");
|
||||
players[1] = new ArtificialPlayer(new MiniMaxAI(9), "MiniMax AI");
|
||||
}
|
||||
if (AppSettings.getSettings().getTutorialFlag() && AppSettings.getSettings().getFirstTTT()) {
|
||||
new ShowEnableTutorialWidget(
|
||||
@@ -86,14 +86,14 @@ public class LocalMultiplayerView extends ViewWidget {
|
||||
break;
|
||||
case REVERSI:
|
||||
if (information.players[0].isHuman) {
|
||||
players[0] = new LocalPlayer<>(information.players[0].name);
|
||||
players[0] = new LocalPlayer(information.players[0].name);
|
||||
} else {
|
||||
players[0] = new ArtificialPlayer<>(new RandomAI<BitboardReversi>(), "Random AI");
|
||||
players[0] = new ArtificialPlayer(new RandomAI(), "Random AI");
|
||||
}
|
||||
if (information.players[1].isHuman) {
|
||||
players[1] = new LocalPlayer<>(information.players[1].name);
|
||||
players[1] = new LocalPlayer(information.players[1].name);
|
||||
} else {
|
||||
players[1] = new ArtificialPlayer<>(new MiniMaxAI<BitboardReversi>(6), "MiniMax");
|
||||
players[1] = new ArtificialPlayer(new MiniMaxAI(6), "MiniMax");
|
||||
}
|
||||
if (AppSettings.getSettings().getTutorialFlag() && AppSettings.getSettings().getFirstReversi()) {
|
||||
new ShowEnableTutorialWidget(
|
||||
|
||||
Reference in New Issue
Block a user