mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
update: style
This commit is contained in:
@@ -5,7 +5,6 @@ import org.toop.app.layer.layers.MainLayer;
|
||||
import org.toop.app.layer.layers.QuitLayer;
|
||||
import org.toop.framework.asset.ResourceManager;
|
||||
import org.toop.framework.asset.resources.CssAsset;
|
||||
import org.toop.framework.asset.resources.SettingsAsset;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.local.AppContext;
|
||||
@@ -24,7 +23,6 @@ public final class App extends Application {
|
||||
private static Stack<Layer> stack;
|
||||
private static int height;
|
||||
private static int width;
|
||||
private static SettingsAsset settingsAsset;
|
||||
|
||||
private static boolean isQuitting;
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package org.toop.app;
|
||||
|
||||
public enum GameType {
|
||||
TICTACTOE, OTHELLO;
|
||||
|
||||
public static String toName(GameType type) {
|
||||
return switch (type) {
|
||||
case TICTACTOE -> "tic-tac-toe";
|
||||
case OTHELLO -> "Othello";
|
||||
};
|
||||
}
|
||||
|
||||
public static GameType toType(String name) {
|
||||
return switch (name) {
|
||||
case "tic-tac-toe" -> TICTACTOE;
|
||||
case "Reversi" -> OTHELLO;
|
||||
|
||||
default -> TICTACTOE;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
package org.toop.app;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.toop.framework.asset.ResourceLoader;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.networking.NetworkingClientManager;
|
||||
import org.toop.framework.networking.events.NetworkEvents;
|
||||
|
||||
import static java.lang.Thread.sleep;
|
||||
|
||||
|
||||
public class Match {
|
||||
private String player1,player2;
|
||||
private boolean player1AI,player2AI;
|
||||
private String ip;
|
||||
private int port;
|
||||
private boolean isLocal;
|
||||
private GameType type;
|
||||
private long clientId;
|
||||
private static final Logger logger = LogManager.getLogger(Match.class);
|
||||
|
||||
public Match(String player1, String player2, boolean player1AI, boolean player2AI, GameType type) {
|
||||
this.player1 = player1;
|
||||
this.player2 = player2;
|
||||
this.player1AI = player1AI;
|
||||
this.player2AI = player2AI;
|
||||
this.type = type;
|
||||
this.isLocal = true;
|
||||
|
||||
startGameLoop();
|
||||
}
|
||||
public Match(String player1, boolean player1AI, String ip, int port, GameType type) {
|
||||
this.player1 = player1;
|
||||
this.player1AI = player1AI;
|
||||
this.ip = ip;
|
||||
this.port = port;
|
||||
this.type = type;
|
||||
this.isLocal = false;
|
||||
|
||||
new EventFlow()
|
||||
.listen(this::handleStartClientResponse)
|
||||
.listen(this::handleYourTurn);
|
||||
|
||||
startServerConnection();
|
||||
//startGameLoop();
|
||||
}
|
||||
private void handleYourTurn(NetworkEvents.YourTurnResponse response) {
|
||||
//System.out.println(response.toString());
|
||||
//new EventFlow().addPostEvent(NetworkEvents.SendMove.class, clientId,(short)1).asyncPostEvent();
|
||||
|
||||
new EventFlow().addPostEvent(NetworkEvents.SendCommand.class, clientId,"MOVE 2").asyncPostEvent();
|
||||
}
|
||||
|
||||
private void loginAndSubscribe(GameType type) {
|
||||
if(clientId > 0){
|
||||
new EventFlow().addPostEvent(NetworkEvents.SendLogin.class,clientId,player1).asyncPostEvent();
|
||||
new EventFlow().addPostEvent(NetworkEvents.SendSubscribe.class,clientId,GameType.toName(type)).asyncPostEvent();
|
||||
startGameLoop();
|
||||
}
|
||||
else {
|
||||
logger.warn("Internal client ID is invalid. Failed to log in.");
|
||||
}
|
||||
}
|
||||
|
||||
void handleStartClientResponse(NetworkEvents.StartClientResponse response) {
|
||||
this.clientId = response.clientId();
|
||||
loginAndSubscribe(type);
|
||||
}
|
||||
|
||||
private boolean startServerConnection() {
|
||||
if(!isLocal){
|
||||
if(ip == null || port <= 0){
|
||||
logger.warn("IP address or port is invalid");
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
new EventFlow().addPostEvent(NetworkEvents.StartClient.class,ip,port).asyncPostEvent();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private void startGameLoop() {
|
||||
if(!isLocal){
|
||||
//new EventFlow().addPostEvent(NetworkEvents.SendMove.class,clientId,2).asyncPostEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package org.toop.app.events;
|
||||
|
||||
import org.toop.framework.eventbus.events.EventWithoutSnowflake;
|
||||
import org.toop.framework.eventbus.events.EventsBase;
|
||||
|
||||
public class AppEvents extends EventsBase {
|
||||
public record OnNodeClick() implements EventWithoutSnowflake {}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.toop.app.layer;
|
||||
|
||||
import org.toop.app.events.AppEvents;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
|
||||
@@ -153,7 +152,6 @@ public abstract class Container {
|
||||
public Separator addSeparator(String cssClass, boolean horizontal) {
|
||||
final Separator element = new Separator(horizontal ? Orientation.HORIZONTAL : Orientation.VERTICAL);
|
||||
element.getStyleClass().add(cssClass);
|
||||
element.setMinSize(50, 50);
|
||||
|
||||
addNode(element);
|
||||
return element;
|
||||
|
||||
@@ -96,12 +96,6 @@ public final class TicTacToeLayer extends Layer {
|
||||
}
|
||||
|
||||
final Container controlContainer = new VerticalContainer(5);
|
||||
|
||||
if (information.isPlayerHuman()[0] || information.isConnectionLocal() && information.isPlayerHuman()[1]) {
|
||||
controlContainer.addButton(AppContext.getString("hint"), () -> {
|
||||
});
|
||||
}
|
||||
|
||||
controlContainer.addButton(AppContext.getString("back"), () -> {
|
||||
App.activate(new MainLayer());
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user