package org.toop; import org.toop.eventbus.Events; import org.toop.eventbus.GlobalEventBus; import org.toop.server.backend.ServerManager; import org.toop.server.frontend.ConnectionManager; import org.toop.server.backend.TcpServer; import org.toop.game.*; import org.toop.game.tictactoe.*; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; import java.io.IOException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; public class Main { private static final Logger logger = LogManager.getLogger(Main.class); public static void main(String[] args) throws ExecutionException, InterruptedException { initSystems(); CompletableFuture serverIdFuture = new CompletableFuture<>(); GlobalEventBus.post(new Events.ServerEvents.StartServerRequest("5001", "tictactoe", serverIdFuture)); String serverId = serverIdFuture.get(); CompletableFuture connectionIdFuture = new CompletableFuture<>(); GlobalEventBus.post(new Events.ServerEvents.StartConnectionRequest("127.0.0.1", "5001", connectionIdFuture)); String connectionId = connectionIdFuture.get(); CompletableFuture ticTacToeGame = new CompletableFuture<>(); GlobalEventBus.post(new Events.ServerEvents.CreateTicTacToeGameRequest(serverId, "J", "P", ticTacToeGame)); String ticTacToeGameId = ticTacToeGame.get(); GlobalEventBus.post(new Events.ServerEvents.RunTicTacToeGame(serverId, ticTacToeGameId)); GlobalEventBus.post(new Events.ServerEvents.SendCommand( connectionId, "gameid " + ticTacToeGameId, "player J", "MOVE", "0" )); GlobalEventBus.post(new Events.ServerEvents.SendCommand( connectionId, "gameid " + ticTacToeGameId, "player P", "MOVE", "1" )); // for (int x = 0; x < 20000000; x++) { // CompletableFuture ticTacToeGame = new CompletableFuture<>(); // GlobalEventBus.post(new Events.ServerEvents.CreateTicTacToeGameRequest(serverId, "J"+x, "P"+x, ticTacToeGame)); // String ticTacToeGameId = ticTacToeGame.get(); // GlobalEventBus.post(new Events.ServerEvents.RunTicTacToeGame(serverId, ticTacToeGameId)); // GlobalEventBus.post(new Events.ServerEvents.Command(connectionId, "MOVE", "" + x)); // } ConsoleGui console = new ConsoleGui(); GameBase.State state = GameBase.State.INVALID; do { console.print(); } while (console.next()); console.print(); } public static void initSystems() { new ServerManager(); new ConnectionManager(); } }