public static void Main(string[] args) { timeOfLastEvolution = DateTime.Now; Console.SetWindowSize(150, 50); Console.SetWindowPosition(0, 0); Console.CursorVisible = false; Console.CancelKeyPress += (sender, args) => { isRunning = false; Console.WriteLine("\nQuitting Application"); Thread.Sleep(2000); Environment.Exit(0); }; while (isRunning) { while (Console.KeyAvailable == false) { if (needsRedraw) { Console.SetCursorPosition(0, 0); Console.CursorVisible = false; PrintInfo(); PrintGrid(); needsRedraw = false; } if ((DateTime.Now - timeOfLastEvolution).TotalMilliseconds >= sleepAmount) { if (!isPaused) { grid.NextGeneration(); timeOfLastEvolution = DateTime.Now; needsRedraw = true; } } } ConsoleKey key = Console.ReadKey(true).Key; needsRedraw = true; switch (key) { case ConsoleKey.F1: enableMoreInfo = !enableMoreInfo; break; case ConsoleKey.F5: grid = new GameGrid(); timeOfLastEvolution = DateTime.Now; break; case ConsoleKey.UpArrow: sleepAmount += SleepIncrement; break; case ConsoleKey.DownArrow: sleepAmount -= sleepAmount < SleepIncrement ? sleepAmount : SleepIncrement; break; case ConsoleKey.P: isPaused = !isPaused; break; default: needsRedraw = false; break; } } }
public void GridTenYear() { initAll(); GameGrid g = new GameGrid(Tuple.Create(8, 8)); foreach (List<GameCell> cells in g.Cells) for (int i = 0; i < 8; i++) { cells.Add(new GameCell(100, 20, 1f)); } g.GridSim(10 * 365, 1); }
public void GridTestOneDay() { initAll(); GameGrid g = new GameGrid(Tuple.Create(8, 8)); foreach (List<GameCell> cells in g.Cells) { for (int i = 0; i < 8; i++) { cells.Add(new GameCell(0, 0, 1f)); } } // g.Cells[0][0] = new Cell(2, 2, 1f); g.GridOneDaySim(); }
protected override void Initialize() { base.Initialize(); ticks = 0; spriteBatch = new SpriteBatch(graphics.GraphicsDevice); int width = graphics.PreferredBackBufferWidth; int height = graphics.PreferredBackBufferHeight; Texture2D texture = this.Content.Load<Texture2D>("alive"); Texture2D dead = this.Content.Load<Texture2D>("dead"); mouse = this.Content.Load<Texture2D>("mouse-pointer"); m_Cell = new Cell[height/10-10, width/10]; int cols = 0; int rows = 0; for (int row = 0; row < height/10-10; row++) { cols = 0; m_Cell[row, 0] = new Cell(0,row, cols, rows,10,graphics.GraphicsDevice, spriteBatch, texture, dead); //m_Cell[row, 0].IsAlive = true; for (int col = 1; col < width/10; col++) { cols += 10/*replace with width*/ + 2; m_Cell[row, col] = new Cell(col,row,cols,rows,10,graphics.GraphicsDevice, spriteBatch, texture, dead); } rows += 10 + 2; } grid = new GameGrid(width/10, height/10-10, m_Cell, graphics.GraphicsDevice, spriteBatch, this); }