0

I'm a beginner with C# (and programming in general) and decided I wanted to overhaul my Dungeon Crawler project for school and instead of using a predetermined map generate a random one, as I have some Java experience and I'm pretty fresh to c# I thought it would be smart to use the Java code I already understand to write something in C# based on the Java code but I've ran into a problem.

Currently I'm trying to write this code: http://rosettacode.org/wiki/Maze_generation#Java In c# which is going pretty well

Only the

private void generateMaze(int cx, int cy) {

And

private enum DIR {

parts don't work at all, it already creates a fully filled map now, but it still has to add the paths, after some searching I found that C# Enums simply don't have the same functionality as Java ones, how do I "convert" the Enum Dir part and generateMaze to c# code?

Currently I have this: Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DungeonCrawler
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("Wide?");
            int x = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Height?");
            int y = Convert.ToInt32(Console.ReadLine());
            MazeGen maze = new MazeGen(x, y);
            maze.display();
            Console.ReadKey();
        }
    }
}

MazeGen.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DungeonCrawler
{
    public class MazeGen
    {
        private int x;
        private int y;
        private int[,] maze;

        public MazeGen(int x, int y)
        {
            this.x = x;
            this.y = y;
            maze = new int[this.x, this.y];
            generateMaze(0, 0);
        }

        public void display()
        {
            for (int i = 0; i < y; i++)
            {
                //Bovenkant
                for (int j = 0; j < x; j++)
                {
                    Console.Write((maze[j, i] & 1) == 0 ? "+---" : "+   ");
                }
                Console.WriteLine("+");
                //Linkerkant
                for (int j = 0; j < x; j++)
                {
                    Console.Write((maze[j, i] & 8) == 0 ? "|   " : "    ");
                }
                Console.WriteLine("|");
            }
            //Onderkant
            for (int j = 0; j < x; j++)
            {
                Console.Write("+---");
            }
            Console.WriteLine("+");
        }

        private void generateMaze(int cx, int cy)
        {

        }

        private static Boolean between(int v, int upper)
        {
            return (v >= 0) && (v < upper);
        }

        private enum DIR
        {

        }

    }
}
Jeremy Wall
  • 23,907
  • 5
  • 55
  • 73
Strah Behry
  • 551
  • 2
  • 8
  • 25
  • 2
    This question/answer might give some good insights: http://stackoverflow.com/questions/469287/c-sharp-vs-java-enum-for-those-new-to-c – Gus Mar 17 '15 at 16:39
  • I've had the one open already but I have to admit I do not understand what is happening there and how I would implement that into the code I have right now. – Strah Behry Mar 17 '15 at 16:46
  • 1
    The "big picture" is this: The structure in C# that behaves most like a java Enum is a private, static instance of a C# class with no public constructor. In that way, you declare the class and all possible instances of it at compile time. – Gus Mar 17 '15 at 17:17
  • Okay, I get what you're trying to say but how would I implement this part in C#? N(1, 0, -1), S(2, 0, 1), E(4, 1, 0), W(8, -1, 0); – Strah Behry Mar 17 '15 at 17:41
  • 1
    `public static DIR N = new DIR(1,0,-1);` Then repeat for S,E,& W – Gus Mar 17 '15 at 18:03
  • If you want specific help converting your Java code to C#, you need to include the Java code you are having trouble with. Please do not link to external web sites as a way of supporting your question. Make sure the question is itself entirely self-contained. – Peter Duniho Mar 18 '15 at 02:30
  • Gus already solved it! Took me the whole night but it's done. – Strah Behry Mar 18 '15 at 06:43

0 Answers0