有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

如何将Java枚举移植到C#?

我是C#(以及一般编程)的初学者,我决定为学校彻底检查我的地下城爬虫项目,而不是使用预先确定的地图生成随机地图,由于我有一些Java经验,而且我对c语言非常熟悉,我认为使用我已经理解的Java代码来基于Java代码用c语言写东西是明智的,但我遇到了一个问题

目前我正在尝试编写以下代码: http://rosettacode.org/wiki/Maze_generation#Java 在c#进行得很顺利

只有

private void generateMaze(int cx, int cy) {

private enum DIR {

部分根本不起作用,它现在已经创建了一个完全填充的映射,但它仍然需要添加路径,经过一些搜索后,我发现C#Enum根本没有Java的功能,我如何“转换”Enum Dir部分和generateMaze到C#代码

目前我有: 程序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();
        }
    }
}

马泽根。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
        {

        }

    }
}

共 (0) 个答案