Пример #1
0
        public override void Validate(Player player, IGame game)
        {
            if (!game.IsStarted)
            {
                throw new GameNotStartedException();
            }

            if (player.Blobs.Count > 0 || player.Join)
            {
                throw new AlreadyJoinedException();
            }
        }
Пример #2
0
        public override void Validate(Player player, IGame game)
        {
            if (!game.IsStarted)
            {
                throw new GameNotStartedException();
            }

            if (!player.Blobs.Any() && !player.Join)
            {
                throw new NotJoinedException();
            }
        }
Пример #3
0
        public void Unregister(Player player)
        {
            lock (SynchronizationLock)
            {
                if (_unregisteredPlayers.Contains(player))
                {
                    return;
                }

                _registeredPlayers.Remove(player);

                if (!_unregisteredPlayers.Contains(player))
                {
                    _unregisteredPlayers.Add(player);
                }
            }
        }
Пример #4
0
        public override void Validate(Player player, IGame game)
        {
            if (!game.IsStarted)
            {
                throw new GameNotStartedException();
            }

            if (!player.Blobs.Any() && !player.Join)
            {
                throw new NotJoinedException();
            }

            if (player.Blobs.All(blob => blob.Mass < game.Settings.MinMassEject))
            {
                throw new TooLowMassException();
            }
        }
Пример #5
0
 public async Task RunAsync(
     StreamReader reader,
     StreamWriter writer,
     CancellationTokenSource cancellationTokenSource)
 {
     _player = _playerRepository.Register(_loginDto.Login, _loginDto.Password);
     try
     {
         var handleIncomingDataTask = HandleIncomingDataAsync(reader, cancellationTokenSource.Token);
         var handleOutgoingDataTask = HandleOutgoingDataAsync(writer, cancellationTokenSource.Token);
         await Task.WhenAny(handleIncomingDataTask, handleOutgoingDataTask).ConfigureAwait(false);
         cancellationTokenSource.Cancel();
         await Task.WhenAll(handleIncomingDataTask, handleOutgoingDataTask).ConfigureAwait(false);
     }
     finally
     {
         _playerRepository.Unregister(_player);
     }
 }
Пример #6
0
        public override CommandResponseDto Execute(Player player, IGame game)
        {
            var visibleBlobs = new HashSet<Blob>();

            player.WaitForTick();

            foreach (var playerBlob in player.Blobs)
            {
                var radius = playerBlob.Radius * game.Settings.VisibilityFactor;
                _physics.ForBlobsInRange(playerBlob.Position, radius, blob => visibleBlobs.Add(blob));
            }

            var playerViewDto = new GetViewResponseDto
            {
                Blobs = Mapper.Map<BlobDto[]>(visibleBlobs)
            };

            return playerViewDto;
        }
Пример #7
0
        public override CommandResponseDto Execute(Player player, IGame game)
        {
            player.PlayerDecisions.Velocity = _direction;

            return Success;
        }
Пример #8
0
 public abstract void Validate(Player player, IGame game);
Пример #9
0
 public abstract CommandResponseDto Execute(Player player, IGame game);
Пример #10
0
        public override CommandResponseDto Execute(Player player, IGame game)
        {
            player.Join = true;

            return Success;
        }
Пример #11
0
        public override CommandResponseDto Execute(Player player, IGame game)
        {
            player.PlayerDecisions.Activity = Activity.EjectMass;

            return Success;
        }