mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Code readability
This commit is contained in:
@@ -11,6 +11,7 @@ import org.toop.app.widget.popup.ErrorPopup;
|
||||
import org.toop.app.widget.popup.SendChallengePopup;
|
||||
import org.toop.app.widget.view.ServerView;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.game.players.LocalPlayer;
|
||||
import org.toop.framework.gameFramework.controller.GameController;
|
||||
import org.toop.framework.eventbus.GlobalEventBus;
|
||||
import org.toop.framework.gameFramework.model.player.Player;
|
||||
@@ -202,33 +203,24 @@ public final class Server {
|
||||
final GameInformation information = new GameInformation(type);
|
||||
//information.players[0] = playerInformation;
|
||||
information.players[0].name = user;
|
||||
information.players[0].isHuman = false;
|
||||
information.players[0].computerDifficulty = 5;
|
||||
information.players[0].computerThinkTime = 1;
|
||||
information.players[0].isHuman = true; // Make false and uncomment/comment code at lines HERE To make use of AI.
|
||||
// information.players[0].computerDifficulty = 5; // HERE
|
||||
// information.players[0].computerThinkTime = 1; // HERE
|
||||
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) {
|
||||
case TICTACTOE -> {
|
||||
Player[] players = new Player[2];
|
||||
players[(myTurn + 1) % 2] = new OnlinePlayer(response.opponent());
|
||||
players[myTurn] = new ArtificialPlayer(new RandomAI(), user);
|
||||
players[Math.abs(myTurn-1)] = new OnlinePlayer(response.opponent());
|
||||
players[myTurn] = new LocalPlayer(user); // HERE
|
||||
// players[myTurn] = new ArtificialPlayer(new RandomAI(), user); // HERE
|
||||
gameController = new TicTacToeBitController(players);
|
||||
}
|
||||
case REVERSI -> {
|
||||
Player[] players = new Player[2];
|
||||
players[(myTurn + 1) % 2] = new OnlinePlayer(response.opponent());
|
||||
players[myTurn] = new ArtificialPlayer(new RandomAI(), user);
|
||||
players[Math.abs(myTurn-1)] = new OnlinePlayer(response.opponent());
|
||||
players[myTurn] = new LocalPlayer(user); // HERE
|
||||
// players[myTurn] = new ArtificialPlayer(new RandomAI(), user); // HERE
|
||||
gameController = new ReversiBitController(players);}
|
||||
default -> new ErrorPopup("Unsupported game type.");
|
||||
|
||||
|
||||
@@ -8,16 +8,16 @@ import org.toop.framework.game.gameThreads.OnlineThreadBehaviour;
|
||||
import org.toop.framework.game.games.reversi.BitboardReversi;
|
||||
import org.toop.framework.game.players.OnlinePlayer;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ReversiBitController extends GenericGameController {
|
||||
public ReversiBitController(Player[] players) {
|
||||
BitboardReversi game = new BitboardReversi();
|
||||
game.init(players);
|
||||
ThreadBehaviour thread = new LocalThreadBehaviour(game);
|
||||
for (Player player : players) {
|
||||
if (player instanceof OnlinePlayer){
|
||||
thread = new OnlineThreadBehaviour(game);
|
||||
}
|
||||
}
|
||||
|
||||
ThreadBehaviour thread = Arrays.stream(players).anyMatch(e -> e instanceof OnlinePlayer) ?
|
||||
new OnlineThreadBehaviour(game) : new LocalThreadBehaviour(game);
|
||||
|
||||
super(new ReversiBitCanvas(), game, thread, "Reversi");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,17 +7,18 @@ import org.toop.framework.game.gameThreads.LocalThreadBehaviour;
|
||||
import org.toop.framework.game.gameThreads.OnlineThreadBehaviour;
|
||||
import org.toop.framework.game.games.tictactoe.BitboardTicTacToe;
|
||||
import org.toop.framework.game.players.OnlinePlayer;
|
||||
import org.toop.framework.networking.server.OnlineGame;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class TicTacToeBitController extends GenericGameController {
|
||||
public TicTacToeBitController(Player[] players) {
|
||||
BitboardTicTacToe game = new BitboardTicTacToe();
|
||||
game.init(players);
|
||||
ThreadBehaviour thread = new LocalThreadBehaviour(game);
|
||||
for (Player player : players) {
|
||||
if (player instanceof OnlinePlayer){
|
||||
thread = new OnlineThreadBehaviour(game);
|
||||
}
|
||||
}
|
||||
|
||||
ThreadBehaviour thread = Arrays.stream(players).anyMatch(e -> e instanceof OnlinePlayer) ?
|
||||
new OnlineThreadBehaviour(game) : new LocalThreadBehaviour(game);
|
||||
|
||||
super(new TicTacToeBitCanvas(), game, thread , "TicTacToe");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,6 @@ public class Server implements GameServer<TurnBasedGame, NettyClient, Long> {
|
||||
players[i] = new ServerPlayer(clients[i]);
|
||||
clients[i].setGame(new ImmutablePair<>(game, players[i]));
|
||||
}
|
||||
System.out.println("Starting OnlineTurnBasedGame");
|
||||
|
||||
game.game().init(players);
|
||||
gameStore.add(game);
|
||||
|
||||
Reference in New Issue
Block a user