Original Post
I have not been so active during the last couple of weeks due to a heavy workload. Anyhow, I am struggling with the project - I am unsure how and where to continue - the 6 or so tips that JWalsh provided don't help me either. I understand the algorithm perfectly well (I believe), but when I get to write the code and convert it into programming language I don't know what to do. So far I have managed to code the following: With this I can get the user input on the desired number of rows and columns and calculate the number of rooms and walls. I have made a petty outline of the fields I would have in my Wall class, but from there I am hopelessly lost. Any help on how I could move on with the project? Thanks in advance!
using System;
using System.Collections.Generic;
using System.Text;
namespace MazeGenerator
{
public class Program
{
public static void Main(string[] args)
{
#region Selection of labyrinth dimensions
int rowsTemporary;
int columnsTemporary;
int rows = 0;
int columns = 0;
Console.WriteLine("Welcome to the maze generator!\n");
while (rows == 0)
{
Console.Write("\nPlease enter the desired number of rows. This must be a number between 2 and 50: ");
try
{
rowsTemporary = int.Parse(Console.ReadLine());
if (rowsTemporary < 2 || rowsTemporary > 50)
Console.WriteLine("Invalid input!");
else
rows = rowsTemporary;
}
catch
{
Console.WriteLine("You must input an integer!");
}
}
while (columns == 0)
{
Console.Write("Please enter the desired number of columns. This must be a number between 2 and 50: ");
try
{
columnsTemporary = int.Parse(Console.ReadLine());
if (columnsTemporary < 2 || columnsTemporary > 50)
Console.WriteLine("Invalid input!");
else
columns = columnsTemporary;
}
catch
{
Console.WriteLine("You must input an integer!");
}
}
Console.WriteLine("\nYou have chosen a labyrinth with the following dimensions:\nRows: {0}\nColumns: {1}", rows, columns);
Console.ReadLine();
#endregion
#region Number of rooms and walls
int numberOfRooms = rows * columns;
int numberOfWalls = (columns - 1)*rows + (rows - 1)*columns;
Console.WriteLine("The labyrinth contains {0} rooms and {1} walls.", numberOfRooms, numberOfWalls);
Console.WriteLine();
#endregion
#region Empty labyrinth
Console.Write("##");
for (int i = 0; i <= columns - 2; i++ )
Console.Write("##");
Console.WriteLine("#");
for (int i = 0; i <= 2*rows - 2; i++)
{
Console.Write("# ");
for (int j = 0; j <= columns - 2; j++)
Console.Write(" ");
Console.WriteLine("#");
}
Console.Write("#");
for (int i = 0; i <= columns - 2; i++)
Console.Write("##");
Console.Write("##");
Console.WriteLine();
Console.ReadLine();
#endregion
}
}
public class Wall
{
bool Up;
int RoomLeft;
int RoomRight;
}
}