Esempio n. 1
0
        public void Handle(IGameCommand command)
        {
            var board = boardManager.FindByConnectionId(command.ConnectionId);

            if (board == null)
            {
                broadcastService.Broadcast(command.ConnectionId, "No active games!");
                return;
            }

            var shootCommand = command as ShootCommand;

            var player    = board.FindPlayer(command.ConnectionId);
            var hitObject = board.ObjectAt(shootCommand.X, shootCommand.Y);

            if (hitObject == null)
            {
                broadcastService.Broadcast(command.ConnectionId, $"BOOM {player.Name} {player.Score}");
                return;
            }

            board.RemoveGameObject(hitObject);
            if (board.GameObjects.Count < 1)
            {
                broadcastService.Broadcast(board, $"Oh no, they are respawning. Now there will be 2 zombies!");
                boardActions.ScheduleNewZombie(board);
                boardActions.ScheduleNewZombie(board, 1000.Random(5000));
            }

            player.Score += 1;

            broadcastService.Broadcast(board, $"BOOM {player.Name} {player.Score} {hitObject.Name}");
        }
Esempio n. 2
0
        public void Handle(IGameCommand command)
        {
            var startGameCommand = command as StartGameCommand;

            var alreadyPlayingOnBoard = boardManager.FindByConnectionId(startGameCommand.ConnectionId);

            if (alreadyPlayingOnBoard != null)
            {
                broadcastService.Broadcast(command.ConnectionId, $"Player {startGameCommand.PlayerName} already playing on board {alreadyPlayingOnBoard.Name}");
                return;
            }

            var board = boardManager.Find(startGameCommand.BoardName);

            if (board == null)
            {
                board = StartNewBoard(startGameCommand.BoardName);
            }

            if (board.IsAlreadyJoined(startGameCommand.ConnectionId))
            {
                broadcastService.Broadcast(command.ConnectionId, $"Player {startGameCommand.PlayerName} already playing on board {board.Name}");
                return;
            }

            board.Join(new Player(startGameCommand.PlayerName, startGameCommand.ConnectionId));
            broadcastService.Broadcast(command.ConnectionId, $"Player {startGameCommand.PlayerName} joined board {board.Name}");
        }
Esempio n. 3
0
        public void Handle(IGameCommand command)
        {
            var board = boardManager.FindByConnectionId(command.ConnectionId);

            if (board == null)
            {
                broadcastService.Broadcast(command.ConnectionId, "No active game");
                return;
            }

            board.RemovePlayer(command.ConnectionId);
            broadcastService.Broadcast(command.ConnectionId, $"You have left game: {board.Name}");
        }
        public void Handle(IGameCommand command)
        {
            var board = boardManager.FindByConnectionId(command.ConnectionId);

            if (board == null)
            {
                broadcastService.Broadcast(command.ConnectionId, "No active game");
                return;
            }
            broadcastService.Broadcast(command.ConnectionId, "All player stats:");
            foreach (var p in board.Players)
            {
                var isMe = p.ConnectionId == command.ConnectionId ? " << you" : "";
                broadcastService.Broadcast(command.ConnectionId, $"Player ({p.ConnectionId}): {p.Name}, Score: {p.Score}{isMe}");
            }
        }