/** * setup all variables when entering this state. * * @param container the Container this state is part of * @param arg1 The statebasedgame this state is part of * @throws SlickException sometimes. */ @Override public void enter(GameContainer container, StateBasedGame arg1) throws SlickException { Logger.getInstance().log("Entering MenuMultiplayerState", Logger.PriorityLevels.LOW, "States"); RND.getInstance().setOpacity(0.0f); elements.reset(); mainGame.stopSwitchState(); SoundPlayer.getInstance().setActiveList(MusicLists.MENU_LIST); }
/** Attempt to host a game. */ private void attemptHost() { mainGame.killMultiplayer(); mainGame.setLanMultiplayer(true); processPlayerHost(); mainGame.resetLifeCount(); mainGame.resetLevelCount(); mainGame.setScore(0); mainGame.spawnHost(new Host(MainGame.getMultiplayerPort(), mainGame, gameState)); mainGame.setIsHost(true); mainGame.setIsClient(false); Logger.getInstance().log("Host started", Logger.PriorityLevels.VERYHIGH, "multiplayer"); }
/** Attempt to join a game. */ private void attemptJoin() { mainGame.killMultiplayer(); mainGame.setLanMultiplayer(true); processPlayerClient(); mainGame.resetLifeCount(); mainGame.resetLevelCount(); mainGame.setScore(0); Client client = new Client(ipField.getText(), MainGame.getMultiplayerPort(), mainGame, gameState); mainGame.spawnClient(client); mainGame.setIsClient(true); mainGame.setIsHost(false); Logger.getInstance().log("Client started", Logger.PriorityLevels.VERYHIGH, "multiplayer"); }
/** * Exit function for state. Fades out and everything. * * @param container the GameContainer we are running in * @param sbg the gamestate cont. * @param delta the deltatime in ms */ public void exit(GameContainer container, StateBasedGame sbg, int delta) { if (mainGame.getShouldSwitchState()) { if (RND.getInstance().getOpacity() > 0.0f) { RND.getInstance() .setOpacity( RND.getInstance().getOpacity() - ((float) delta) / mainGame.getOpacityFadeTimer()); } else { Logger.getInstance() .log("Exiting MenuMultiplayerState", Logger.PriorityLevels.LOW, "States"); if (mainGame.getSwitchState() == -1) { container.exit(); } else { mainGame.switchColor(); sbg.enterState(mainGame.getSwitchState()); } } } }