Code readability

This commit is contained in:
Bas de Jong
2026-01-07 14:38:19 +01:00
parent a7d1a964c2
commit 67f39c3f3b
4 changed files with 26 additions and 34 deletions

View File

@@ -11,6 +11,7 @@ import org.toop.app.widget.popup.ErrorPopup;
import org.toop.app.widget.popup.SendChallengePopup; import org.toop.app.widget.popup.SendChallengePopup;
import org.toop.app.widget.view.ServerView; import org.toop.app.widget.view.ServerView;
import org.toop.framework.eventbus.EventFlow; import org.toop.framework.eventbus.EventFlow;
import org.toop.framework.game.players.LocalPlayer;
import org.toop.framework.gameFramework.controller.GameController; import org.toop.framework.gameFramework.controller.GameController;
import org.toop.framework.eventbus.GlobalEventBus; import org.toop.framework.eventbus.GlobalEventBus;
import org.toop.framework.gameFramework.model.player.Player; import org.toop.framework.gameFramework.model.player.Player;
@@ -202,33 +203,24 @@ public final class Server {
final GameInformation information = new GameInformation(type); final GameInformation information = new GameInformation(type);
//information.players[0] = playerInformation; //information.players[0] = playerInformation;
information.players[0].name = user; information.players[0].name = user;
information.players[0].isHuman = false; information.players[0].isHuman = true; // Make false and uncomment/comment code at lines HERE To make use of AI.
information.players[0].computerDifficulty = 5; // information.players[0].computerDifficulty = 5; // HERE
information.players[0].computerThinkTime = 1; // information.players[0].computerThinkTime = 1; // HERE
information.players[1].name = response.opponent(); information.players[1].name = response.opponent();
/*switch (type){
case TICTACTOE ->{
players[myTurn] = new ArtificialPlayer<>(new TicTacToeAIR(9), user);
}
case REVERSI ->{
players[myTurn] = new ArtificialPlayer<>(new ReversiAIR(), user);
}
}*/
switch (type) { switch (type) {
case TICTACTOE ->{ case TICTACTOE -> {
Player[] players = new Player[2]; Player[] players = new Player[2];
players[(myTurn + 1) % 2] = new OnlinePlayer(response.opponent()); players[Math.abs(myTurn-1)] = new OnlinePlayer(response.opponent());
players[myTurn] = new ArtificialPlayer(new RandomAI(), user); players[myTurn] = new LocalPlayer(user); // HERE
// players[myTurn] = new ArtificialPlayer(new RandomAI(), user); // HERE
gameController = new TicTacToeBitController(players); gameController = new TicTacToeBitController(players);
} }
case REVERSI -> { case REVERSI -> {
Player[] players = new Player[2]; Player[] players = new Player[2];
players[(myTurn + 1) % 2] = new OnlinePlayer(response.opponent()); players[Math.abs(myTurn-1)] = new OnlinePlayer(response.opponent());
players[myTurn] = new ArtificialPlayer(new RandomAI(), user); players[myTurn] = new LocalPlayer(user); // HERE
// players[myTurn] = new ArtificialPlayer(new RandomAI(), user); // HERE
gameController = new ReversiBitController(players);} gameController = new ReversiBitController(players);}
default -> new ErrorPopup("Unsupported game type."); default -> new ErrorPopup("Unsupported game type.");

View File

@@ -8,16 +8,16 @@ import org.toop.framework.game.gameThreads.OnlineThreadBehaviour;
import org.toop.framework.game.games.reversi.BitboardReversi; import org.toop.framework.game.games.reversi.BitboardReversi;
import org.toop.framework.game.players.OnlinePlayer; import org.toop.framework.game.players.OnlinePlayer;
import java.util.Arrays;
public class ReversiBitController extends GenericGameController { public class ReversiBitController extends GenericGameController {
public ReversiBitController(Player[] players) { public ReversiBitController(Player[] players) {
BitboardReversi game = new BitboardReversi(); BitboardReversi game = new BitboardReversi();
game.init(players); game.init(players);
ThreadBehaviour thread = new LocalThreadBehaviour(game);
for (Player player : players) { ThreadBehaviour thread = Arrays.stream(players).anyMatch(e -> e instanceof OnlinePlayer) ?
if (player instanceof OnlinePlayer){ new OnlineThreadBehaviour(game) : new LocalThreadBehaviour(game);
thread = new OnlineThreadBehaviour(game);
}
}
super(new ReversiBitCanvas(), game, thread, "Reversi"); super(new ReversiBitCanvas(), game, thread, "Reversi");
} }
} }

View File

@@ -7,17 +7,18 @@ import org.toop.framework.game.gameThreads.LocalThreadBehaviour;
import org.toop.framework.game.gameThreads.OnlineThreadBehaviour; import org.toop.framework.game.gameThreads.OnlineThreadBehaviour;
import org.toop.framework.game.games.tictactoe.BitboardTicTacToe; import org.toop.framework.game.games.tictactoe.BitboardTicTacToe;
import org.toop.framework.game.players.OnlinePlayer; import org.toop.framework.game.players.OnlinePlayer;
import org.toop.framework.networking.server.OnlineGame;
import java.util.Arrays;
public class TicTacToeBitController extends GenericGameController { public class TicTacToeBitController extends GenericGameController {
public TicTacToeBitController(Player[] players) { public TicTacToeBitController(Player[] players) {
BitboardTicTacToe game = new BitboardTicTacToe(); BitboardTicTacToe game = new BitboardTicTacToe();
game.init(players); game.init(players);
ThreadBehaviour thread = new LocalThreadBehaviour(game);
for (Player player : players) { ThreadBehaviour thread = Arrays.stream(players).anyMatch(e -> e instanceof OnlinePlayer) ?
if (player instanceof OnlinePlayer){ new OnlineThreadBehaviour(game) : new LocalThreadBehaviour(game);
thread = new OnlineThreadBehaviour(game);
}
}
super(new TicTacToeBitCanvas(), game, thread , "TicTacToe"); super(new TicTacToeBitCanvas(), game, thread , "TicTacToe");
} }
} }

View File

@@ -136,7 +136,6 @@ public class Server implements GameServer<TurnBasedGame, NettyClient, Long> {
players[i] = new ServerPlayer(clients[i]); players[i] = new ServerPlayer(clients[i]);
clients[i].setGame(new ImmutablePair<>(game, players[i])); clients[i].setGame(new ImmutablePair<>(game, players[i]));
} }
System.out.println("Starting OnlineTurnBasedGame");
game.game().init(players); game.game().init(players);
gameStore.add(game); gameStore.add(game);