public ReadUserGuessService(IBattleshipsConfiguration configuration,
                             IConvertCharService charService
                             )
 {
     _charService   = charService;
     _configuration = configuration;
 }
示例#2
0
 public ShowGameStateService(IConvertCharService charService,
                             IConsole console,
                             IBattleshipsConfiguration configuration,
                             ICellMapper mapper)
 {
     _charService   = charService;
     _console       = console;
     _configuration = configuration;
     _mapper        = mapper;
 }
 public BattleshipStateBuilder(IReadUserGuess guessReader,
                               IBattleshipsConfiguration configuration,
                               IDetectColisionService detectCollisionService,
                               ICellMapper mapper,
                               IRandom randomService)
 {
     _guessReader            = guessReader;
     _configuration          = configuration;
     _detectCollisionService = detectCollisionService;
     _mapper = mapper;
     _random = randomService;
 }
示例#4
0
        public CellMapper(IBattleshipsConfiguration configuration)
        {
            _cellStatesAfterHit = new[] { BattleshipGridCell.Miss, BattleshipGridCell.Hit };
            _configuration      = configuration;

            // cannot be static, depend on configuration which is injectable
            _displayMappings = new Dictionary <BattleshipGridCell, char>
            {
                { BattleshipGridCell.Empty, _configuration.Empty },
                { BattleshipGridCell.Ship, _configuration.Empty },
                { BattleshipGridCell.Miss, _configuration.Miss },
                { BattleshipGridCell.Hit, _configuration.Hit }
            };
        }
示例#5
0
        public void SetUp()
        {
            _guessService  = Substitute.For <IReadUserGuess>();
            _config        = Substitute.For <IBattleshipsConfiguration>();
            _randomService = Substitute.For <IRandom>();
            _config.GridSize.Returns(gridSize);
            _detectCollisionService = Substitute.For <IDetectColisionService>();
            var mapper = Substitute.For <ICellMapper>();

            mapper.NewCellState(BattleshipGridCell.Empty).Returns(BattleshipGridCell.Miss);
            mapper.NewCellState(BattleshipGridCell.Ship).Returns(BattleshipGridCell.Hit);

            _servceUnderTest = new BattleshipStateBuilder(
                _guessService,
                _config,
                _detectCollisionService,
                mapper,
                _randomService);
        }
示例#6
0
        public static ContainerBuilder GetContainerBuilder(IBattleshipsConfiguration configuration)
        {
            var builder = new ContainerBuilder();

            // configurations
            builder.RegisterInstance(configuration).As <IBattleshipsConfiguration>();
            // I/O wrappers
            builder.RegisterType <Battleships.Services.Console>().As <IConsole>();
            // services
            builder.RegisterType <BattleshipGame>().As <IBattleshipGame>();
            builder.RegisterType <BattleshipStateBuilder>().As <IBattleshipStateBuilder>();
            builder.RegisterType <ConvertCharService>().As <IConvertCharService>();
            builder.RegisterType <RandomService>().As <IRandom>();
            builder.RegisterType <DetectColisionService>().As <IDetectColisionService>();
            builder.RegisterType <ShowGameStateService>().As <IShowGameState>();
            builder.RegisterType <ReadUserGuessService>().As <IReadUserGuess>();
            builder.RegisterType <CellMapper>().As <ICellMapper>();

            return(builder);
        }
示例#7
0
 public RandomService(IBattleshipsConfiguration configuration)
 {
     _configuration = configuration;
     _random        = new Random();
 }
示例#8
0
        public static IContainer GetContainer(IBattleshipsConfiguration configuration)
        {
            ContainerBuilder builder = GetContainerBuilder(configuration);

            return(builder.Build());
        }