Exemple #1
0
        /// <summary>
        /// Links and fills init'd Room Cells in the RoomCells array
        /// </summary>
        public void FinalizeMap()
        {
            int  playerY = 0;
            int  playerX = 0;
            bool bossSet = false;

            for (int x = 0; x <= MapSizeX - 1; x++)
            {
                for (int y = 0; y <= MapSizeY - 1; y++)
                {
                    //skip link step for null room
                    if (RoomCells[x, y] == null)
                    {
                        continue;
                    }

                    if (!bossSet)
                    {
                        bossSet = true;
                        RoomCells[x, y].Boss    = true;
                        RoomCells[x, y].Visited = true;
                        BossLocation            = new int[2] {
                            x, y
                        };
                    }

                    RoomCells[x, y].Treasure = false;
                    //determine if treasure
                    int tChance = rng.Next(0, 8);
                    if (tChance == 0)
                    {
                        RoomCells[x, y].Treasure = true;
                    }

                    //set room coordinates
                    RoomCells[x, y].RoomCoords = new int[2] {
                        x, y
                    };

                    //begin linking rooms
                    int px;
                    int py;
                    //check North
                    px = x;
                    py = y - 1;


                    if (CheckBounds(px, py, MapSizeX, MapSizeY))
                    {
                        RoomCell rm = RoomCells[px, py];
                        RoomCells[x, y].North = rm;
                    }
                    else
                    {
                        RoomCells[x, y].North = null;
                    }

                    //check East
                    px = x + 1;
                    py = y;

                    if (CheckBounds(px, py, MapSizeX, MapSizeY))
                    {
                        RoomCell rm = RoomCells[px, py];
                        RoomCells[x, y].East = rm;
                    }
                    else
                    {
                        RoomCells[x, y].East = null;
                    }

                    //check South
                    px = x;
                    py = y + 1;

                    if (CheckBounds(px, py, MapSizeX, MapSizeY))
                    {
                        RoomCell rm = RoomCells[px, py];
                        RoomCells[x, y].South = rm;
                    }
                    else
                    {
                        RoomCells[x, y].South = null;
                    }

                    //check West
                    px = x - 1;
                    py = y;

                    if (CheckBounds(px, py, MapSizeX, MapSizeY))
                    {
                        RoomCell rm = RoomCells[px, py];
                        RoomCells[x, y].West = rm;
                    }
                    else
                    {
                        RoomCells[x, y].West = null;
                    }

                    playerX = x;
                    playerY = y;
                }
            }

            PlayerStartLocation = new int[2] {
                playerX, playerY
            };

            //spin the png
            //MapCharter mapc = new MapCharter(RoomCells, MapSizeX, MapSizeY);
        }
Exemple #2
0
        /// <summary>
        /// Dig Map places the digger at a random location in the cells array
        /// The digger follows the rules stated above, and then calls finalize to link all the rooms
        /// </summary>
        public void DigMap()
        {
            //init cell array
            RoomCells = new RoomCell[MapSizeX, MapSizeY];
            //calculate threshold of room
            //might need tweaking but ideally 35% of the room should be filled
            MapSizeTotal       = MapSizeX * MapSizeY;
            RoomCountThreshold = (int)(MapSizeTotal * 0.15f); //might truncate awkwardly, but some variation is okay
            RoomCountRunning   = 0;                           //set room tally to 0

            //this will be the initial digger location
            int xpos = rng.Next(0, MapSizeX);
            int ypos = rng.Next(0, MapSizeY);

            int       stepCounter     = 0; //local step count for random dig pattern
            Direction diggerDirection = (Direction)rng.Next(0, 4);

            if (diggerDirection == Direction.None)
            {
                //superhack
                diggerDirection = Direction.North;
            }
            //begin digger step event
            while (RoomCountRunning <= RoomCountThreshold)
            {
                //check room tally on beginning of step event

                //check if room has already been dug
                if (RoomCells[xpos, ypos] != null)
                {
                    //do not increase room count or step count
                    Console.WriteLine("cross over occurred");
                }
                else
                {
                    //dig this room
                    RoomCells[xpos, ypos] = new RoomCell();
                    RoomCountRunning     += 1;
                }



                //determine direction
                if (stepCounter >= RandomStep)
                {
                    //if step threshold is reached, reroll direction and reset counter
                    int dir = rng.Next(0, 4);
                    switch (dir)
                    {
                    case 0: diggerDirection = Direction.North;
                        break;

                    case 1: diggerDirection = Direction.South;
                        break;

                    case 2: diggerDirection = Direction.East;
                        break;

                    case 3: diggerDirection = Direction.West;
                        break;
                    }
                    stepCounter = 0;
                }

                //temp predicted next positions
                bool validMove = false;
                //

                while (!validMove)
                {
                    int pxpos = xpos;
                    int pypos = ypos;
                    //calculate next position
                    switch (diggerDirection)
                    {
                    case Direction.North: pypos -= 1; break;

                    case Direction.South: pypos += 1; break;

                    case Direction.East: pxpos += 1; break;

                    case Direction.West: pxpos -= 1; break;
                    }

                    //check if next room is valid (is not a boundary and is not a populated room)
                    if (pxpos >= 0 && pxpos < MapSizeX - 1 && pypos >= 0 && pypos < MapSizeY)
                    {
                        if (RoomCells[pxpos, pypos] == null)
                        {
                            //okay to set the positions now
                            xpos         = pxpos;
                            ypos         = pypos;
                            validMove    = true;
                            stepCounter += 1;
                        }
                        else
                        {
                            xpos      = pxpos;
                            ypos      = pypos;
                            validMove = true;
                        }
                    }
                    else
                    {
                        validMove = false;
                    }

                    if (!validMove)
                    {
                        var oldDiggerDirection = diggerDirection;

                        switch (oldDiggerDirection)
                        {
                        case Direction.North:
                            switch (rng.Next(0, 3))
                            {
                            case 0: diggerDirection = Direction.East; break;

                            case 1: diggerDirection = Direction.South; break;

                            case 2: diggerDirection = Direction.West; break;
                            }
                            break;

                        case Direction.South:
                            switch (rng.Next(0, 3))
                            {
                            case 0: diggerDirection = Direction.East; break;

                            case 1: diggerDirection = Direction.North; break;

                            case 2: diggerDirection = Direction.West; break;
                            }
                            break;

                        case Direction.East:
                            switch (rng.Next(0, 3))
                            {
                            case 0: diggerDirection = Direction.North; break;

                            case 1: diggerDirection = Direction.South; break;

                            case 2: diggerDirection = Direction.West; break;
                            }
                            break;

                        case Direction.West:
                            switch (rng.Next(0, 3))
                            {
                            case 0: diggerDirection = Direction.North; break;

                            case 1: diggerDirection = Direction.South; break;

                            case 2: diggerDirection = Direction.East; break;
                            }
                            break;
                        }

                        stepCounter = 0;
                    }
                }
            }

            //call finalize to link the map
            FinalizeMap();
        }
Exemple #3
0
        //create thumbnail
        public void ChartMap()
        {
            int resBytes = (MaxSizeX * 4) * MaxSizeY;

            imageBuffer = new byte[resBytes];
            StringBuilder sb  = new StringBuilder();
            MapManager    man = MapManager.Instance;

            for (int x = 0; x < MaxSizeX; x++)
            {
                for (int y = 0; y < MaxSizeY; y++)
                {
                    RoomCell rm = Map[y, x];

                    ////int[] coords = TranslateCoords(x, y, MaxSizeX, MaxSizeY);

                    //if(rm == null)
                    //{
                    //    //PlotPixel(coords[0], coords[1], PixelMaker(Markers.Wall));
                    //    PlotPixel(y, x, PixelMaker(Markers.Wall));

                    //}
                    //else
                    //{
                    //    //PlotPixel(coords[0], coords[1], PixelMaker(Markers.Explored));
                    //    PlotPixel(y, x, PixelMaker(Markers.Explored));

                    //}
                    if (rm == null || !rm.Visited)
                    {
                        sb.Append(" ");
                    }
                    else if (rm.Boss)
                    {
                        sb.Append("B");
                    }
                    else if (x == man.PlayerCoords[1] && y == man.PlayerCoords[0])
                    {
                        sb.Append("O");
                    }
                    else
                    {
                        sb.Append("X");
                    }
                }
                sb.AppendLine();
            }

            //unsafe
            //{
            //    fixed(byte* ptr = imageBuffer)
            //    {
            //        using (Bitmap image = new Bitmap(MaxSizeX, MaxSizeY, MaxSizeX * 4, System.Drawing.Imaging.PixelFormat.Format32bppRgb, new IntPtr(ptr)))
            //        {
            //            image.Save(@"map.png");
            //        }
            //    }
            //

            //creating coregraphics bitmap context is overly difficult,
            //instead of relying on gfx, we'll make a string array

            //TODO: Implement string array
            MapString = sb.ToString();
        }