示例#1
0
        public bool TryLoadMapCache(out AbstractMatterType[,] mapCache, int width, int height)
        {
            mapCache = null;
            FileInfo file = new FileInfo(originalFileName + fileSuffix);

            if (!file.Exists)
            {
                return(false);
            }

            AbstractMatterType wall = new MatterTypeWall();

            mapCache = new AbstractMatterType[width, height];

            int x = 0;
            int y = 0;

            using (BinaryReader binaryReader = new BinaryReader(File.Open(originalFileName + fileSuffix, FileMode.Open)))
            {
                int position = 0;
                int length   = (int)binaryReader.BaseStream.Length;

                List <bool> boolList = new List <bool>(8);
                for (int i = 0; i < 8; i++)
                {
                    boolList.Add(false);
                }

                while (position < length)
                {
                    byte byteFromFile = binaryReader.ReadByte();

                    WriteByteToBoolList(byteFromFile, boolList);

                    foreach (bool boolean in boolList)
                    {
                        if (boolean)
                        {
                            mapCache[x, y] = wall;
                        }
                        else
                        {
                            mapCache[x, y] = null;
                        }

                        x++;
                        if (x == width)
                        {
                            x = 0;
                            y++;
                        }
                    }

                    position += sizeof(byte);
                }
            }

            return(true);
        }
示例#2
0
        public MapFromImage(string imageFileName, Random random)
        {
            Bitmap bitmap = new Bitmap(imageFileName);

            imageWidth  = bitmap.Width;
            imageHeight = bitmap.Height;

            width  = (int)Math.Ceiling((double)imageWidth * precision);
            height = (int)Math.Ceiling((double)imageHeight * precision);

            imageCache = new ImageCache(imageFileName);

            if (!imageCache.TryLoadMapCache(out mapCache, bitmap.Width, bitmap.Height))
            {
                mapCache = new AbstractMatterType[imageWidth, imageHeight];

                AbstractMatterType wall = new MatterTypeWall();

                Color currentPixelColor;
                for (int x = 0; x < bitmap.Width; x++)
                {
                    for (int y = 0; y < bitmap.Height; y++)
                    {
                        currentPixelColor = bitmap.GetPixel(x, y);

                        if (currentPixelColor.R > 128)
                        {
                            mapCache[x, y] = null;
                        }
                        else
                        {
                            mapCache[x, y] = wall;
                        }
                    }
                }

                imageCache.SaveCache(mapCache, bitmap.Width, bitmap.Height);
            }

            colorMap = new ColorMap(random, width, height);
        }
示例#3
0
        /// <summary>
        /// Create hardcoded map
        /// </summary>
        public HardCodedMap()
        {
            internalMap = new AbstractMatterType[height, width];

            AbstractMatterType wall = new MatterTypeWall();

            AddRow(0, new AbstractMatterType[] { wall, wall, wall, wall, wall, wall, wall, wall, wall, wall, wall, wall, wall, wall, wall, wall });
            AddRow(1, new AbstractMatterType[] { wall, null, null, null, wall, null, null, wall, null, wall, null, null, null, null, null, wall });
            AddRow(2, new AbstractMatterType[] { wall, null, wall, null, null, null, null, wall, null, null, null, null, null, wall, null, wall });
            AddRow(3, new AbstractMatterType[] { wall, null, wall, null, null, null, null, wall, null, null, null, null, null, wall, null, wall });
            AddRow(4, new AbstractMatterType[] { wall, null, wall, wall, wall, wall, null, wall, null, null, null, null, wall, wall, null, wall });
            AddRow(5, new AbstractMatterType[] { wall, null, null, wall, wall, wall, null, wall, null, null, null, null, wall, null, null, wall });
            AddRow(6, new AbstractMatterType[] { wall, null, null, null, null, null, null, wall, null, null, null, null, wall, null, wall, wall });
            AddRow(7, new AbstractMatterType[] { wall, null, null, wall, wall, null, wall, wall, wall, wall, null, null, wall, null, wall, wall });
            AddRow(8, new AbstractMatterType[] { wall, null, null, wall, wall, null, wall, wall, wall, wall, null, null, wall, null, null, wall });
            AddRow(9, new AbstractMatterType[] { wall, null, null, null, null, null, wall, wall, wall, wall, null, wall, wall, null, null, wall });
            AddRow(10, new AbstractMatterType[] { wall, null, wall, wall, wall, null, wall, wall, null, null, null, null, wall, null, wall, wall });
            AddRow(11, new AbstractMatterType[] { wall, null, wall, null, null, null, null, wall, wall, null, null, null, wall, null, wall, wall });
            AddRow(12, new AbstractMatterType[] { wall, null, wall, wall, wall, null, null, wall, wall, null, null, null, null, null, null, wall });
            AddRow(13, new AbstractMatterType[] { wall, null, null, null, null, null, null, null, null, null, null, null, null, null, null, wall });
            AddRow(14, new AbstractMatterType[] { wall, null, null, null, null, null, null, wall, null, null, wall, null, wall, null, null, wall });
            AddRow(15, new AbstractMatterType[] { wall, wall, wall, wall, wall, wall, wall, wall, wall, wall, wall, wall, wall, wall, wall, wall });
        }