예제 #1
0
        protected bool DoesCellLive(int X, int Y, LifeGrid grid)
        {
            bool result = grid.DoesCellLive(X, Y);

            if (fOnDoesCellLive != null)
            {
                fOnDoesCellLive(this, X, Y, grid, ref result);
            }
            return(result);
        }
예제 #2
0
        public LifeViewer()
        {
            DoubleBuffered = true;

            fOptions       = new LifeOptions();
            fRules         = new LifeRules();
            fGrid          = new LifeGrid(LifeConsts.DefaultGridWidth, LifeConsts.DefaultGridHeight);
            fHistory       = new LifeHistory(LifeConsts.DefaultNumberOfHistoryLevels);
            fGridLineColor = LifeConsts.DefaultGridLineColor;
            fGridLineStyle = LifeConsts.DefaultGridLineStyle;
        }
예제 #3
0
        public int Contains(LifeGrid grid)
        {
            int result = 0;

            while ((result < fList.Count) && !grid.Equals(this[result]))
            {
                result++;
            }
            if (result >= fList.Count)
            {
                result = -1;
            }

            return(result);
        }
예제 #4
0
        public LifeGrid Add(LifeGrid grid)
        {
            if (fList.Count < fList.Capacity)
            {
                fList.Add(new LifeGrid());
                fMostRecent = fList.Count - 1;
            }
            else
            {
                fMostRecent = (fMostRecent + 1) % Count;
            }

            LifeGrid result = fList[fMostRecent];

            result.Assign(grid);
            return(result);
        }
예제 #5
0
        public int NextGeneration()
        {
            LifeGrid MostRecentGrid = fHistory.Add(fGrid);

            for (int y = 0; y < GridHeight; y++)
            {
                for (int x = 0; x < GridWidth; x++)
                {
                    bool live = DoesCellLive(x, y, MostRecentGrid);
                    SetCell(x, y, (short)((live) ? 1 : 0));
                }
            }

            fGeneration++;
            Change();

            int result = fHistory.Contains(fGrid) + 1;

            return(result);
        }