Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication8
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             while (true)
  13.             {
  14.  
  15.                 string answer = "k";
  16.                 Console.Clear();
  17.                 Console.Write("Input a horizontal size of the game board or \"E\" for exit ");
  18.                
  19.                 string input1 = Console.ReadLine();
  20.                 if (input1 == "E")
  21.                     break;
  22.  
  23.                 int horizont = int.Parse(input1);
  24.                 Console.Write("Input a vertical size of the game board or \"E\" for exit ");
  25.                 string input2 = Console.ReadLine();
  26.                 int vertical = int.Parse(input2);
  27.                 if (input2 == "E")
  28.                     break;
  29.  
  30.  
  31.                 int[,] board = new int[horizont + 2, vertical + 2];
  32.  
  33.                 string s = "ROW↓  \\ COLUMN→| ";
  34.                 Console.Write(s);
  35.                 for (int u = 0; u < horizont; u++)
  36.                 { Console.Write(u); }
  37.                 Console.WriteLine();
  38.                 Console.WriteLine("_______________");
  39.  
  40.                 for (int i = 0; i < vertical; i++)
  41.                     Console.WriteLine("   " + i + "           | ");
  42.                 int hplace = 0;
  43.                 int vplace = 0;
  44.                 #region istheplacesettled
  45.                 while (hplace < horizont)
  46.                 {
  47.  
  48.                     while (vplace < vertical)
  49.                     {
  50.                         Console.Write("Is {0},{1} place settled? Y/N, E - End of completion ", hplace, vplace);
  51.  
  52.                         answer = Console.ReadLine();
  53.                         if (answer == "E")
  54.                             break;
  55.                         if (answer == "Y")
  56.                         {
  57.                             Console.SetCursorPosition(49, vertical + 4);
  58.                             Console.Write(" ");
  59.  
  60.                             board[hplace + 1, vplace + 1] = 1;
  61.  
  62.                             Console.SetCursorPosition(17 + hplace, 4 + vplace);
  63.                             string star = "*";
  64.                             Console.Write(star);
  65.                             Console.SetCursorPosition(0, vertical + 4);
  66.  
  67.  
  68.  
  69.                         }
  70.                         else
  71.                         {
  72.                             if (answer == "N")
  73.                                 Console.SetCursorPosition(49, vertical + 4);
  74.                             Console.Write(" ");
  75.                             board[hplace + 1, vplace + 1] = 0;
  76.  
  77.                             Console.SetCursorPosition(17 + hplace, 4 + vplace);
  78.                             Console.Write(" ");
  79.                             Console.SetCursorPosition(0, vertical + 4);
  80.  
  81.  
  82.  
  83.                         }
  84.  
  85.                         vplace++;
  86.                     }
  87.                     if (answer == "E")
  88.                         break;
  89.  
  90.                     hplace++;
  91.                     vplace = 0;
  92.                 }
  93.                 Console.SetCursorPosition(0,vertical+4);
  94.                 Console.Write("                                                                                            ");
  95.                 #endregion
  96.                
  97.                 while(true)
  98.                 {
  99.                    
  100.  
  101.                     #region changestatus
  102.                     Console.SetCursorPosition(0, vertical+6);
  103.                     Console.Write("Do you want to change status of some place ? Y/N ");
  104.                     Console.WriteLine("                                                                                                     ");
  105.                     Console.WriteLine("                                                                 ");
  106.                     Console.WriteLine("                                                                 ");
  107.                     Console.WriteLine("                                                                 ");
  108.                     Console.SetCursorPosition(49,vertical+6);
  109.                     string changest = Console.ReadLine();
  110.                     if (changest == "Y")
  111.                     {
  112.                         Console.SetCursorPosition(49, vertical + 6);
  113.                         Console.WriteLine(" ");
  114.                         Console.WriteLine("Choose a) - horizontal and b) - vertical coordinates of the place");
  115.                         Console.WriteLine("that need to be changed");
  116.                         Console.Write("Insert  a horizontal coordinate ");
  117.                         int hchangest = int.Parse(Console.ReadLine());
  118.  
  119.                         Console.Write("Insert a vertical coordinate ");
  120.                         int vchangest = int.Parse(Console.ReadLine());
  121.  
  122.                         if (board[hchangest + 1, vchangest + 1] == 1)
  123.                         {
  124.                             board[hchangest + 1, vchangest + 1] = 0;
  125.                             Console.SetCursorPosition(17 + hchangest, 4 + vchangest);
  126.                             Console.Write(" ");
  127.                             Console.SetCursorPosition(0, vertical + 6);
  128.  
  129.                         }
  130.                         else
  131.                             if (board[hchangest + 1, vchangest + 1] == 0)
  132.                             {
  133.                                 board[hchangest + 1, vchangest + 1] = 1;
  134.                                 Console.SetCursorPosition(17 + hchangest, 4 + vchangest);
  135.                                 Console.Write("*");
  136.                                 Console.SetCursorPosition(0, vertical + 5);
  137.  
  138.                             }
  139.                        
  140.                     }
  141.                     if (changest == "N")
  142.                         break;
  143.  #endregion
  144.                 }
  145.                 Console.SetCursorPosition(0, vertical + 5);
  146.                 Console.Write("Choose number of the next generations ");
  147.                 Console.WriteLine("                                                                                                     ");
  148.                 Console.WriteLine("                                                                                                     ");
  149.                 Console.WriteLine("                                                                 ");
  150.                 Console.WriteLine("                                                                 ");
  151.                 Console.WriteLine("                                                                 ");
  152.  
  153.                 Console.SetCursorPosition(39, vertical + 5);
  154.                 int Numgen = int.Parse(Console.ReadLine());
  155.                 int neib = 0;
  156.                 int[,] second = new int[horizont + 2, vertical + 2];
  157.                 for (int i = 1; i <= Numgen; i++)
  158.                 {  
  159.                     #region nextgener + changest2
  160.                     for (hplace = 1; hplace < horizont + 1; hplace++)
  161.                     {
  162.                         for (vplace = 1; vplace < vertical + 1; vplace++)
  163.                         {
  164.                             neib =
  165.                                 board[hplace - 1, vplace - 1] +
  166.                                 board[hplace - 1, vplace] +
  167.                                 board[hplace - 1, vplace + 1] +
  168.                                 board[hplace, vplace - 1] +
  169.                                 board[hplace, vplace + 1] +
  170.                                 board[hplace + 1, vplace - 1] +
  171.                                 board[hplace + 1, vplace] +
  172.                                 board[hplace + 1, vplace + 1];
  173.  
  174.                             if (board[hplace, vplace] == 0)
  175.                                 if (neib == 3)
  176.                                     second[hplace, vplace] = 1;
  177.                                 else
  178.                                     second[hplace, vplace] = board[hplace, vplace];
  179.                             if (board[hplace, vplace] == 1)
  180.                                 if (neib == 2 || neib == 3)
  181.                                     second[hplace, vplace] = board[hplace, vplace];
  182.                                 else second[hplace, vplace] = 0;
  183.                             if (second[hplace, vplace] == 0)
  184.                             {
  185.                                 Console.SetCursorPosition(16 + hplace, 3 + vplace);
  186.                                 Console.Write(" ");
  187.                             }
  188.                             else
  189.                             {
  190.                                 if (second[hplace, vplace] == 1)
  191.                                 {
  192.                                     Console.SetCursorPosition(16 + hplace, 3 + vplace);
  193.                                     Console.Write("*");
  194.  
  195.  
  196.                                 }
  197.  
  198.  
  199.                             }
  200.                         }
  201.  
  202.                     }
  203.                     for (hplace = 1; hplace < horizont + 1; hplace++)
  204.                     {
  205.                         for (vplace = 1; vplace < vertical + 1; vplace++)
  206.                         {
  207.                             board[hplace, vplace] = second[hplace, vplace];
  208.  
  209.                         }
  210.                     }
  211.                     Console.SetCursorPosition(0, vertical + 5);
  212.                     Console.WriteLine("{0} generation                                ", i);
  213.                     while (true)
  214.                     {
  215.                         Console.SetCursorPosition(0, vertical + 6);
  216.                         Console.Write("Do you want to change status of some place ? Y/N ");
  217.                         Console.WriteLine("                                                                                                     ");
  218.                         Console.WriteLine("                                                                 ");
  219.                         Console.WriteLine("                                                                 ");
  220.                         Console.WriteLine("                                                                 ");
  221.                         Console.SetCursorPosition(49,vertical+6);
  222.                         string changest = Console.ReadLine();
  223.                       if (changest == "Y")
  224.                        {
  225.                         Console.SetCursorPosition(49, vertical + 6);
  226.                         Console.WriteLine(" ");
  227.                         Console.WriteLine("Choose a) - horizontal and b) - vertical coordinates of the place");
  228.                         Console.WriteLine("that need to be changed");
  229.                         Console.Write("Insert  a horizontal coordinate ");
  230.                         int hchangest = int.Parse(Console.ReadLine());
  231.  
  232.                         Console.Write("Insert a vertical coordinate ");
  233.                         int vchangest = int.Parse(Console.ReadLine());
  234.  
  235.                         if (board[hchangest + 1, vchangest + 1] == 1)
  236.                         {
  237.                             board[hchangest + 1, vchangest + 1] = 0;
  238.                             Console.SetCursorPosition(17 + hchangest, 4 + vchangest);
  239.                             Console.Write(" ");
  240.                             Console.SetCursorPosition(0, vertical + 6);
  241.  
  242.                         }
  243.                         else
  244.                             if (board[hchangest + 1, vchangest + 1] == 0)
  245.                             {
  246.                                 board[hchangest + 1, vchangest + 1] = 1;
  247.                                 Console.SetCursorPosition(17 + hchangest, 4 + vchangest);
  248.                                 Console.Write("*");
  249.                                 Console.SetCursorPosition(0, vertical + 5);
  250.  
  251.                             }
  252.                        
  253.                     }
  254.                        
  255.                    
  256.                     if (changest == "N")
  257.                     {
  258.                        Console.SetCursorPosition(49, vertical + 6);
  259.                        Console.WriteLine(" ");
  260.                         break;                    
  261.                     }
  262.                     }
  263.                     Console.SetCursorPosition(0, vertical +7);
  264.                     Console.WriteLine("Press <Enter> to continue                         ");
  265.                     Console.ReadLine();
  266.                    
  267.                 #endregion
  268.                 }
  269.  
  270.                 Console.SetCursorPosition(0, vertical + 8);
  271.                     Console.Write("Press any key to continue or E for exit");
  272.                 string exit = Console.ReadLine();
  273.                 if (exit == "E")
  274.                     break;
  275.             }
  276.         }
  277.     }
  278. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement