Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication46
- {
- class Program
- {
- static void Main(string[] args)
- {
- int AmountBacteria = 0, generation = 0;
- char sigh = ' ';
- Console.WriteLine("The life game!");
- Console.WriteLine("Enter how many bacteria do you want to start the game"); // מספר חיידקים התחלתי
- AmountBacteria = int.Parse(Console.ReadLine());
- while (AmountBacteria < 0)
- {
- Console.WriteLine("enter amount bacteria");
- AmountBacteria = int.Parse(Console.ReadLine());
- }
- Console.WriteLine("Enter how many generation do you want to live?");//כמה דורות יחיו
- generation = int.Parse(Console.ReadLine());
- while (generation < 0)
- {
- Console.WriteLine("enter how many generation do you ant to live");
- generation = int.Parse(Console.ReadLine());
- }
- Console.WriteLine("Enter your user ( it can be : * , & , @ , # , ~ , > , < )");//הסימן של המשתמש
- sigh = char.Parse(Console.ReadLine());
- if (sigh != '*' && sigh != '&' && sigh != '@' && sigh != '#' && sigh != '~' && sigh != '>' && sigh != '<') //בחירת סימן משתמש
- {
- bool sighTrue = false;
- while (sighTrue != true)
- {
- Console.WriteLine("Your sigh is unillgal ,so enter another your user ( it can be : * , & , @ , # , ~ , > , <) "); //בדיקת תקינות של הסימן
- sigh = char.Parse(Console.ReadLine());
- if (sigh == '*' || sigh == '&' || sigh == '@' || sigh == '#' || sigh == '~' || sigh == '>' || sigh == '<')
- sighTrue = true;
- }
- }
- Console.WriteLine("Enter the size of the board like :5*5"); // קליטתת גודל הטבלה
- int width = int.Parse(Console.ReadLine()); //גובה
- Console.WriteLine("*");
- int high = int.Parse(Console.ReadLine()); // שורות
- char[,] table1 = new char[width, high];
- Console.WriteLine("enter 1 if you wnat frame , enter 0 if you don't want frame"); //קליטת מסגרת לטבלה
- int frame = int.Parse(Console.ReadLine());
- while (frame != 0 && frame != 1) //בדיקת תקינות שהמספר 0 1
- {
- Console.WriteLine("enter 1 if you wnat frame , enter 0 if you don't want frame");
- frame = int.Parse(Console.ReadLine());
- }
- if (high * width < AmountBacteria) // בדיקה שכמות החיידקים לא גדולה מגודל הטבלה
- {
- Console.WriteLine("the amount of the Bacterias is bigger than the table, so enter the how much Bacterias do you want ");
- AmountBacteria = int.Parse(Console.ReadLine());
- }
- Random rnd = new Random();
- bool tr = false;
- for (int z = 0; z < AmountBacteria; z++) // הגרלת בקטריות התחלתיות
- {
- tr = false;
- int high1 = rnd.Next(0, high);
- int width1 = rnd.Next(0, width);
- // Console.WriteLine(high1 + " " + width1);
- while (tr != true)
- {
- if (table1[width1,high1] == sigh)
- {
- high1 = rnd.Next(0, high);
- width1 = rnd.Next(0, width);
- }
- else
- tr = true;
- }
- table1[width1, high1] = sigh;
- }
- for (int i = 0; i < high; i++) // הדפסת הטבלה //גובה
- {
- for (int j = 0; j < width; j++)
- {
- if (frame == 1)
- Console.Write("+--");
- }
- if (frame == 1)
- Console.Write("+");
- Console.WriteLine(" ");
- for (int y = 0; y < width; y++) // שורות הדפסת
- {
- if (frame == 1)
- Console.Write("| ");
- Console.Write(table1[y,i]);
- }
- if (frame == 1)
- Console.Write("|");
- Console.WriteLine(" ");
- }
- for (int j = 0; j < width; j++)
- {
- if (frame == 1)
- Console.Write("+--");
- }
- if (frame == 1)
- Console.Write("+");
- for (int n = 0; n < generation; n++)
- {
- // כללי המשחק
- int sum = 0;
- char[,] helpboard = new char[width, high]; // יצירת לוח עזר
- for (int j = 0; j< high; j++)
- {
- for (int i = 0;i < width; i++)
- {
- sum = 0;
- // if ( i==0 && j==0 )
- if (i > 0 && j > 0)
- {
- if (table1[i - 1, j - 1] == sigh)
- sum++;
- }
- if (i != 0)
- {
- if (table1[i - 1, j] == sigh)
- sum++;
- }
- if (i != 0 && j < high-1)
- {
- // Console.WriteLine(i + " " + j);
- if (table1[i - 1, j + 1] == sigh)
- sum++;
- }
- if (j != 0)
- {
- if (table1[i, j - 1] == sigh)
- sum++;
- }
- if (j < high-1)
- {
- if (table1[i, j + 1] == sigh)
- sum++;
- }
- if (i < width-1 && j != 0)
- {
- //Console.WriteLine(i + " " + j);
- if (table1[i + 1, j - 1] == sigh)
- sum++;
- }
- if (i < width-1)// fix
- {
- if (table1[i + 1, j] == sigh)
- sum++;
- }
- if ((i < width-1 && j < high-1))
- {
- if (table1[i + 1, j + 1] == sigh)
- sum++;
- }
- if (table1[i, j] == sigh) // בדיקת שכנים של תא חי
- {
- if (sum < 2)
- helpboard[i, j] = ' ';
- if (sum == 2 || sum == 3)
- helpboard[i, j] = sigh;
- if (sum > 3)
- helpboard[i, j] = ' ';
- }
- else // בדיקת שכנים של תא מת
- {
- if (sum == 3)
- helpboard[i, j] = sigh;
- }
- //Console.WriteLine(i+" "+" "+j+" "+sum+" ");
- }
- }
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- Console.WriteLine("-------------------------------------------------------- ");
- for (int j = 0; j < high; j++)// עידכון הטבלה האמיתית
- {
- for (int i = 0; i < width; i++)
- {
- table1[i, j] = helpboard[i, j];
- helpboard[i, j] = ' '; // איפוס טבלת עזר
- }
- }
- for (int i = 0; i < high; i++) // *2הדפסת הטבלה //גובה
- {
- for (int j = 0; j < width; j++)
- {
- if (frame == 1)
- Console.Write("+--");
- }
- if (frame == 1)
- Console.Write("+");
- Console.WriteLine(" ");
- for (int y = 0; y < width; y++) // שורות הדפסת
- {
- if (frame == 1)
- Console.Write("| ");
- Console.Write(table1[y,i]);
- }
- if (frame == 1)
- Console.Write("|");
- Console.WriteLine(" ");
- }
- for (int j = 0; j < width; j++)
- {
- if (frame == 1)
- Console.Write("+--");
- }
- if (frame == 1)
- Console.Write("+");
- Console.WriteLine(" ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement