Beispiel #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();
            }
        }
Beispiel #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();
            }
        }
Beispiel #3
0
        public void Unregister(Player player)
        {
            lock (SynchronizationLock)
            {
                if (_unregisteredPlayers.Contains(player))
                {
                    return;
                }

                _registeredPlayers.Remove(player);

                if (!_unregisteredPlayers.Contains(player))
                {
                    _unregisteredPlayers.Add(player);
                }
            }
        }
Beispiel #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();
            }
        }
Beispiel #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);
     }
 }
Beispiel #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;
        }
Beispiel #7
0
        public override CommandResponseDto Execute(Player player, IGame game)
        {
            player.PlayerDecisions.Velocity = _direction;

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

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

            return Success;
        }