Ejemplo n.º 1
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;
                }
            }
        }
Ejemplo n.º 2
0
        public RoomMapSearchResult SearchRoom(int roomnumber, int col, int row, int dir)
        {
            // ONLY ALL is implemented
            RoomMapSearchResult searchresult = null;
            string   key        = "";
            GameRoom gm         = null;
            int      search_col = 0;
            int      search_row = 0;

            RoomMapSearchResult.SEARCH_TYPE searchtype = RoomMapSearchResult.SEARCH_TYPE.ALL_DIRECTION;

            if (roomnumber >= 1 && roomnumber <= NumberOfRooms)
            {
                search_col = col;
                search_row = row;
                gm         = GameRoomList.ElementAt(roomnumber - 1);
                searchtype = (RoomMapSearchResult.SEARCH_TYPE)dir;

                searchresult = new RoomMapSearchResult();

                if (searchtype == RoomMapSearchResult.SEARCH_TYPE.ALL_DIRECTION)
                {
                    //North
                    search_col = col;
                    search_row = row;
                    search_row--;
                    key = search_col + "-" + search_row;
                    if (gm.ItemsHashTable.ContainsKey(key) &&
                        ((IAvailable)gm.ItemsHashTable[key]).isAvailable)
                    {
                        searchresult.ItemFound++;
                        searchresult.North_Item = gm.ItemsHashTable[key];
                        if (AutoAddToInventory(gm.ItemsHashTable[key], searchresult))
                        {
                            gm.ItemsHashTable.Remove(key);
                        }
                        else
                        {
                            ProcessInventory(gm.ItemsHashTable[key], searchresult);
                        }
                    }

                    //North East
                    search_col = col;
                    search_row = row;
                    search_row--;
                    search_col++;
                    key = search_col + "-" + search_row;
                    if (gm.ItemsHashTable.ContainsKey(key) &&
                        ((IAvailable)gm.ItemsHashTable[key]).isAvailable)
                    {
                        searchresult.ItemFound++;
                        searchresult.NorthEast_Item = gm.ItemsHashTable[key];

                        if (AutoAddToInventory(gm.ItemsHashTable[key], searchresult))
                        {
                            gm.ItemsHashTable.Remove(key);
                        }
                        else
                        {
                            ProcessInventory(gm.ItemsHashTable[key], searchresult);
                        }
                    }

                    //North West
                    search_col = col;
                    search_row = row;
                    search_row--;
                    search_col--;
                    key = search_col + "-" + search_row;
                    if (gm.ItemsHashTable.ContainsKey(key) &&
                        ((IAvailable)gm.ItemsHashTable[key]).isAvailable)
                    {
                        searchresult.ItemFound++;
                        searchresult.NorthWest_Item = gm.ItemsHashTable[key];
                        if (AutoAddToInventory(gm.ItemsHashTable[key], searchresult))
                        {
                            gm.ItemsHashTable.Remove(key);
                        }
                        else
                        {
                            ProcessInventory(gm.ItemsHashTable[key], searchresult);
                        }
                    }


                    //South
                    search_col = col;
                    search_row = row;
                    search_row++;
                    key = search_col + "-" + search_row;
                    if (gm.ItemsHashTable.ContainsKey(key) &&
                        ((IAvailable)gm.ItemsHashTable[key]).isAvailable)
                    {
                        searchresult.ItemFound++;
                        searchresult.South_Item = gm.ItemsHashTable[key];
                        if (AutoAddToInventory(gm.ItemsHashTable[key], searchresult))
                        {
                            gm.ItemsHashTable.Remove(key);
                        }
                        else
                        {
                            ProcessInventory(gm.ItemsHashTable[key], searchresult);
                        }
                    }

                    //South East
                    search_col = col;
                    search_row = row;
                    search_row++;
                    search_col++;
                    key = search_col + "-" + search_row;
                    if (gm.ItemsHashTable.ContainsKey(key) &&
                        ((IAvailable)gm.ItemsHashTable[key]).isAvailable)
                    {
                        searchresult.ItemFound++;
                        searchresult.SouthEast_Item = gm.ItemsHashTable[key];
                        if (AutoAddToInventory(gm.ItemsHashTable[key], searchresult))
                        {
                            gm.ItemsHashTable.Remove(key);
                        }
                        else
                        {
                            ProcessInventory(gm.ItemsHashTable[key], searchresult);
                        }
                    }

                    //South West
                    search_col = col;
                    search_row = row;
                    search_row++;
                    search_col--;
                    key = search_col + "-" + search_row;
                    if (gm.ItemsHashTable.ContainsKey(key) &&
                        ((IAvailable)gm.ItemsHashTable[key]).isAvailable)
                    {
                        searchresult.ItemFound++;
                        searchresult.West_Item = gm.ItemsHashTable[key];
                        if (AutoAddToInventory(gm.ItemsHashTable[key], searchresult))
                        {
                            gm.ItemsHashTable.Remove(key);
                        }
                        else
                        {
                            ProcessInventory(gm.ItemsHashTable[key], searchresult);
                        }
                    }


                    //East
                    search_col = col;
                    search_row = row;
                    search_col++;
                    key = search_col + "-" + search_row;
                    if (gm.ItemsHashTable.ContainsKey(key) &&
                        ((IAvailable)gm.ItemsHashTable[key]).isAvailable)
                    {
                        searchresult.ItemFound++;
                        searchresult.East_Item = gm.ItemsHashTable[key];
                        if (AutoAddToInventory(gm.ItemsHashTable[key], searchresult))
                        {
                            gm.ItemsHashTable.Remove(key);
                        }
                        else
                        {
                            ProcessInventory(gm.ItemsHashTable[key], searchresult);
                        }
                    }

                    //West
                    search_col = col;
                    search_row = row;
                    search_col--;
                    key = search_col + "-" + search_row;
                    if (gm.ItemsHashTable.ContainsKey(key) &&
                        ((IAvailable)gm.ItemsHashTable[key]).isAvailable)
                    {
                        searchresult.ItemFound++;
                        searchresult.East_Item = gm.ItemsHashTable[key];
                        if (AutoAddToInventory(gm.ItemsHashTable[key], searchresult))
                        {
                            gm.ItemsHashTable.Remove(key);
                        }
                        else
                        {
                            ProcessInventory(gm.ItemsHashTable[key], searchresult);
                        }
                    }
                }
            }

            return(searchresult);
        }