예제 #1
0
        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.");
            }
        }
예제 #2
0
 private static void startGame(GameState gs)
 {
     gameStarted = true;
     gs.startGame();
     Console.WriteLine("A game has started in " + gs.roomName + ".  Good luck and have fun!");
 }
예제 #3
0
 public static void startStopGame(GameState gameState)
 {
     if (gameState.playerList.Count > 1 && !gameState.gameStarted)
     {
         startGame(gameState);
     }
     if(gameState.playerList.Count < 1)
     {
         gameState.gameStarted = false;
     }
 }
예제 #4
0
 public static void roomUpdateToAllPlayers(GameState roomUpdated)
 {
     foreach (Player p in playerList)
     {
         p.sendCommand(Command.roomUpdateCommand(0, roomUpdated));
     }
 }
예제 #5
0
        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;
        }
예제 #6
0
        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;
        }