Beispiel #1
0
 // Hidden cells around cell with given indexes
 public void createHiddenCells(int x, int y)
 {
     int[][] CellsIndexes = Board.generateNeighbourIndexes(x, y);
     foreach (int[] i in CellsIndexes)
     {
         if (!this.storage.ContainsKey(i[0]))
         {
             this.storage.Add(i[0], new Dictionary <int, Cell> {
             });
             this.storage[i[0]].Add(i[1], new Cell(i[0], i[1], highlightCell.body.Size, false));
         }
         else if (!this.storage[i[0]].ContainsKey(i[1]))
         {
             this.storage[i[0]].Add(i[1], new Cell(i[0], i[1], highlightCell.body.Size, false));
         }
     }
 }
Beispiel #2
0
            // Sumulates the game
            public void simulate()
            {
                List <Cell> dead   = new List <Cell> {
                };
                List <Cell> toHide = new List <Cell> {
                };
                List <Cell> toShow = new List <Cell> {
                };

                // Looking for changes
                foreach (KeyValuePair <int, Dictionary <int, Cell> > nd in this.storage)
                {
                    foreach (KeyValuePair <int, Cell> n in nd.Value)
                    {
                        if (n.Value.isAlive)
                        {
                            int[][] CellsIndexes     = Board.generateNeighbourIndexes(nd.Key, n.Key);
                            int     activeCellsCount = 0;
                            foreach (int[] i in CellsIndexes)
                            {
                                Cell nRef = this.storage[i[0]][i[1]];
                                if (nRef.isAlive)
                                {
                                    activeCellsCount++;
                                }
                                else if (!dead.Contains(nRef))
                                {
                                    dead.Add(nRef);
                                }
                            }
                            if (!(activeCellsCount == 2 || activeCellsCount == 3))
                            {
                                toHide.Add(n.Value);
                            }
                        }
                    }
                }
                foreach (Cell n in dead)
                {
                    int[][] deadCellsInNdexes   = Board.generateNeighbourIndexes(n.indexes[0], n.indexes[1]);
                    int     aciveDeadCellsCount = 0;
                    foreach (int[] j in deadCellsInNdexes)
                    {
                        if (this.storage.ContainsKey(j[0]) && this.storage[j[0]].ContainsKey(j[1]) && this.storage[j[0]][j[1]].isAlive)
                        {
                            aciveDeadCellsCount++;
                        }
                    }
                    if (aciveDeadCellsCount == 3)
                    {
                        toShow.Add(n);
                    }
                }

                // Applying changes
                foreach (Cell n in toShow)
                {
                    if (n.isNew)
                    {
                        n.changeState();
                        n.reSize(cellSize);
                        createHiddenCells(n.indexes[0], n.indexes[1]);
                        n.isNew = false;
                    }
                    else
                    {
                        n.changeState();
                        n.reSize(cellSize);
                    }
                }
                foreach (Cell n in toHide)
                {
                    n.changeState();
                }
                toShow.Clear();
                toHide.Clear();
                dead.Clear();
            }