示例#1
0
        private void _actionCreateGame(OBJ_Client from, MSG_MESSAGE message)
        {
            // if user is Logged
            if (from.Login != null)
            {
                Guid     guid       = Guid.NewGuid();
                MSG_Game createGame = (MSG_Game)message.Values;

                while (this._games.ContainsKey(guid))
                {
                    guid = Guid.NewGuid();
                }

                OBJ_Game game = new OBJ_Game(guid, from, createGame);
                this._games.Add(guid, game);

                from.send(new MSG_MESSAGE("GAME_JOINED", game));
            }

            // User not logged.
            else
            {
                from.send(new MSG_MESSAGE("ERROR", "Please connect before"));
            }
        }
示例#2
0
        private void _actionJoinGame(OBJ_Client from, MSG_MESSAGE message)
        {
            // if user is Logged
            if (from.Login != null)
            {
                MSG_Game game = (MSG_Game)message.Values;

                // If game exist.
                if (this._games.ContainsKey(game.ID))
                {
                    OBJ_Game selectedGame = this._games[game.ID];

                    // If game is free
                    if (null == selectedGame.Player2)
                    {
                        selectedGame.Player2 = from;
                        selectedGame.Player1.send(new MSG_MESSAGE("PLAYER_CONNECTED", from.Login));
                        from.send(new MSG_MESSAGE("GAME_JOINED", game));
                    }

                    // if game is full
                    else
                    {
                        from.send(new MSG_MESSAGE("ERROR", "Game is full"));
                    }
                }

                // If game not exist.
                else
                {
                    from.send(new MSG_MESSAGE("ERROR", "Game not exist"));
                }
            }

            // User not logged.
            else
            {
                from.send(new MSG_MESSAGE("ERROR", "Please connect before"));
            }
        }