コード例 #1
0
ファイル: WorldGen.cs プロジェクト: NordsidaSoftware/TreDe
        public bool GenerateRandomHouse()
        {
            int Width     = Randomizer.rnd.Next(3, 10);
            int Height    = Randomizer.rnd.Next(3, 10);
            int PositionX = Randomizer.rnd.Next(10, WorldWidth - (Width + 10));
            int PositionY = Randomizer.rnd.Next(10, WorldHeight - (Height + 10));
            int NRDoors   = Randomizer.rnd.Next(1, 3);

            Rectangle rectangle = new Rectangle(PositionX,
                                                PositionY,
                                                Width,
                                                Height);

            List <Point> walls = RectangleExtension.Walls(rectangle);
            List <Point> doors = new List <Point>();

            for (int door = 0; door < NRDoors; door++)
            {
                doors.Add(walls[Randomizer.rnd.Next(0, walls.Count - 1)]);
            }

            Building b = new Building(null, rectangle, doors);

            Buildings.Add(b);
            return(true);
        }
コード例 #2
0
        internal byte[,,] ReadMap()
        {
            Random rnd = new Random();

            for (int x = 0; x < worldWidth; x++)
            {
                for (int y = 0; y < worldHeight; y++)
                {
                    for (int z = 0; z < worldDepth; z++)
                    {
                        if (z == 0)
                        {
                            Map[x, y, z] = (byte)TileType.Grass;
                        }
                        else
                        {
                            Map[x, y, z] = (byte)TileType.Empty;
                        }
                    }
                }
            }

            for (int i = 0; i < (worldHeight * worldWidth) / 100; i++)
            {
                var randX = rnd.Next(0, worldWidth);
                var randY = rnd.Next(0, worldHeight);

                AddStructure(randX, randY, "Tree");
            }

            foreach (Building house in buildings)
            {
                foreach (Point p in RectangleExtension.Walls(house.Rectangle))
                {
                    AddStructure(p.X, p.Y, "HouseWall");
                }

                foreach (Point p in RectangleExtension.Area(house.Rectangle))
                {
                    Map[p.X, p.Y, 0] = (byte)TileType.Empty;
                }

                foreach (Point p in house.Doors)
                {
                    AddStructure(p.X, p.Y, "DoorClosed");
                }
            }



            return(Map);
        }