private void Form1_Load(object sender, EventArgs e) { n = 40; deltaX = this.Height / n; deltaY = this.Width / n; life = new Life(40, 200); tokenSource = new CancellationTokenSource(); CancellationToken ct = tokenSource.Token; // C# var t = Task.Factory.StartNew(() => { while(true) { //evaluate life with for subtask life.Evaluate(4); alife = life.GetUniversity().ToBoolArray(); Invalidate(); Thread.Sleep(500); //if cancel if (ct.IsCancellationRequested) { ct.ThrowIfCancellationRequested(); } } }, tokenSource.Token); //pass cancelation token to task }
static void Main(string[] args) { string[] fileStrings = File.ReadAllLines("LifeGameInitial.txt"); //int Height = File.ReadAllLines("LifeGameInitial.txt").Length; int Height = File.ReadLines(@"LifeGameInitial.txt").Count(); int Width = File.ReadAllLines(@"LifeGameInitial.txt")[0].Length; Life life = new Life(Height, Width, true); string consoleAnswer = "N"; VladBolotin vb = new VladBolotin(); do { int i = 1; int MaxCount = 100; Console.WriteLine("Game life started"); Console.WriteLine("How many steps in the game ?"); MaxCount = Convert.ToInt32(Console.ReadLine()); //life.initCurrentArray.initFillSomeColony(); // test case //life.initCurrentArray.initFill3PointsInLine(); // test case if (life.IsInitFromFile) { life.initCurrentArray.FromFile(); } else { life.initCurrentArray.FillSomeColony(); } vb.initFillAllZero(); vb.InitState(); //life.showArray(life.CurrentArray); //Console.ReadLine(); do { Console.Clear(); Console.WriteLine("step " + i.ToString() + "/" + MaxCount.ToString()); if (!life.Next()) { Console.WriteLine("Apocalypsis happened"); break; } vb.NextState(); Console.WriteLine("Stas Vlad"); for (int k = 0; k < life.W; k++) { Console.Write("-"); } Console.WriteLine(); //life.showArray(life.NextArray); life.showBothArrays(life.NextArray, vb.LifeArrayNextStep); Console.WriteLine(); for (int k = 0; k < life.W; k++) { Console.Write("-"); } i++; Thread.Sleep(6000); }while (i != MaxCount + 1); Console.WriteLine(); Console.WriteLine("Game over"); Console.WriteLine("One more game Y/N ?"); consoleAnswer = Convert.ToString(Console.ReadLine()); }while (consoleAnswer == "Y"); Console.WriteLine("Stas games development inc. All right reserved"); Console.Read(); }
static void Main(string[] args) { Life life = new Life(true); life.Randomize(true); while (life.GetGeneration() < 1000) { Console.WriteLine(life); try { System.Threading.Thread.Sleep(250); } catch (Exception e) { Console.WriteLine(e.ToString()); return; } life.step(); } }
public LifeUI() { InitializeComponent(); engine = new Life(GRID_DIMENSION_CELLS, GRID_DIMENSION_CELLS); }