示例#1
0
 internal Game(IGameSetup gameSetup)
 {
     _board = gameSetup.GetSetup();
     CheckDuplications(_board);
     _currentPlayer = PieceColor.White;
     _possibleMoves = GetPossibleMoves(_board, _currentPlayer);
 }
示例#2
0
        public Game1(
            IGameSetup gameSetup,
            IDeltaTimeCalculator deltaTimeCalculator,
            IGameCollection <Entity> entityList,
            IGameCollection <Player> playerList,
            IGameCollection <Bullet> bulletList,
            IPlayerActionManager playerActionManager,
            IBulletMovementManger bulletMovementManger)
        {
            this.gameSetup           = gameSetup;
            graphics                 = new GraphicsDeviceManager(this);
            Content.RootDirectory    = "Content";
            this.deltaTimeCalculator = deltaTimeCalculator;

            // Assets
            assetLoader = new AssetLoader(Content);

            // Collections
            this.entityList = entityList;
            this.playerList = playerList;
            this.bulletList = bulletList;

            // Rendering
            renderingManager = new RenderingManager(assetLoader);

            // Game setup
            playerList.AddListRange(this.gameSetup.SetUpPlayers());
            this.playerActionManager  = playerActionManager;
            this.bulletMovementManger = bulletMovementManger;

            // Window size
            graphics.PreferredBackBufferWidth  = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
            graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
        }
示例#3
0
        public void ShouldCreateAGridWithTheCorrectDimensions(string[,] initialGenerations)
        {
            _gameSetupHandler = new StringArrayGameSetupHandler(initialGenerations);
            var result = _gameSetupHandler.CreateInitialGrid();

            Assert.AreEqual(initialGenerations.GetLength(1), result.Width);
            Assert.AreEqual(initialGenerations.GetLength(0), result.Height);
        }
示例#4
0
        public void ShouldCreateAGridWithTheCorrectNumberOfCells(string[,] initialGenerations)
        {
            var expected = initialGenerations.GetLength(0) * initialGenerations.GetLength(1);

            _gameSetupHandler = new StringArrayGameSetupHandler(initialGenerations);
            var result = _gameSetupHandler.CreateInitialGrid();

            Assert.AreEqual(expected, result.CellGrid.Length);
        }
        public void ShouldThrowErrorIfInputIsOutOfBounds()
        {
            var initialGeneration = new[, ] {
                { "o", "o", "o" }, { "o", "x", "o" }, { "o", "o", "o" }
            };

            _gameSetupHandler = new StringArrayGameSetupHandler(initialGeneration);
            var grid = _gameSetupHandler.CreateInitialGrid();

            Assert.Throws <IndexOutOfRangeException>(() => grid.GetAliveNeighbours(2, 3));
        }
        public void ShouldCountNeighboursCorrectlyForAGridWithTwoNeighbours()
        {
            var initialGeneration = new[, ] {
                { "o", "o", "o", "o" }, { "x", "o", "o", "x" }, { "o", "x", "o", "x" }, { "o", "o", "o", "o" }
            };

            _gameSetupHandler = new StringArrayGameSetupHandler(initialGeneration);
            var grid = _gameSetupHandler.CreateInitialGrid();

            Assert.AreEqual(grid.GetAliveNeighbours(1, 3), 2);
        }
        public void ShouldNotReviveSingleLiveCellWithFourNeighboursOnTheEdge()
        {
            var initialGeneration = new[, ] {
                { "o", "x", "x" }, { "o", "o", "o" }, { "x", "o", "x" }
            };

            _gameSetupHandler = new StringArrayGameSetupHandler(initialGeneration);
            var grid   = _gameSetupHandler.CreateInitialGrid();
            var result = _generationUpdater.CreateNewGeneration(grid);

            Assert.AreEqual(CellStatus.Dead, result.CellGrid[2, 1].CellStatus);
        }
        public void ShouldReviveSingleLiveCellWithThreeNeighbours()
        {
            var initialGeneration = new[, ] {
                { "x", "o", "o" }, { "o", "x", "o" }, { "x", "o", "o" }
            };

            _gameSetupHandler = new StringArrayGameSetupHandler(initialGeneration);
            var grid   = _gameSetupHandler.CreateInitialGrid();
            var result = _generationUpdater.CreateNewGeneration(grid);

            Assert.AreEqual(CellStatus.Alive, result.CellGrid[1, 0].CellStatus);
        }
        public void ShouldKillSingleLiveCellOnTheEdgeOfALargeBoard()
        {
            var initialGeneration = new[, ] {
                { "o", "o", "o", "o", "o" }, { "o", "o", "o", "o", "o" }, { "o", "o", "o", "o", "x" }
            };

            _gameSetupHandler = new StringArrayGameSetupHandler(initialGeneration);
            var grid   = _gameSetupHandler.CreateInitialGrid();
            var result = _generationUpdater.CreateNewGeneration(grid);

            Assert.AreEqual(CellStatus.Dead, result.CellGrid[2, 2].CellStatus);
            Assert.AreEqual(CellStatus.Dead, result.CellGrid[2, 4].CellStatus);
        }
示例#10
0
        public void ShouldCreateAGridWithTheAccurateCellStatusesOnUnevenYAxisBoard()
        {
            var initialGeneration = new[, ] {
                { "o", "o", "o", "x" }, { "o", "o", "o", "o" }, { "x", "o", "x", "o" }
            };

            _gameSetupHandler = new StringArrayGameSetupHandler(initialGeneration);
            var result = _gameSetupHandler.CreateInitialGrid();

            Assert.AreEqual(CellStatus.Alive, result.CellGrid[0, 3].CellStatus);
            Assert.AreEqual(CellStatus.Dead, result.CellGrid[1, 0].CellStatus);
            Assert.AreEqual(CellStatus.Dead, result.CellGrid[0, 2].CellStatus);
            Assert.AreEqual(CellStatus.Alive, result.CellGrid[2, 2].CellStatus);
            Assert.AreEqual(CellStatus.Alive, result.CellGrid[2, 0].CellStatus);
        }
示例#11
0
        public void ShouldCreateAGridWithAllCellStatusesAlive()
        {
            var initialGeneration = new[, ] {
                { "x", "x", "x" }, { "x", "x", "x" }, { "x", "x", "x" }
            };

            _gameSetupHandler = new StringArrayGameSetupHandler(initialGeneration);
            var result = _gameSetupHandler.CreateInitialGrid();

            Assert.AreEqual(CellStatus.Alive, result.CellGrid[0, 0].CellStatus);
            Assert.AreEqual(CellStatus.Alive, result.CellGrid[0, 1].CellStatus);
            Assert.AreEqual(CellStatus.Alive, result.CellGrid[0, 2].CellStatus);
            Assert.AreEqual(CellStatus.Alive, result.CellGrid[1, 0].CellStatus);
            Assert.AreEqual(CellStatus.Alive, result.CellGrid[1, 1].CellStatus);
            Assert.AreEqual(CellStatus.Alive, result.CellGrid[1, 2].CellStatus);
            Assert.AreEqual(CellStatus.Alive, result.CellGrid[2, 0].CellStatus);
            Assert.AreEqual(CellStatus.Alive, result.CellGrid[2, 1].CellStatus);
            Assert.AreEqual(CellStatus.Alive, result.CellGrid[2, 2].CellStatus);
        }
示例#12
0
 public GetShootStatusQueryHandler(IGameSetup gs)
 {
     gameSetup = gs;
 }
 public GetPlayersQueryHandler(IGameSetup gs)
 {
     gameSetup = gs;
 }
 public CreatePlayerCommandHandler(IGameSetup gs)
 {
     gameSetup = gs;
 }
 public GetshipListQueryHandler(IGameSetup gs)
 {
     gameSetup = gs;
 }
示例#16
0
 public GetWinnerQueryHandler(IGameSetup gs)
 {
     gameSetup = gs;
 }
 public GetScoresQueryHandler(IGameSetup gs)
 {
     gameSetup = gs;
 }