Пример #1
0
        public ShootResponse Shoot(ShootRequest shootRequest, PlayerState playerState)
        {
            var x             = shootRequest.X - 1;
            var y             = shootRequest.Y - 1;
            var shootResponse = new ShootResponse
            {
                IsHit = playerState.Field[x, y] == Constants.FieldShipSymbol
            };

            playerState.Field[x, y] = shootResponse.IsHit
                                ? Constants.FieldShipSinkSymbol
                                : Constants.FieldHitSymbol;

            shootResponse.PlayerState = playerState;
            return(shootResponse);
        }
Пример #2
0
        public ShootResponse Shoot(ShootRequest shootRequest)
        {
            var x             = shootRequest.X - 1;
            var y             = shootRequest.Y - 1;
            var shootResponse = new ShootResponse
            {
                IsHit = shootRequest.Field[x, y] == Constants.FieldShipSymbol
            };

            shootRequest.Field[x, y] = shootResponse.IsHit
                                ? Constants.FieldShipSinkSymbol
                                : Constants.FieldHitSymbol;

            var ships = shootRequest.Field.Cast <char>().Count(symbol => symbol == Constants.FieldShipSymbol);

            shootResponse.Field    = shootRequest.Field;
            shootResponse.IsWinner = ships == 0;
            return(shootResponse);
        }