Game of Life..need some assistance...
hello guys. i am trying to create Conway's game of life in C# (the whole generation of life 'game' from the 70's) i have created my window and gotten everything set up, i have a class structure but i need a little help. the program goes like this: if you left click the mouse you create a 'cell' and everytime you right click it is moves on one generation for every click. here are the rules :
1. If a cell has less than 2 living neighbors it is lonely and dies in the next generation.
2. If a cell has exactly 2 living neighbors it is happy and continues life in the next generation.
3. If a cell has exactly 3 living neighbors a new cell is born in that cell or continues to exist if it is already alive.
4. If a cell has 4 or more neighbors it is overcrowded and dies in the next generation
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace LifeofConway
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel pnlLife;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
private const int MAXX = 150;
private const int MAXY = 105;
private bool [,] world = new bool [MAXX, MAXY];
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
int row, col;
for(row=0; row
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.pnlLife = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// pnlLife
//
this.pnlLife.BackColor = System.Drawing.SystemColors.Desktop;
this.pnlLife.Location = new System.Drawing.Point(16, 8);
this.pnlLife.Name = "pnlLife";
this.pnlLife.Size = new System.Drawing.Size(712, 464);
this.pnlLife.TabIndex = 0;
this.pnlLife.Paint += new System.Windows.Forms.PaintEventHandler(this.pnlLife_Paint);
this.pnlLife.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pnlLife_MouseDown);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(742, 491);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.pnlLife});
this.Name = "Form1";
this.Text = " Life Is Short...";
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void pnlLife_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
int row, col;
Graphics grphPanel = e.Graphics;
Pen bluPen = new Pen(Color.Aqua, 1);
Brush bluBrush = new SolidBrush(Color.Aqua);
grphPanel.DrawRectangle(bluPen, 0, 0, 749, 524);
for (col=0;col