private static void startServer() { if(gss != null) { Console.WriteLine("Game is already in progress. Please reset or quit to start a new game."); } else { gss = new GameState[NUMBER_OF_GAMES]; gameStarted = false; string[] names = new string[] {"Butterflies","Hurricanes","Black Holes","Revelations","Stockholm","Syndrome"}; for (int i = 0; i < NUMBER_OF_GAMES; i++ ) { gss[i] = new GameState(names[i], i);//"Foo foo for you " + i, i); } listener = new PlayerListener(); Console.WriteLine("The server is up, players can now connect."); } }
private static void startGame(GameState gs) { gameStarted = true; gs.startGame(); Console.WriteLine("A game has started in " + gs.roomName + ". Good luck and have fun!"); }
public static void startStopGame(GameState gameState) { if (gameState.playerList.Count > 1 && !gameState.gameStarted) { startGame(gameState); } if(gameState.playerList.Count < 1) { gameState.gameStarted = false; } }
public static void roomUpdateToAllPlayers(GameState roomUpdated) { foreach (Player p in playerList) { p.sendCommand(Command.roomUpdateCommand(0, roomUpdated)); } }
public static Command roomUpdateCommand(long ts, GameState gs) { Command newCommand = new Command(); newCommand.timeStamp = ts; newCommand.cType = CType.RoomUpdate; newCommand.message = newCommand.cType + ":" + ts + ":" + gs.roomID +":" + gs.playerList.Count + ";"; return newCommand; }
public static Command loginCommand(long ts, LoginResponseType t, GameState[] gss) { Command newCommand = new Command(); newCommand.timeStamp = ts; newCommand.cType = CType.Login; newCommand.loginResponse = t; newCommand.message = newCommand.cType + ":" + t; newCommand.message += ":" + gss.Length; if((newCommand.loginResponse & LoginResponseType.SucceededLogin) != 0) { foreach (GameState gs in gss) { newCommand.message += ":" + gs.roomName + ":" + gs.numberOfPlayers(); } } newCommand.message += ";"; return newCommand; }