Beispiel #1
0
        /// <summary>
        /// Handles setting up a new bomb by a player
        /// </summary>
        /// <param name="client">Client that sent the set bomb command</param>
        /// <param name="receivedMessage">The set bomb command with parameters</param>
        public void SetBomb(Client client, ClientBombSet update)
        {
            Bomb bomb = null;

            // Check if player is allowed to set more bombs
            lock (_bombs)
            {
                int bombcount = _bombs.Count(bmb => bmb.OwnerColor == client.LocalPlayer.Color);

                if (bombcount >= client.LocalPlayer.BombNumber)
                {
                    Console.WriteLine("Too many bombs set.");
                    return;
                }


                Point position = Util.ToGridCoordinates(new Point(update.X, update.Y));

                // Check if there's already bomb on current position

                int bombsHere = _bombs.Count(bmb => bmb.Position == position);

                if (bombsHere > 0)
                {
                    Console.WriteLine("Bomb already exists on this position.");
                    return;
                }


                // Create new bomb
                bomb = new Bomb(position, client.LocalPlayer.ManualTrigger ? 0 : 2000, client.LocalPlayer.BombRange, client.LocalPlayer.Color);


                _bombs.Add(bomb);
            }

            // Notify all clients about the new bomb
            lock (_clients)
            {
                Player[] players          = (from cl in _clients select cl.LocalPlayer).ToArray();
                Point    absolutePosition = Util.ToRealCoordinates(bomb.Position);

                foreach (Client cl in _clients)
                {
                    cl.SendStatusUpdate(new GameStatusUpdate(players, Command.BombSet, absolutePosition.X, absolutePosition.Y));
                }
            }
        }
Beispiel #2
0
        private IClientUpdate GetUpdate(byte[] buffer, int offset, int length)
        {
            MemoryStream ms = new MemoryStream(buffer, offset, length);

            ClientMessageTypes msgType = (ClientMessageTypes)ms.ReadByte();

            switch (msgType)
            {
            case ClientMessageTypes.StatusUpdate:
                ClientStatusUpdate statusUpdate = Serializer.DeserializeWithLengthPrefix <ClientStatusUpdate>(ms, PrefixStyle.Base128);
                return(statusUpdate);

            case ClientMessageTypes.PositionUpdate:
                ClientPositionUpdate positionUpdate = Serializer.DeserializeWithLengthPrefix <ClientPositionUpdate>(ms, PrefixStyle.Base128);
                return(positionUpdate);

            case ClientMessageTypes.BombSet:
                ClientBombSet bombSetUpdate = Serializer.DeserializeWithLengthPrefix <ClientBombSet>(ms, PrefixStyle.Base128);
                return(bombSetUpdate);
            }

            return(null);
        }
Beispiel #3
0
        public void SendBombSetNotify(Point location)
        {
            ClientBombSet update = new ClientBombSet((int)location.X, (int)(location.Y - 8));

            SendResponse(update);
        }