Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static bool[,] mineArray;
- static Random random = new Random();
- static int BoolCount(int row, int col, int rowMax, int colMax)
- {
- int boolcount = 0;
- for (int i = -1; i <= 1; i++)
- for (int j = -1; j <= 1; j++)
- {
- if (row + i < 0 ||
- col + j < 0 ||
- row + i >= rowMax ||
- col + j >= colMax ||
- (row + i == row && col + j == col)) continue;
- if (mineArray[row + i, col + j] == true)
- boolcount++;
- }
- return boolcount;
- }
- static void Main()
- {
- ConsoleKey key;
- do
- {
- int k = random.Next(1, 6),
- m = random.Next(1, 11); // мне лень писать метод для ввода значений
- mineArray = new bool[k, m];
- for (int i = 0; i < k; i++)
- {
- for (int j = 0; j < m; j++)
- {
- mineArray[i, j] = random.Next(0, 2) == 0;
- Console.Write((mineArray[i, j] == false ? "0" : "1") + "\t"); // для наглядности
- }
- Console.WriteLine();
- }
- int row = random.Next(0, k),
- col = random.Next(0, m);
- int boolcount = BoolCount(row, col, k, m);
- Console.WriteLine("count @ [{0}, {1}] = {2}", row, col, boolcount);
- key = Console.ReadKey(true).Key;
- }
- while (key != ConsoleKey.Escape);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement