Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace Labyrinth
- {
- class Program
- {
- static void Main(string[] args)
- {
- var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
- var row = input[0];
- var col = input[1];
- var matrix = new int[row, col];
- var lengt = row * col;
- var numbers = new List<int>();
- var random = new Random();
- while (numbers.Any(item => item == 1) == false)
- {
- var stopper = lengt / 2;
- do
- {
- numbers.Add((random.Next(0, 2)));
- } while (numbers.Count <= stopper);
- for (int i = 0; i < lengt / 2; i++)
- {
- if (numbers.Any(item => item == 2))
- {
- numbers.Add((random.Next(0, 2)));
- }
- else
- {
- numbers.Add((random.Next(0, 3)));
- }
- }
- }
- var playerRow = 0;
- var playerCol = 0;
- var position = 0;
- for (int a = 0; a < matrix.GetLength(0); a++)
- {
- for (int b = 0; b < matrix.GetLength(1); b++)
- {
- matrix[a, b] = numbers[position++];
- if (matrix[a, b] == 2)
- {
- playerRow = a;
- playerCol = b;
- }
- }
- }
- for (int a = 0; a < matrix.GetLength(0); a++)
- {
- for (int b = 0; b < matrix.GetLength(1); b++)
- {
- Console.Write(matrix[a, b] + " ");
- }
- Console.WriteLine();
- }
- while (true)
- {
- try
- {
- if (matrix[playerRow, playerCol + 1] == 0)
- {
- matrix[playerRow, playerCol] = 1;
- matrix[playerRow, playerCol++] = 2;
- }
- else if (matrix[playerRow, playerCol - 1] == 0)
- {
- matrix[playerRow, playerCol] = 1;
- matrix[playerRow, playerCol--] = 2;
- }
- else if (matrix[playerRow + 1, playerCol] == 0)
- {
- matrix[playerRow, playerCol] = 1;
- matrix[playerRow++, playerCol] = 2;
- }
- else if (matrix[playerRow - 1, playerCol] == 0)
- {
- matrix[playerRow, playerCol] = 1;
- matrix[playerRow--, playerCol] = 1;
- }
- else
- {
- Console.WriteLine("There is no way out.");
- return;
- }
- }
- catch (Exception)
- {
- Console.WriteLine("There is a way out.");
- return;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement