コード例 #1
0
        public static void build(Region region, int x, int y, Building building)
        {
            switch (building.getBuildingType())
            {
                case BuildingType.BANK:
                    buildByArray(region, x, y, building, bankStruct);
                    break;

                case BuildingType.INN:
                    buildByArray(region, x, y, building, innStruct);
                    building.setLit(false);
                    break;

                case BuildingType.HOUSE:
                    buildByArray(region, x, y, building, houseStruct);
                    break;

                case BuildingType.FOOD_STORE:
                    buildByArray(region, x, y, building, foodStoreStruct);
                    break;

                case BuildingType.TOOL_STORE:
                    buildByArray(region, x, y, building, toolStoreStruct);
                    break;
            }
        }
コード例 #2
0
 public object CopyObject()
 {
     Building newBuild = new Building();
     newBuild.setName(this.getName());
     newBuild.setX(this.x);
     newBuild.setY(this.y);
     newBuild.setWidth(this.width);
     newBuild.setHeight(this.height);
     newBuild.setBuildingType(this.buildingType);
     newBuild.setDoor(this.door.x, this.door.y);
     newBuild.setLit(this.isLit());
     newBuild.setRoofType(this.roofType);
     return newBuild;
 }
コード例 #3
0
ファイル: Region.cs プロジェクト: seaweedfactory/LumberjackRL
        public void LoadObject(StreamReader inStream)
        {
            this.width = Int32.Parse(inStream.ReadLine());
            this.height = Int32.Parse(inStream.ReadLine());
            terrainField = new Terrain[getWidth(),getHeight()];
            for(int x=0; x < getWidth(); x++)
            {
                for(int y=0; y < getHeight(); y++)
                {
                    Terrain newTerrain = new Terrain();
                    newTerrain.LoadObject(inStream);
                    terrainField[x,y] = newTerrain;
                }
            }
            getMonsters().Clear();
            int monstersSize = Int32.Parse(inStream.ReadLine());
            for(int i=0; i < monstersSize; i++)
            {
                Monster newMonster = new Monster();
                newMonster.LoadObject(inStream);

                //do not load any monster with the player ID
                if(!newMonster.ID.Equals(MonsterActionManager.PLAYER_ID))
                {
                    getMonsters().Add(newMonster);
                }
            }
            getItems().Clear();
            int itemsSize = Int32.Parse(inStream.ReadLine());
            for(int i=0; i < itemsSize; i++)
            {
                Item newItem = new Item();
                newItem.LoadObject(inStream);
                getItems().Add(newItem);
            }
            getBuildings().Clear();
            int buildSize = Int32.Parse(inStream.ReadLine());
            for(int i=0; i < buildSize; i++)
            {
                Building newBuild = new Building();
                newBuild.LoadObject(inStream);
                getBuildings().Add(newBuild);
            }
            this.lightingModel = (LightingModel)Enum.Parse(typeof(LightingModel), inStream.ReadLine());
        }
コード例 #4
0
        public void generate()
        {
            int centerX = (int)(region.getWidth() / 2);
            int centerY = (int)(region.getHeight() / 2);
            int distanceCutoff = (int)(centerX * radius);

            //make the town center
            for (int x = 0; x < region.getWidth(); x++)
            {
                for (int y = 0; y < region.getHeight(); y++)
                {
                    region.setTerrain(x, y, new Terrain());
                    int distance = (int)(Math.Sqrt(((x - centerX) * (x - centerX)) + ((y - centerY) * (y - centerY))));
                    if (distance > distanceCutoff + RandomNumber.RandomInteger(wiggle))
                    {
                        region.getTerrain(x, y).setCode(TerrainCode.GRASS);
                    }
                    else
                    {
                        region.getTerrain(x, y).setCode(TerrainCode.DIRT);
                    }
                }
            }

            //make the path
            MapGenerator.makePath(region, overworldCell.nExit, overworldCell.eExit, overworldCell.sExit, overworldCell.wExit);

            //add trees
            MapGenerator.addTrees(region, treeDensity);

            //add grave yard
            MapGenerator.addGraveyard(15, 10, region.getWidth() - 19, region.getHeight() - 14, region);

            //add buildings
            Building bank = new Building();
            bank.setBuildingType(BuildingType.BANK);
            BuildingManager.initialize(bank);
            bank.setPosition((region.getWidth() / 10) * 3, (int)((region.getHeight() / 10) * 2.5));
            region.getBuildings().Add(bank);

            Building inn = new Building();
            inn.setBuildingType(BuildingType.INN);
            BuildingManager.initialize(inn);
            inn.setPosition(3 + ((region.getWidth() / 10) * 5), (int)((region.getHeight() / 10) * 2.5));
            region.getBuildings().Add(inn);

            for (int i = 0; i < 3; i++)
            {
                Building house = new Building();
                if (i == 1)
                {
                    house.setBuildingType(BuildingType.HOUSE);
                }
                else if (i == 0)
                {
                    house.setBuildingType(BuildingType.FOOD_STORE);
                }
                else if (i == 2)
                {
                    house.setBuildingType(BuildingType.TOOL_STORE);
                }
                BuildingManager.initialize(house);
                house.setPosition((region.getWidth() / 10) * (4 + (i * 2)), (int)((region.getHeight() / 10) * 6));
                region.getBuildings().Add(house);
            }

            region.buildBuildings();

            //Add a pond in the corner
            region.getTerrain(7, 7).getParameters().Add(TerrainParameter.HAS_SPRING, TerrainManager.SPRING_RATE + "");
            for (int x = 4; x < 10; x++)
            {
                for (int y = 4; y < 10; y++)
                {
                    region.getTerrain(x, y).setCode(TerrainCode.STREAM_BED);
                }
            }
        }
コード例 #5
0
        public static void buildByArray(Region region, int startX, int startY, Building building, int[,] plan)
        {
            for (int x = 0; x < BuildingManager.getWidth(building.getBuildingType()); x++)
            {
                for (int y = 0; y < BuildingManager.getHeight(building.getBuildingType()); y++)
                {
                    if (x + startX < region.getWidth() && x + startX > 0
                    && y + startY < region.getHeight() && y + startY > 0)
                    {
                        switch (plan[y,x])
                        {
                            case 0:
                                region.getTerrain(startX + x, startY + y).setCode(TerrainCode.STONE_FLOOR);
                                break;

                            case 1:
                                region.getTerrain(startX + x, startY + y).setCode(TerrainCode.STONE_WALL);
                                break;

                            case 9:
                                region.getTerrain(startX + x, startY + y).setCode(TerrainCode.STONE_FLOOR);
                                region.getTerrain(startX + x, startY + y).getParameters().Add(TerrainParameter.HAS_DOOR, Enum.GetName(typeof(DoorCode), DoorCode.CLOSED));
                                building.setDoor(startX + x, startY + y);
                                break;

                            case 8:
                                region.getTerrain(startX + x, startY + y).setCode(TerrainCode.STONE_WALL);
                                region.getTerrain(startX + x, startY + y).getParameters().Add(TerrainParameter.HAS_SIGN, building.getName());
                                break;

                            case 2:
                                region.getTerrain(startX + x, startY + y).setCode(TerrainCode.STONE_FLOOR);
                                Monster newMon = new Monster();
                                switch (building.getBuildingType())
                                {
                                    case BuildingType.BANK:
                                        newMon.monsterCode = MonsterCode.HUMAN;
                                        newMon.role = MonsterRole.BANKER;
                                        break;

                                    case BuildingType.INN:
                                        newMon.monsterCode = MonsterCode.HUMAN;
                                        newMon.role = MonsterRole.NULL;
                                        break;

                                    case BuildingType.FOOD_STORE:
                                        newMon.monsterCode = MonsterCode.HUMAN;
                                        newMon.role = MonsterRole.CHEF;
                                        break;

                                    case BuildingType.TOOL_STORE:
                                        newMon.monsterCode = MonsterCode.HUMAN;
                                        newMon.role = MonsterRole.HANDYMAN;
                                        break;
                                }
                                MonsterActionManager.initialize(newMon);
                                newMon.setPosition(startX + x, startY + y);
                                region.getMonsters().Add(newMon);
                                break;

                            case 3:
                                //Add a bed
                                region.getTerrain(startX + x, startY + y).setCode(TerrainCode.STONE_FLOOR);
                                region.getTerrain(startX + x, startY + y).getParameters().Add(TerrainParameter.HAS_BED, "");
                                break;
                        }
                    }
                }
            }
        }
コード例 #6
0
        public static String makeBuildingName(Building building)
        {
            switch (building.getBuildingType())
            {
                case BuildingType.BANK:
                    return NameMaker.makeBankName();

                case BuildingType.FOOD_STORE:
                    return NameMaker.makeFoodName();

            }
            return EnumUtil.EnumName<BuildingType>(building.getBuildingType());
        }
コード例 #7
0
 public static void initialize(Building building)
 {
     building.setWidth(getWidth(building.getBuildingType()));
     building.setHeight(getHeight(building.getBuildingType()));
     building.setName(BuildingManager.makeBuildingName(building));
 }