Esempio n. 1
0
 private void Initialize_Grid(int Apply_Ruleset = -1)
 {
     G = new Grid(1,1);
     Resizer();
     if (Apply_Ruleset == 0)
         Conway();
     G.Rules = Rules;
     Draw_Grid(1);
 }
Esempio n. 2
0
 private void Initialize_File(string[] args)
 {
     try
     {
         if (!args[0].EndsWith(".cas"))
         {
             Rules_Path.Text = args[0];
             System.IO.File.WriteAllText(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\setup.ini", Rules_Path.Text);
             Apply_Rule();
         }
         else
         {
             string[] all_lines;
             all_lines = System.IO.File.ReadAllLines(args[0]);
             if (all_lines[all_lines.Length - 1] != "")
             {
                 Rules_Path.Text = all_lines[all_lines.Length - 1];
                 Apply_Rule();
             }
             else if (System.IO.File.Exists(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\setup.ini"))
                 Rules_Path.Text = System.IO.File.ReadAllText(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\setup.ini");
             G = new Grid(Convert.ToInt32(all_lines[all_lines.Length - 3]), Convert.ToInt32(all_lines[all_lines.Length - 2]), G);
             for (int i = 0; i < G.Length; i++)
                 for (int j = 0; j < G.Width; j++)
                 {
                     if (G.Rules.No_States > Convert.ToInt32(all_lines[i * G.Width + j]))
                         G.Value[i, j] = Convert.ToInt32(all_lines[i * G.Width + j]);
                     else
                         G.Value[i, j] = G.Rules.No_States - 1;
                 }
             Generation = Convert.ToInt32(all_lines[all_lines.Length - 4]);
             Speed.Text = all_lines[all_lines.Length - 5];
             Cell_Size.Text = all_lines[all_lines.Length - 6].Substring(all_lines[all_lines.Length - 6].LastIndexOf(' ') + 1);
             this.Size = new Size(Convert.ToInt32(all_lines[all_lines.Length - 8]), Convert.ToInt32(all_lines[all_lines.Length - 7]));
             Draw_Grid(100);
             Display_Info();
         }
     }
     catch (IndexOutOfRangeException)
     {
         if (System.IO.File.Exists(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\setup.ini"))
             Rules_Path.Text = System.IO.File.ReadAllText(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\setup.ini");
     }
 }
Esempio n. 3
0
 public Grid(int Length, int Width, Grid Old)
 {
     Value = new int[Length, Width];
     this.Width = Width;
     this.Length = Length;
     Rules = Old.Rules;
     int Length_Limit;
     int Width_Limit;
     if (Length >= Old.Length)
         Length_Limit = Old.Length;
     else
         Length_Limit = Length;
     if (Width >= Old.Width)
         Width_Limit = Old.Width;
     else
         Width_Limit = Width;
     for (int i = 0; i < Length_Limit; i++)
         for (int j = 0; j < Width_Limit; j++)
             this.Value[i, j] = Old.Value[i, j];
 }
Esempio n. 4
0
 private void Load_State_Click(object sender, EventArgs e)
 {
     string[] all_lines;
     OpenFileDialog Out_File = new OpenFileDialog();
     Out_File.Filter = "Cellular Automata State File (.cas)|*.cas|All Files (*.*)|*.*";
     Out_File.FilterIndex = 1;
     Out_File.Title = "Choose a State to Load from";
     bool okClicked = Convert.ToBoolean(Out_File.ShowDialog());
     if (okClicked && Out_File.FileName != "")
     {
         all_lines = System.IO.File.ReadAllLines(Out_File.FileName);
         G = new Grid(Convert.ToInt32(all_lines[all_lines.Length - 3]), Convert.ToInt32(all_lines[all_lines.Length - 2]), G);
         for (int i = 0; i < G.Length; i++)
             for (int j = 0; j < G.Width; j++)
             {
                 if (G.Rules.No_States > Convert.ToInt32(all_lines[i * G.Width + j]))
                     G.Value[i, j] = Convert.ToInt32(all_lines[i * G.Width + j]);
                 else
                     G.Value[i, j] = G.Rules.No_States - 1;
             }
         Generation = Convert.ToInt32(all_lines[all_lines.Length - 4]);
         Speed.Text = all_lines[all_lines.Length - 5];
         Cell_Size.Text = all_lines[all_lines.Length - 6].Substring(all_lines[all_lines.Length - 6].LastIndexOf(' ') + 1);
         this.Size = new Size(Convert.ToInt32(all_lines[all_lines.Length - 8]), Convert.ToInt32(all_lines[all_lines.Length - 7]));
         Draw_Grid();
         Display_Info();
     }
 }
Esempio n. 5
0
 private void Reset_Button_Click(object sender, EventArgs e)
 {
     G = new Grid(G.Length, G.Width);
     Initialize_Grid();
     Draw_Grid();
     Generation = 1;
     Display_Info();
 }
Esempio n. 6
0
 public void Resizer()
 {
     int X_Cells = (this.Size.Width - Shift - 16) / Cell_Pixels;
     int Y_Cells = (this.Size.Height - 40) / Cell_Pixels;
     try
     {
         if ((X_Cells != G.Length || Y_Cells != G.Width) && X_Cells >= 2 && Y_Cells >= 2)
         {
             G = new Grid(X_Cells, Y_Cells, G);
             Draw_Grid();
             Display_Info();
         }
     }
     catch (NullReferenceException)
     { }
 }