예제 #1
0
        public Point GetRoomWorldMapCentrePos(int roomNumner)
        {
            RoomMap item = null;
            Point   pos  = new Point(0, 0);

            item = RoomMapList.ElementAt(roomNumner - 1);

            if (item != null)
            {
                pos = new Point(
                    item.TopLeftCol + (item.BottomRightCol - item.TopLeftCol) / 2,
                    item.TopLeftRow + (item.BottomRightRow - item.TopLeftRow) / 2
                    );
            }
            return(pos);
        }
예제 #2
0
        //Main Data Structure
        public GameWorldInfo()
        {
            RoomMapFileInfo rmmapInfo = null;

            WorldMapInfo = new WorldMap();
            rmmapInfo    = RoomInfoFileReader.ReadRoomMapInfo(ConfigManager.RoomInfoFile);

            RoomMapList       = rmmapInfo.roomaplist;
            dropPointlist     = rmmapInfo.dropPointlist;
            boundaryPointlist = rmmapInfo.boundaryPointlist;

            if (RoomMapList != null)
            {
                NumberOfRooms = RoomMapList.Count;
            }

            The_Player = new Player(0, 0);  //Init the Player

            GameRoom rm = null;

            for (int roomindex = 0; roomindex < NumberOfRooms; roomindex++)
            {
                GameRoomList.Add(new GameRoom(RoomMapList.ElementAt(roomindex)));
                rm = GameRoomList.ElementAt(roomindex);
                rm.GenerateEnvrionemnt();
                NumberOfMonster = NumberOfMonster + rm.MonsterList.Count;
                NumberOfGlobin  = NumberOfGlobin + rm.GlobinList.Count;
            }

            //Generate item in room

            int    maxnoitem = ConfigManager.MaxChestPerWorld;
            int    rmindex   = 0;
            Random random    = ConfigManager.RandomGen;
            Dictionary <string, string> ItemsHashTable = new Dictionary <string, string>();
            int    col      = 0;
            int    row      = 0;
            Chest  chestobj = null;
            String key      = null;

            //Chest First
            for (int item = 0; item < maxnoitem; item++)
            {
                while (true)
                {
                    rmindex = random.Next(0, NumberOfRooms - 1);   //Get a Random Room

                    if (!ItemsHashTable.ContainsKey(Convert.ToString(rmindex)))
                    {
                        ItemsHashTable.Add(Convert.ToString(rmindex), Convert.ToString(rmindex));
                        rm = GameRoomList.ElementAt(rmindex);

                        while (true)
                        {
                            col = random.Next(
                                ((RoomMap.RoomWidth - RoomMap.RoomEffectiveWidth) / 2) + 1,
                                ((RoomMap.RoomWidth - RoomMap.RoomEffectiveWidth) / 2) + RoomMap.RoomEffectiveWidth - 1);

                            row = random.Next(0, RoomMap.RoomHeight - 1);
                            if (!rm.IsLocationInRoomTaken(col, row) && rm.Room_Map.IsEmpty(col, row))
                            {
                                key      = col + "-" + row;
                                chestobj = new Chest("Treasure Chest", col + PlayUIWorldMap.mapBoxColPos, row + PlayUIWorldMap.mapBoxRowPos, key);
                                rm.ChestList.Add(chestobj);
                                rm.ItemsHashTable.Add(key, chestobj);
                                rm.TotalItem++;
                                break;
                            }
                        }
                    }
                    break;
                }
            }

            //Key Next
            maxnoitem = ConfigManager.MaxKeyPerWorld;
            Key keyobj = null;

            ItemsHashTable = new Dictionary <string, string>();

            for (int item = 0; item < maxnoitem; item++)
            {
                while (true)
                {
                    rmindex = random.Next(0, NumberOfRooms - 1);   //Get a Random Room

                    if (!ItemsHashTable.ContainsKey(Convert.ToString(rmindex)))
                    {
                        ItemsHashTable.Add(Convert.ToString(rmindex), Convert.ToString(rmindex));
                        rm = GameRoomList.ElementAt(rmindex);

                        while (true)
                        {
                            col = random.Next(
                                ((RoomMap.RoomWidth - RoomMap.RoomEffectiveWidth) / 2) + 1,
                                ((RoomMap.RoomWidth - RoomMap.RoomEffectiveWidth) / 2) + RoomMap.RoomEffectiveWidth - 1);

                            row = random.Next(0, RoomMap.RoomHeight - 1);
                            if (!rm.IsLocationInRoomTaken(col, row) && rm.Room_Map.IsEmpty(col, row))
                            {
                                key    = col + "-" + row;
                                keyobj = new Key("Treasure Chest Key", col + PlayUIWorldMap.mapBoxColPos, row + PlayUIWorldMap.mapBoxRowPos, key);
                                rm.KeyList.Add(keyobj);
                                rm.ItemsHashTable.Add(key, keyobj);
                                rm.TotalItem++;
                                break;
                            }
                        }
                    }
                    break;
                }
            }

            //Iron Armour Next
            maxnoitem = ConfigManager.MaxIronArmourPerWorld;
            IronArmour amobj = null;

            ItemsHashTable = new Dictionary <string, string>();

            for (int item = 0; item < maxnoitem; item++)
            {
                while (true)
                {
                    rmindex = random.Next(0, NumberOfRooms - 1);   //Get a Random Room

                    if (!ItemsHashTable.ContainsKey(Convert.ToString(rmindex)))
                    {
                        ItemsHashTable.Add(Convert.ToString(rmindex), Convert.ToString(rmindex));
                        rm = GameRoomList.ElementAt(rmindex);

                        while (true)
                        {
                            col = random.Next(
                                ((RoomMap.RoomWidth - RoomMap.RoomEffectiveWidth) / 2) + 1,
                                ((RoomMap.RoomWidth - RoomMap.RoomEffectiveWidth) / 2) + RoomMap.RoomEffectiveWidth - 1);

                            row = random.Next(0, RoomMap.RoomHeight - 1);
                            if (!rm.IsLocationInRoomTaken(col, row) && rm.Room_Map.IsEmpty(col, row))
                            {
                                key   = col + "-" + row;
                                amobj = new IronArmour("Iron Armour", col + PlayUIWorldMap.mapBoxColPos, row + PlayUIWorldMap.mapBoxRowPos, key);
                                rm.ArmourList.Add(amobj);
                                rm.ItemsHashTable.Add(key, amobj);
                                rm.TotalItem++;
                                break;
                            }
                        }
                    }
                    break;
                }
            }

            //Wooden Armour Next
            maxnoitem = ConfigManager.MaxWoodenArmourPerWorld;
            WoodenArmour wmobj = null;

            ItemsHashTable = new Dictionary <string, string>();

            for (int item = 0; item < maxnoitem; item++)
            {
                while (true)
                {
                    rmindex = random.Next(0, NumberOfRooms - 1);   //Get a Random Room

                    if (!ItemsHashTable.ContainsKey(Convert.ToString(rmindex)))
                    {
                        ItemsHashTable.Add(Convert.ToString(rmindex), Convert.ToString(rmindex));
                        rm = GameRoomList.ElementAt(rmindex);

                        while (true)
                        {
                            col = random.Next(
                                ((RoomMap.RoomWidth - RoomMap.RoomEffectiveWidth) / 2) + 1,
                                ((RoomMap.RoomWidth - RoomMap.RoomEffectiveWidth) / 2) + RoomMap.RoomEffectiveWidth - 1);

                            row = random.Next(0, RoomMap.RoomHeight - 1);
                            if (!rm.IsLocationInRoomTaken(col, row) && rm.Room_Map.IsEmpty(col, row))
                            {
                                key   = col + "-" + row;
                                wmobj = new WoodenArmour("Wooden Armour", col + PlayUIWorldMap.mapBoxColPos, row + PlayUIWorldMap.mapBoxRowPos, key);
                                rm.ArmourList.Add(wmobj);
                                rm.ItemsHashTable.Add(key, wmobj);
                                rm.TotalItem++;
                                break;
                            }
                        }
                    }
                    break;
                }
            }


            //Iron Sword Next
            maxnoitem = ConfigManager.MaxIronSwordPerWorld;
            IronSword iswbj = null;

            ItemsHashTable = new Dictionary <string, string>();

            for (int item = 0; item < maxnoitem; item++)
            {
                while (true)
                {
                    rmindex = random.Next(0, NumberOfRooms - 1);   //Get a Random Room

                    if (!ItemsHashTable.ContainsKey(Convert.ToString(rmindex)))
                    {
                        ItemsHashTable.Add(Convert.ToString(rmindex), Convert.ToString(rmindex));
                        rm = GameRoomList.ElementAt(rmindex);

                        while (true)
                        {
                            col = random.Next(
                                ((RoomMap.RoomWidth - RoomMap.RoomEffectiveWidth) / 2) + 1,
                                ((RoomMap.RoomWidth - RoomMap.RoomEffectiveWidth) / 2) + RoomMap.RoomEffectiveWidth - 1);

                            row = random.Next(0, RoomMap.RoomHeight - 1);
                            if (!rm.IsLocationInRoomTaken(col, row) && rm.Room_Map.IsEmpty(col, row))
                            {
                                key   = col + "-" + row;
                                iswbj = new IronSword("Iron Sword", col + PlayUIWorldMap.mapBoxColPos, row + PlayUIWorldMap.mapBoxRowPos, key);
                                rm.WeaponList.Add(iswbj);
                                rm.ItemsHashTable.Add(key, iswbj);
                                rm.TotalItem++;
                                break;
                            }
                        }
                    }
                    break;
                }
            }


            //Wooden Sword Next
            maxnoitem = ConfigManager.MaxWoodenSwordPerWorld;
            WoodenSword wswbj = null;

            ItemsHashTable = new Dictionary <string, string>();

            for (int item = 0; item < maxnoitem; item++)
            {
                while (true)
                {
                    rmindex = random.Next(0, NumberOfRooms - 1);   //Get a Random Room

                    if (!ItemsHashTable.ContainsKey(Convert.ToString(rmindex)))
                    {
                        ItemsHashTable.Add(Convert.ToString(rmindex), Convert.ToString(rmindex));
                        rm = GameRoomList.ElementAt(rmindex);

                        while (true)
                        {
                            col = random.Next(
                                ((RoomMap.RoomWidth - RoomMap.RoomEffectiveWidth) / 2) + 1,
                                ((RoomMap.RoomWidth - RoomMap.RoomEffectiveWidth) / 2) + RoomMap.RoomEffectiveWidth - 1);

                            row = random.Next(0, RoomMap.RoomHeight - 1);
                            if (!rm.IsLocationInRoomTaken(col, row) && rm.Room_Map.IsEmpty(col, row))
                            {
                                key   = col + "-" + row;
                                wswbj = new WoodenSword("Wooden Sword", col + PlayUIWorldMap.mapBoxColPos, row + PlayUIWorldMap.mapBoxRowPos, key);
                                rm.WeaponList.Add(wswbj);
                                rm.ItemsHashTable.Add(key, wswbj);
                                rm.TotalItem++;
                                break;
                            }
                        }
                    }
                    break;
                }
            }
        }