Esempio n. 1
0
 public Player(IBoard primaryBoard, IShootingStrategy shootingStrategy, IFleetCreator fleetCreator, ILogger logger)
 {
     _primaryBoard     = primaryBoard;
     _shootingStrategy = shootingStrategy;
     _fleetCreator     = fleetCreator;
     _logger           = logger;
 }
Esempio n. 2
0
        public Player()
        {
            // Each player has 1 Battleship & 2 Destroyers (currently)
            // TODO - Would be nice to have this as a configuration option
            Ships = new List <Ship>()
            {
                new Destroyer(),
                new Destroyer(),
                new Battleship(),
            };
            // Each player has a board where the ships are placed
            GameBoard = new GameBoard();
            // Each player has a board that keeps track of shots made at the opponents ships
            ShootingBoard = new ShootingBoard();

            // Set up the players shooting strategy..
            ShootingStrategy = new RandomShotStrategy(ShootingBoard); //TODO inject the shooting strategy !
        }
Esempio n. 3
0
        public void GameFactory_CreateNewSinglePlayerGame_CreatesAGameWithHumanAndAComputer_WithBombsLoadedForTheHuman()
        {
            //Arrange
            GameFactory  factory  = new GameFactory();
            GameSettings settings = new GameSettings();
            User         user     = new UserBuilder().WithId().Build();

            //Act
            IGame game = factory.CreateNewSinglePlayerGame(settings, user);

            //Assert
            Assert.That(game, Is.Not.Null, "No instance of a class that implements IGame is returned.");
            Assert.That(game.Id, Is.Not.EqualTo(Guid.Empty), "The Id of the game must be a new Guid (Guid.NewGuid();).");
            Assert.That(game.Settings, Is.SameAs(settings),
                        "The Settings of the game must be a reference to the same Settings object that was passed in as parameter.");

            Assert.That(game.Player1, Is.TypeOf <HumanPlayer>(), "Player 1 must be a HumanPlayer.");
            Assert.That(game.Player1.Id, Is.EqualTo(user.Id), "The Id of Player1 must be the Id of the User that was passed in as parameter.");
            Assert.That(game.Player1.HasBombsLoaded, Is.False, "No player should have bombs loaded after a game is created. " +
                        "Bombs are loaded when a game is started.");

            ComputerPlayer computerPlayer = game.Player2 as ComputerPlayer;

            Assert.That(computerPlayer, Is.Not.Null, "Player 2 must be a ComputerPlayer.");
            Assert.That(computerPlayer.Id, Is.Not.EqualTo(Guid.Empty), "The Id of Player2 must be a new Guid (Guid.NewGuid();).");
            Assert.That(computerPlayer.HasBombsLoaded, Is.False, "No player should have bombs loaded after a game is created. " +
                        "Bombs are loaded when a game is started.");

            IShootingStrategy shootingStrategy = computerPlayer.GetPrivateFieldValue <IShootingStrategy>();

            Assert.That(shootingStrategy, Is.Not.Null, "Cannot find a private field of type IShootingStrategy in the ComputerPlayer class.");

            IGrid opponentGrid = shootingStrategy.GetPrivateFieldValue <IGrid>();

            Assert.That(opponentGrid, Is.Not.Null, "Cannot find a private field of type IGrid in the shooting strategy class.");
            Assert.That(opponentGrid, Is.SameAs(game.Player1.Grid),
                        "The grid used in the shooting strategy of the computer player should be the same instance as the grid of player1 " +
                        "(because player1 is the opponent of the computer player.");
        }
 public ComputerPlayer(GameSettings settings, IShootingStrategy shootingStrategy) : base(Guid.NewGuid(), "Computer", settings)
 {
     this.shootingStrategy = shootingStrategy;
     this.Fleet.RandomlyPositionOnGrid(this.Grid, settings.AllowDeformedShips);
 }
Esempio n. 5
0
 public ComputerPlayer(GameSettings settings, IShootingStrategy shootingStrategy) : base(Guid.NewGuid(), "Computer", settings)
 {
 }