Exemple #1
0
    public static DungeonProgram Compile(string source)
    {
        AntlrInputStream  antlerStream = new AntlrInputStream(source);
        DungeonMapLexer   lexer        = new DungeonMapLexer(antlerStream);
        CommonTokenStream tokenStream  = new CommonTokenStream(lexer);
        DungeonMapParser  parser       = new DungeonMapParser(tokenStream);

        parser.prog(); // <-- compile happens here (see .g4 file)

        DungeonCompiler compiler = parser.Compiler;
        DungeonProgram  program  = new DungeonProgram(compiler.Elements);

        return(program);
    }
Exemple #2
0
    public IEnumerator GenerateDungeonMap(GameProgram.MapSize mapSize)
    {
        //Randomly choose dominant direction
        domDir = (DominantDirection)(UnityEngine.Random.Range(0, Enum.GetNames(typeof(DominantDirection)).Length));

        //Randomly choose the number of rooms (from a range, based on size)
        int maxRooms = 1;

        if (mapSize == GameProgram.MapSize.Small)
        {
            maxRooms = UnityEngine.Random.Range(4, 6);
        }
        else if (mapSize == GameProgram.MapSize.Medium)
        {
            maxRooms = UnityEngine.Random.Range(7, 10);;
        }
        else if (mapSize == GameProgram.MapSize.Large)
        {
            maxRooms = UnityEngine.Random.Range(11, 15);
        }

        int completedCorrSegments = 5;
        int maxIterations         = (completedCorrSegments * 4) - 1;

        //build a random corridor to connection each room:
        string path = "";

        for (int i = 0; i < maxRooms; i++)
        {
            string firstChar;

            if (i == 0)
            {
                firstChar = "X";
            }
            else
            {
                firstChar = "R";
            }

            path += DungeonPathString(maxIterations, firstChar);
        }

        path += DungeonPathString(maxIterations, "Z");
        path  = path.ToLower();

        Debug.Log(domDir);
        Debug.Log(path);

        //TESTING:
        //path = "aj.fnnj.fnnl.hnnm.innl.hnnj.fnnm.innj";                                                                       //Testing all DD:North connections
        //path = "bk.gssk.gssl.hssm.issl.hssk.jssm.issj";                                                                       //Testing all DD:South connections
        //path = "cl.heel.heek.geej.feek.geel.heej.feel";                                                                       //Testing all DD:East connections
        //path = "dm.iwwm.iwwk.gwwj.fwwk.gwwm.iwwj.fwwm";                                                                       //Testing all DD:West connections
        //path = "aj.fnnj.feej.fnnj.frm.iwwj.feel.hnnm.innj.frm.iwwm.innj.frm.innl.heej.frl.heej.fnnj.frm.iwwm.innj.fz";        //testing rooms going north
        //path = "bk.gssk.gssl.hssm.iwwk.grl.heel.hssk.grm.issl.heek.gwwm.iwwk.grl.hssm.issk.grl.heel.hssk.grm.issl.hssk.gz";   //testing rooms going south
        //path = "cl.heel.heel.hrj.fnnl.heel.hrk.gssl.hssl.hrj.feej.feel.hrj.feej.feek.geel.hz";                                //testing rooms going east
        //path = "dm.iwwm.iwwm.issm.irk.gssm.issm.iwwm.iwwm.irk.gssm.innj.fwwm.irj.fwwk.gwwk.gwwm.irj.fnnm.iwwm.iz";            //testing rooms going west

        _dProgram = DungeonCompiler.Compile(path);
        yield return(_dProgram.Run());
    }