Skip to main content
gamedev.net
🔒 Locked

Lost..

Started by CKolding Aug 9, 2007 at 4:21 AM 2 replies 2k views
Original Post
CKolding
CKolding
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:

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;
    }
}

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!
zz2
zz2
I think you should try creating a Maze class. Maze class should:
- store a maze (instance of a Maze class should be a maze)
- generate a maze based on input entered in console (hint: use constructor)
- be able to draw itself (hint: create public Draw method)

I think that everything after line "#region Number of rooms and walls" should go out of main method (use that code inside Maze class)

After you make Maze class you should be able to create a maze from inside of main method like this:
Maze maze = new Maze(rows, columns);  //this calls constructor that generates perfect mazemaze.Draw();

CKolding
CKolding
Thanks a lot! I will have a go at that.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.