Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication46
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int AmountBacteria = 0, generation = 0;
  14. char sigh = ' ';
  15.  
  16. Console.WriteLine("The life game!");
  17. Console.WriteLine("Enter how many bacteria do you want to start the game"); // מספר חיידקים התחלתי
  18. AmountBacteria = int.Parse(Console.ReadLine());
  19. while (AmountBacteria < 0)
  20. {
  21. Console.WriteLine("enter amount bacteria");
  22. AmountBacteria = int.Parse(Console.ReadLine());
  23. }
  24. Console.WriteLine("Enter how many generation do you want to live?");//כמה דורות יחיו
  25. generation = int.Parse(Console.ReadLine());
  26. while (generation < 0)
  27. {
  28. Console.WriteLine("enter how many generation do you ant to live");
  29. generation = int.Parse(Console.ReadLine());
  30. }
  31. Console.WriteLine("Enter your user ( it can be : * , & , @ , # , ~ , > , < )");//הסימן של המשתמש
  32. sigh = char.Parse(Console.ReadLine());
  33. if (sigh != '*' && sigh != '&' && sigh != '@' && sigh != '#' && sigh != '~' && sigh != '>' && sigh != '<') //בחירת סימן משתמש
  34. {
  35. bool sighTrue = false;
  36. while (sighTrue != true)
  37. {
  38. Console.WriteLine("Your sigh is unillgal ,so enter another your user ( it can be : * , & , @ , # , ~ , > , <) "); //בדיקת תקינות של הסימן
  39. sigh = char.Parse(Console.ReadLine());
  40. if (sigh == '*' || sigh == '&' || sigh == '@' || sigh == '#' || sigh == '~' || sigh == '>' || sigh == '<')
  41. sighTrue = true;
  42. }
  43. }
  44. Console.WriteLine("Enter the size of the board like :5*5"); // קליטתת גודל הטבלה
  45. int width = int.Parse(Console.ReadLine()); //גובה
  46. Console.WriteLine("*");
  47. int high = int.Parse(Console.ReadLine()); // שורות
  48. char[,] table1 = new char[width, high];
  49. Console.WriteLine("enter 1 if you wnat frame , enter 0 if you don't want frame"); //קליטת מסגרת לטבלה
  50. int frame = int.Parse(Console.ReadLine());
  51.  
  52. while (frame != 0 && frame != 1) //בדיקת תקינות שהמספר 0 1
  53. {
  54. Console.WriteLine("enter 1 if you wnat frame , enter 0 if you don't want frame");
  55. frame = int.Parse(Console.ReadLine());
  56. }
  57. if (high * width < AmountBacteria) // בדיקה שכמות החיידקים לא גדולה מגודל הטבלה
  58. {
  59. Console.WriteLine("the amount of the Bacterias is bigger than the table, so enter the how much Bacterias do you want ");
  60. AmountBacteria = int.Parse(Console.ReadLine());
  61. }
  62. Random rnd = new Random();
  63.  
  64. bool tr = false;
  65. for (int z = 0; z < AmountBacteria; z++) // הגרלת בקטריות התחלתיות
  66. {
  67. tr = false;
  68. int high1 = rnd.Next(0, high);
  69. int width1 = rnd.Next(0, width);
  70. // Console.WriteLine(high1 + " " + width1);
  71. while (tr != true)
  72. {
  73. if (table1[width1,high1] == sigh)
  74. {
  75. high1 = rnd.Next(0, high);
  76. width1 = rnd.Next(0, width);
  77. }
  78. else
  79. tr = true;
  80. }
  81. table1[width1, high1] = sigh;
  82.  
  83. }
  84.  
  85. for (int i = 0; i < high; i++) // הדפסת הטבלה //גובה
  86. {
  87. for (int j = 0; j < width; j++)
  88. {
  89. if (frame == 1)
  90. Console.Write("+--");
  91. }
  92. if (frame == 1)
  93. Console.Write("+");
  94. Console.WriteLine(" ");
  95. for (int y = 0; y < width; y++) // שורות הדפסת
  96. {
  97. if (frame == 1)
  98. Console.Write("| ");
  99. Console.Write(table1[y,i]);
  100. }
  101. if (frame == 1)
  102. Console.Write("|");
  103. Console.WriteLine(" ");
  104. }
  105. for (int j = 0; j < width; j++)
  106. {
  107. if (frame == 1)
  108. Console.Write("+--");
  109. }
  110. if (frame == 1)
  111. Console.Write("+");
  112. for (int n = 0; n < generation; n++)
  113. {
  114. // כללי המשחק
  115. int sum = 0;
  116. char[,] helpboard = new char[width, high]; // יצירת לוח עזר
  117. for (int j = 0; j< high; j++)
  118. {
  119. for (int i = 0;i < width; i++)
  120. {
  121. sum = 0;
  122. // if ( i==0 && j==0 )
  123. if (i > 0 && j > 0)
  124. {
  125. if (table1[i - 1, j - 1] == sigh)
  126. sum++;
  127. }
  128. if (i != 0)
  129. {
  130. if (table1[i - 1, j] == sigh)
  131. sum++;
  132. }
  133. if (i != 0 && j < high-1)
  134. {
  135. // Console.WriteLine(i + " " + j);
  136. if (table1[i - 1, j + 1] == sigh)
  137. sum++;
  138. }
  139. if (j != 0)
  140. {
  141. if (table1[i, j - 1] == sigh)
  142. sum++;
  143. }
  144. if (j < high-1)
  145. {
  146. if (table1[i, j + 1] == sigh)
  147. sum++;
  148. }
  149. if (i < width-1 && j != 0)
  150. {
  151. //Console.WriteLine(i + " " + j);
  152. if (table1[i + 1, j - 1] == sigh)
  153. sum++;
  154. }
  155. if (i < width-1)// fix
  156. {
  157. if (table1[i + 1, j] == sigh)
  158. sum++;
  159. }
  160. if ((i < width-1 && j < high-1))
  161. {
  162. if (table1[i + 1, j + 1] == sigh)
  163. sum++;
  164. }
  165. if (table1[i, j] == sigh) // בדיקת שכנים של תא חי
  166. {
  167. if (sum < 2)
  168. helpboard[i, j] = ' ';
  169. if (sum == 2 || sum == 3)
  170. helpboard[i, j] = sigh;
  171. if (sum > 3)
  172. helpboard[i, j] = ' ';
  173. }
  174. else // בדיקת שכנים של תא מת
  175. {
  176. if (sum == 3)
  177. helpboard[i, j] = sigh;
  178. }
  179. //Console.WriteLine(i+" "+" "+j+" "+sum+" ");
  180. }
  181.  
  182. }
  183. Console.WriteLine(" ");
  184. Console.WriteLine(" ");
  185. Console.WriteLine("-------------------------------------------------------- ");
  186.  
  187. for (int j = 0; j < high; j++)// עידכון הטבלה האמיתית
  188. {
  189. for (int i = 0; i < width; i++)
  190. {
  191. table1[i, j] = helpboard[i, j];
  192. helpboard[i, j] = ' '; // איפוס טבלת עזר
  193. }
  194. }
  195. for (int i = 0; i < high; i++) // *2הדפסת הטבלה //גובה
  196. {
  197. for (int j = 0; j < width; j++)
  198. {
  199. if (frame == 1)
  200. Console.Write("+--");
  201. }
  202. if (frame == 1)
  203. Console.Write("+");
  204. Console.WriteLine(" ");
  205. for (int y = 0; y < width; y++) // שורות הדפסת
  206. {
  207. if (frame == 1)
  208. Console.Write("| ");
  209. Console.Write(table1[y,i]);
  210. }
  211. if (frame == 1)
  212. Console.Write("|");
  213. Console.WriteLine(" ");
  214. }
  215. for (int j = 0; j < width; j++)
  216. {
  217. if (frame == 1)
  218. Console.Write("+--");
  219. }
  220. if (frame == 1)
  221. Console.Write("+");
  222. Console.WriteLine(" ");
  223. }
  224. }
  225. }
  226. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement