Example #1
0
        public void drawMap()
        {
            this.sColor = mapColor();
            //determine if a map exists, if so, unload it.  Otherwise, initialize a fresh oMapArray.
            if (oMapArray == null)
            {
                // do nothing
                oMapArray = new TileButton[iXSize, iYSize];
            }
            else
            {
                unloadMap();
            }
            lCoords = PathBuilder.MakeViableMap(iXSize, iYSize);

            for (int xPos = 0; xPos < iXSize; xPos++)
            {
                for (int yPos = 0; yPos < iYSize; yPos++)
                {
                    oMapArray[xPos, yPos] = NewRandomTile(xPos, yPos, sColor);
                }
            }
            CompleteMap();
        }
Example #2
0
        public TileButton NewRandomTile(int iXpos, int iYpos, string sColor)
        {
            int    iIndex     = 0;
            string sImageName = "";
            int    iPrevX     = 0;
            int    iPrevY     = 0;
            int    iNextX     = 0;
            int    iNextY     = 0;

            string[]   sSplitter;
            TileButton oThisTileButton = new TileButton();

            oThisTileButton.BNorthOpen = false;
            oThisTileButton.BSouthOpen = false;
            oThisTileButton.BEastOpen  = false;
            oThisTileButton.BWestOpen  = false;
            oThisTileButton.Location   = new System.Drawing.Point(12 + (iXpos * 40), 60 + (iYpos * 40));
            iIndex = lCoords.IndexOf(PathBuilder.MakeCoords(iXpos, iYpos));
            if ((iIndex > 0) && (iIndex < (lCoords.Count - 2)))
            {
                // path is made, use what is in the pathbuilder.
                // ignore first and last items
                // find neighbors
                sImageName = "solid.BMP";
                //lCoords.RemoveAt(iIndex - 1);
                sSplitter = lCoords[iIndex - 1].Split(',');
                iPrevX    = Int32.Parse(sSplitter[0]);
                iPrevY    = Int32.Parse(sSplitter[1]);
                sSplitter = lCoords[iIndex + 1].Split(',');
                iNextX    = Int32.Parse(sSplitter[0]);
                iNextY    = Int32.Parse(sSplitter[1]);
                // previous tile had x-axis (left/right) movement
                if (iPrevY == iYpos)
                {
                    if (iPrevX > iXpos)
                    {
                        // east must be open
                        oThisTileButton.BEastOpen = true;
                    }
                    else
                    {
                        // west must be open
                        oThisTileButton.BWestOpen = true;
                    }
                }
                else
                {
                    if (iPrevX > iXpos)
                    {
                        // south must be open
                        oThisTileButton.BSouthOpen = true;
                    }
                    else
                    {
                        // north must be open
                        oThisTileButton.BNorthOpen = true;
                    }
                }
                if (iNextY == iYpos)
                {
                    if (iNextX > iXpos)
                    {
                        // east must be open
                        oThisTileButton.BEastOpen = true;
                    }
                    else
                    {
                        // west must be open
                        oThisTileButton.BWestOpen = true;
                    }
                }
                else
                {
                    if (iNextX > iXpos)
                    {
                        // south must be open
                        oThisTileButton.BSouthOpen = true;
                    }
                    else
                    {
                        // north must be open
                        oThisTileButton.BNorthOpen = true;
                    }
                }

                if ((oThisTileButton.BNorthOpen) && (oThisTileButton.BEastOpen))
                {
                    sImageName = "L.BMP";
                }

                if ((oThisTileButton.BNorthOpen) && (oThisTileButton.BWestOpen))
                {
                    sImageName = "L2.BMP";
                }

                if ((oThisTileButton.BSouthOpen) && (oThisTileButton.BWestOpen))
                {
                    sImageName = "L3.BMP";
                }

                if ((oThisTileButton.BSouthOpen) && (oThisTileButton.BEastOpen))
                {
                    sImageName = "L4.BMP";
                }

                if ((oThisTileButton.BSouthOpen) && (oThisTileButton.BNorthOpen))
                {
                    sImageName = "ntos.BMP";
                }

                if ((oThisTileButton.BWestOpen) && (oThisTileButton.BEastOpen))
                {
                    sImageName = "etow.BMP";
                }
            }
            else
            {
                sImageName = "solid.BMP";
            }
            //switch (_myRandom.Next(50) % 7)
            //{
            //    case 0:
            //        sImageName = "L.BMP";
            //        oThisTileButton.BNorthOpen = true;
            //        oThisTileButton.BSouthOpen = false;
            //        oThisTileButton.BEastOpen = true;
            //        oThisTileButton.BWestOpen = false;
            //        break;
            //    case 1:
            //        sImageName = "L2.BMP";
            //        oThisTileButton.BNorthOpen = true;
            //        oThisTileButton.BSouthOpen = false;
            //        oThisTileButton.BEastOpen = false;
            //        oThisTileButton.BWestOpen = true;
            //        break;
            //    case 2:
            //        sImageName = "L3.BMP";
            //        oThisTileButton.BNorthOpen = false;
            //        oThisTileButton.BSouthOpen = true;
            //        oThisTileButton.BEastOpen = false;
            //        oThisTileButton.BWestOpen = true;
            //        break;
            //    case 3:
            //        sImageName = "L4.BMP";
            //        oThisTileButton.BNorthOpen = false;
            //        oThisTileButton.BSouthOpen = true;
            //        oThisTileButton.BEastOpen = true;
            //        oThisTileButton.BWestOpen = false;
            //        break;
            //    case 4:
            //        sImageName = "ntos.BMP";
            //        oThisTileButton.BNorthOpen = true;
            //        oThisTileButton.BSouthOpen = true;
            //        oThisTileButton.BEastOpen = false;
            //        oThisTileButton.BWestOpen = false;
            //        break;
            //    case 5:
            //        sImageName = "etow.BMP";
            //        oThisTileButton.BNorthOpen = false;
            //        oThisTileButton.BSouthOpen = false;
            //        oThisTileButton.BEastOpen = true;
            //        oThisTileButton.BWestOpen = true;
            //        break;
            //    case 6:
            //        sImageName = "solid.BMP";
            //        oThisTileButton.BNorthOpen = false;
            //        oThisTileButton.BSouthOpen = false;
            //        oThisTileButton.BEastOpen = false;
            //        oThisTileButton.BWestOpen = false;
            //        break;
            //}
            // catch the first and last items to ensure that they are castles
            if (((iXpos == 0) && (iYpos == 0)) || ((iXpos == (iXSize - 1)) && (iYpos == (iYSize - 1))))
            {
                sImageName = "castle.bmp";
                if ((iXpos == 0) && (iYpos == 0))
                {
                }
                else
                {
                }
            }
            oThisTileButton.IXPos = iXpos;
            oThisTileButton.IYPos = iYpos;
            string sPath = @"..\..\Resources\Images\" + sColor + @"\" + sImageName;

            oThisTileButton.SImage = sPath;
            return(oThisTileButton);
        }