Ejemplo n.º 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"));
            }
        }
Ejemplo n.º 2
0
        private MSG_Game _get_MSG_Game()
        {
            MSG_Game game = new MSG_Game();

            game.ID     = this._id;
            game.By     = this._player1.Login;
            game.Name   = this._name;
            game.Width  = this._width;
            game.Height = this._height;
            game.Boats  = this._boats;

            return(game);
        }
Ejemplo n.º 3
0
        public OBJ_Game(Guid guid, OBJ_Client creator, MSG_Game game = null)
        {
            this._id      = guid;
            this._player1 = creator;
            this._boats   = new Dictionary <int, int>();

            if (null != game)
            {
                this._name   = game.Name;
                this._width  = game.Width > 20 ? 20 : game.Width;
                this._height = game.Height > 20 ? 20 : game.Width;
                this._boats  = game.Boats;
            }
        }
Ejemplo n.º 4
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"));
            }
        }