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;
- namespace ConsoleApplication8
- {
- class Program
- {
- static void Main(string[] args)
- {
- while (true)
- {
- string answer = "k";
- Console.Clear();
- Console.Write("Input a horizontal size of the game board or \"E\" for exit ");
- string input1 = Console.ReadLine();
- if (input1 == "E")
- break;
- int horizont = int.Parse(input1);
- Console.Write("Input a vertical size of the game board or \"E\" for exit ");
- string input2 = Console.ReadLine();
- int vertical = int.Parse(input2);
- if (input2 == "E")
- break;
- int[,] board = new int[horizont + 2, vertical + 2];
- string s = "ROW↓ \\ COLUMN→| ";
- Console.Write(s);
- for (int u = 0; u < horizont; u++)
- { Console.Write(u); }
- Console.WriteLine();
- Console.WriteLine("_______________");
- for (int i = 0; i < vertical; i++)
- Console.WriteLine(" " + i + " | ");
- int hplace = 0;
- int vplace = 0;
- #region istheplacesettled
- while (hplace < horizont)
- {
- while (vplace < vertical)
- {
- Console.Write("Is {0},{1} place settled? Y/N, E - End of completion ", hplace, vplace);
- answer = Console.ReadLine();
- if (answer == "E")
- break;
- if (answer == "Y")
- {
- Console.SetCursorPosition(49, vertical + 4);
- Console.Write(" ");
- board[hplace + 1, vplace + 1] = 1;
- Console.SetCursorPosition(17 + hplace, 4 + vplace);
- string star = "*";
- Console.Write(star);
- Console.SetCursorPosition(0, vertical + 4);
- }
- else
- {
- if (answer == "N")
- Console.SetCursorPosition(49, vertical + 4);
- Console.Write(" ");
- board[hplace + 1, vplace + 1] = 0;
- Console.SetCursorPosition(17 + hplace, 4 + vplace);
- Console.Write(" ");
- Console.SetCursorPosition(0, vertical + 4);
- }
- vplace++;
- }
- if (answer == "E")
- break;
- hplace++;
- vplace = 0;
- }
- Console.SetCursorPosition(0,vertical+4);
- Console.Write(" ");
- #endregion
- while(true)
- {
- #region changestatus
- Console.SetCursorPosition(0, vertical+6);
- Console.Write("Do you want to change status of some place ? Y/N ");
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- Console.SetCursorPosition(49,vertical+6);
- string changest = Console.ReadLine();
- if (changest == "Y")
- {
- Console.SetCursorPosition(49, vertical + 6);
- Console.WriteLine(" ");
- Console.WriteLine("Choose a) - horizontal and b) - vertical coordinates of the place");
- Console.WriteLine("that need to be changed");
- Console.Write("Insert a horizontal coordinate ");
- int hchangest = int.Parse(Console.ReadLine());
- Console.Write("Insert a vertical coordinate ");
- int vchangest = int.Parse(Console.ReadLine());
- if (board[hchangest + 1, vchangest + 1] == 1)
- {
- board[hchangest + 1, vchangest + 1] = 0;
- Console.SetCursorPosition(17 + hchangest, 4 + vchangest);
- Console.Write(" ");
- Console.SetCursorPosition(0, vertical + 6);
- }
- else
- if (board[hchangest + 1, vchangest + 1] == 0)
- {
- board[hchangest + 1, vchangest + 1] = 1;
- Console.SetCursorPosition(17 + hchangest, 4 + vchangest);
- Console.Write("*");
- Console.SetCursorPosition(0, vertical + 5);
- }
- }
- if (changest == "N")
- break;
- #endregion
- }
- Console.SetCursorPosition(0, vertical + 5);
- Console.Write("Choose number of the next generations ");
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- Console.SetCursorPosition(39, vertical + 5);
- int Numgen = int.Parse(Console.ReadLine());
- int neib = 0;
- int[,] second = new int[horizont + 2, vertical + 2];
- for (int i = 1; i <= Numgen; i++)
- {
- #region nextgener + changest2
- for (hplace = 1; hplace < horizont + 1; hplace++)
- {
- for (vplace = 1; vplace < vertical + 1; vplace++)
- {
- neib =
- board[hplace - 1, vplace - 1] +
- board[hplace - 1, vplace] +
- board[hplace - 1, vplace + 1] +
- board[hplace, vplace - 1] +
- board[hplace, vplace + 1] +
- board[hplace + 1, vplace - 1] +
- board[hplace + 1, vplace] +
- board[hplace + 1, vplace + 1];
- if (board[hplace, vplace] == 0)
- if (neib == 3)
- second[hplace, vplace] = 1;
- else
- second[hplace, vplace] = board[hplace, vplace];
- if (board[hplace, vplace] == 1)
- if (neib == 2 || neib == 3)
- second[hplace, vplace] = board[hplace, vplace];
- else second[hplace, vplace] = 0;
- if (second[hplace, vplace] == 0)
- {
- Console.SetCursorPosition(16 + hplace, 3 + vplace);
- Console.Write(" ");
- }
- else
- {
- if (second[hplace, vplace] == 1)
- {
- Console.SetCursorPosition(16 + hplace, 3 + vplace);
- Console.Write("*");
- }
- }
- }
- }
- for (hplace = 1; hplace < horizont + 1; hplace++)
- {
- for (vplace = 1; vplace < vertical + 1; vplace++)
- {
- board[hplace, vplace] = second[hplace, vplace];
- }
- }
- Console.SetCursorPosition(0, vertical + 5);
- Console.WriteLine("{0} generation ", i);
- while (true)
- {
- Console.SetCursorPosition(0, vertical + 6);
- Console.Write("Do you want to change status of some place ? Y/N ");
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- Console.SetCursorPosition(49,vertical+6);
- string changest = Console.ReadLine();
- if (changest == "Y")
- {
- Console.SetCursorPosition(49, vertical + 6);
- Console.WriteLine(" ");
- Console.WriteLine("Choose a) - horizontal and b) - vertical coordinates of the place");
- Console.WriteLine("that need to be changed");
- Console.Write("Insert a horizontal coordinate ");
- int hchangest = int.Parse(Console.ReadLine());
- Console.Write("Insert a vertical coordinate ");
- int vchangest = int.Parse(Console.ReadLine());
- if (board[hchangest + 1, vchangest + 1] == 1)
- {
- board[hchangest + 1, vchangest + 1] = 0;
- Console.SetCursorPosition(17 + hchangest, 4 + vchangest);
- Console.Write(" ");
- Console.SetCursorPosition(0, vertical + 6);
- }
- else
- if (board[hchangest + 1, vchangest + 1] == 0)
- {
- board[hchangest + 1, vchangest + 1] = 1;
- Console.SetCursorPosition(17 + hchangest, 4 + vchangest);
- Console.Write("*");
- Console.SetCursorPosition(0, vertical + 5);
- }
- }
- if (changest == "N")
- {
- Console.SetCursorPosition(49, vertical + 6);
- Console.WriteLine(" ");
- break;
- }
- }
- Console.SetCursorPosition(0, vertical +7);
- Console.WriteLine("Press <Enter> to continue ");
- Console.ReadLine();
- #endregion
- }
- Console.SetCursorPosition(0, vertical + 8);
- Console.Write("Press any key to continue or E for exit");
- string exit = Console.ReadLine();
- if (exit == "E")
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement