public Game(CellsImage cells) { generationTimer = new System.Timers.Timer(Config.Conf.timerInterval); generationTimer.Elapsed += gameMethod; int w = cells.Cells.GetLength(0); int h = cells.Cells.GetLength(1); Config.Conf.worldSize = new System.Drawing.Size(w, h); lg = new LifeGame(cells.Cells); }
// Constructors public LifeGame(bool[,] cells) { // инициализация полей this.cells = new CellsImage(cells); width = cells.GetLength(0); heigth = cells.GetLength(1); try { this.SetRules(GameRules.Parse(Config.Conf.GameRules)); } catch (Exception) { this.SetRules(GameRules.Conways); } }
/// <summary> /// Загружает игровое поле из файла с изображением (Учитывая текущую цветовую схему!) /// </summary> /// <param name="FileName">Имя файла с изображением</param> /// <returns></returns> public static CellsImage LoadFromImage(string FileName) { using (FileStream fs = new FileStream(FileName, FileMode.Open)) { Bitmap img = new Bitmap(Bitmap.FromStream(fs)); CellsImage c = new CellsImage(); c.Image = img; return c; } }
public void Random() { // размер из конфига System.Drawing.Size s = Config.Conf.worldSize; bool[,] cells = new bool[s.Width, s.Height]; Random r = new Random(); for (int i = 0; i < s.Height; i++) { for (int j = 0; j < s.Width; j++) { cells[j, i] = (r.Next() & 0x01) == 1; } } Cells = new CellsImage(cells); }
public CellsEventArgs(CellsImage c) { cells = c; }
public void Update(CellsImage cells) { lock (this) { lg = new LifeGame(cells); } }