Beispiel #1
0
        public void TearDown()
        {
            TestObjects.ThreexThreeGrid.GetCellByIndex(0, 0).IsAlive = false;
            TestObjects.ThreexThreeGrid.GetCellByIndex(0, 1).IsAlive = false;
            TestObjects.ThreexThreeGrid.GetCellByIndex(0, 2).IsAlive = false;
            TestObjects.ThreexThreeGrid.GetCellByIndex(1, 0).IsAlive = false;
            TestObjects.ThreexThreeGrid.GetCellByIndex(1, 1).IsAlive = false;
            TestObjects.ThreexThreeGrid.GetCellByIndex(1, 2).IsAlive = false;
            TestObjects.ThreexThreeGrid.GetCellByIndex(2, 0).IsAlive = false;
            TestObjects.ThreexThreeGrid.GetCellByIndex(2, 1).IsAlive = false;
            TestObjects.ThreexThreeGrid.GetCellByIndex(2, 2).IsAlive = false;
            //D D D
            //D D D
            //D D D

            _neighbourCalculator = null;
            _deadCellRule = null;
        }
Beispiel #2
0
 public void SetUp()
 {
     _neighbourCalculator = new NeighbourCalculator { Grid = TestObjects.ThreexThreeGrid };
     _deadCellRule = new DeadCellRule{Grid = TestObjects.ThreexThreeGrid, NeighbourCalculator = _neighbourCalculator};
 }
Beispiel #3
0
        /// <summary>
        /// Updates the is alive state of all cells.
        /// </summary>
        /// <param name="rule">The rule to determine the alive state of the cell with.</param>
        public void UpdateCells(ICellRule rule)
        {
            bool[] newValues = new bool[rows * columns];

            int x;
            int y;

            for (int i = 0; i < cells.Length; i++)
            {
                y = i / columns;
                x = i % columns;

                newValues[i] = GetCellValue(cells[i], x, y, rule);
            }

            cells = newValues;
        }
Beispiel #4
0
        private bool GetCellValue(bool cell, int currX, int currY, ICellRule rule)
        {
            int livingNeighbours = 0;

            for (int dX = -1; dX <= 1; dX++)
            {
                for (int dY = -1; dY <= 1; dY++)
                {
                    if (!(dX == 0 && dY == 0)
                        && GetCellAt(currY + dY, currX + dX))
                    {
                        livingNeighbours++;
                    }
                }
            }

            return rule.GetAliveState(cell, livingNeighbours);
        }
Beispiel #5
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            field = new Field(400, 400);
            fieldInitializer = new RandomFieldInitializer();
            rule = new RegularCellRule();
            InitializeStartPopulation();

            int fieldWidth = graphics.PreferredBackBufferWidth / field.Columns;
            int fieldHeight = graphics.PreferredBackBufferHeight / field.Rows;

            InitializeRectangles(fieldWidth, fieldHeight);

            base.Initialize();
        }