mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Fixed bugs, easy to use host button
This commit is contained in:
@@ -20,15 +20,8 @@ import org.toop.framework.audio.*;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.eventbus.GlobalEventBus;
|
||||
import org.toop.framework.game.BitboardGame;
|
||||
import org.toop.framework.game.games.reversi.BitboardReversi;
|
||||
import org.toop.framework.game.games.tictactoe.BitboardTicTacToe;
|
||||
import org.toop.framework.gameFramework.model.game.TurnBasedGame;
|
||||
import org.toop.framework.networking.connection.NetworkingClientEventListener;
|
||||
import org.toop.framework.networking.connection.NetworkingClientManager;
|
||||
import org.toop.framework.networking.server.GameDefinition;
|
||||
import org.toop.framework.networking.server.MasterServer;
|
||||
import org.toop.framework.networking.server.Server;
|
||||
import org.toop.framework.resource.ResourceLoader;
|
||||
import org.toop.framework.resource.ResourceManager;
|
||||
import org.toop.framework.resource.events.AssetLoaderEvents;
|
||||
@@ -38,9 +31,7 @@ import org.toop.framework.resource.resources.SoundEffectAsset;
|
||||
import org.toop.local.AppContext;
|
||||
import org.toop.local.AppSettings;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -101,17 +92,6 @@ public final class App extends Application {
|
||||
|
||||
WidgetContainer.setCurrentView(loading);
|
||||
|
||||
var games = new ConcurrentHashMap<String, Class<? extends TurnBasedGame>>();
|
||||
games.put("tictactoe", BitboardTicTacToe.class);
|
||||
games.put("reversi", BitboardReversi.class);
|
||||
|
||||
var a = new MasterServer(6666, games, Duration.ofSeconds(5));
|
||||
try {
|
||||
a.start();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
setOnLoadingSuccess(loading);
|
||||
|
||||
EventFlow loadingFlow = new EventFlow();
|
||||
|
||||
@@ -263,7 +263,7 @@ public final class Server {
|
||||
String gameType = extractQuotedValue(response.gameType());
|
||||
final String finalGameType = gameType;
|
||||
var a = new ChallengePopup(challengerName, gameType, (playerInformation) -> {
|
||||
final int challengeId = Integer.parseInt(response.challengeId().replaceAll("\\D", ""));
|
||||
final long challengeId = Long.parseLong(response.challengeId().replaceAll("\\D", ""));
|
||||
new EventFlow().addPostEvent(new NetworkEvents.SendAcceptChallenge(clientId, challengeId)).postEvent();
|
||||
isSingleGame.set(true);
|
||||
});
|
||||
|
||||
@@ -6,6 +6,13 @@ import org.toop.app.widget.complex.LabeledInputWidget;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import org.toop.framework.game.games.reversi.BitboardReversi;
|
||||
import org.toop.framework.game.games.tictactoe.BitboardTicTacToe;
|
||||
import org.toop.framework.gameFramework.model.game.TurnBasedGame;
|
||||
import org.toop.framework.networking.server.MasterServer;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class OnlineView extends ViewWidget {
|
||||
public OnlineView() {
|
||||
@@ -23,6 +30,28 @@ public class OnlineView extends ViewWidget {
|
||||
);
|
||||
});
|
||||
|
||||
var localHostButton = Primitive.button("host!", () -> {
|
||||
var games = new ConcurrentHashMap<String, Class<? extends TurnBasedGame>>();
|
||||
games.put("tictactoe", BitboardTicTacToe.class);
|
||||
games.put("reversi", BitboardReversi.class);
|
||||
|
||||
var a = new MasterServer(6666, games, Duration.ofSeconds(10));
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
a.start();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}).start();
|
||||
|
||||
new Server(
|
||||
"127.0.0.1",
|
||||
"6666",
|
||||
"host"
|
||||
);
|
||||
}, false);
|
||||
|
||||
add(Pos.CENTER, Primitive.vbox(
|
||||
serverInformationHeader,
|
||||
Primitive.separator(),
|
||||
@@ -32,7 +61,9 @@ public class OnlineView extends ViewWidget {
|
||||
playerNameInput.getNode(),
|
||||
Primitive.separator(),
|
||||
|
||||
connectButton
|
||||
connectButton,
|
||||
Primitive.separator(),
|
||||
localHostButton
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user