Почему не прорисовывается путь в лабиринте? - C#
Формулировка задачи:
Не могу понять почему нормально не прорисовывается путь, путь это нули, вот код
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication8
{
class Program
{
int height = 11;
int Weight = 11;
int[,] maze;
static void Main(string[] args)
{
Program t = new Program();
t.maze = t.GenerationMaze(t.height,t.Weight);
Console.WriteLine();
for (int i = 0; i < t.height; i++)
{
for (int j = 0; j < t.Weight; j++)
{
Console.Write(t.maze[i, j] + " ");
}
Console.WriteLine();
}
Console.ReadKey();
}
int[,] GenerationMaze(int height, int Weight )
{
Program t = new Program();
t.maze = new int[height, Weight];
Random rand = new Random();
for (int i = 0; i< height; i++)
{
for (int j = 0; j < Weight; j++)
{
t.maze[i, j] = 1;///Stenki
///HODa
//
}
//
}
int r = rand.Next(height);
while (r % 2 == 0)
{
r = rand.Next(height);
}
int c = rand.Next(Weight);
while (c % 2 == 0)
{
c = rand.Next(Weight);
}
t.maze[r, c] = 0;
MazeDigger(t.maze, c, r);
return t. maze;
}
void MazeDigger(int[,] maze, int c,int r)
{
Program t = new Program();
int[] derection = new int[] { 1, 2, 3, 4 };
Shuffle(derection);
for(int i = 0; i < derection.Length; i++)
{
switch (derection[i])
{
case 1://verh
if (r - 2 <= 0)
continue;
if (maze[r - 2, c] != 0)
{
// maze[r - 3, c] = 0;
maze[r - 2, c] = 0;
maze[r - 1, c] = 0;
MazeDigger(maze, r - 2, c);
}
break;
case 2://pravo
if (c + 2 >= t.Weight-1)
continue;
if (maze[r , c+2] != 0)
{
maze[r, c+2] = 0;
maze[r , c+1] = 0;
MazeDigger(maze, r , c + 2);
}
break;
case 3://verh
if (r + 2 >= t.height-1)
continue;
if (maze[r + 2, c] != 0)
{
maze[r + 2, c] = 0;
maze[r + 1, c] = 0;
MazeDigger(maze, r + 2, c);
}
break;
case 4:///vniz
if (c - 2 <= 0)
continue;
if (maze[r , c - 2] != 0)
{
maze[r , c - 2] = 0;
maze[r , c - 1] = 0;
MazeDigger(maze, r , c - 2);
}
break;
}
}
}
public static void Shuffle<T>(T[] array)
{
Program t = new Program();
Random rand = new Random();
for (int i = array.Length; i > 1; i--)
{
int j = rand.Next(i);
T tmp = array[j];
array[j] = array[i - 1];
array[i - 1] = tmp;
}
}
}
}Решение задачи: «Почему не прорисовывается путь в лабиринте?»
textual
Листинг программы
// Создает массив лабиринт t.maze = t.GenerationMaze(t.height,t.Weight);