// Map surroundings
        internal void Surroundings(List <CurrentMapObjects> nearObjects, CurrentMapObjects item, GameBoard board)
        {
            if (item.Position.Row == this.Position.Row && item.Position.Col == this.Position.Col)
            {
                nearObjects.Add(new CurrentMapObjects(item.Position, item.Name, item.Info, "on your current position:"));
                board.cells[item.Position.Row, item.Position.Col] = new BoardCells((char)item.Name, false, new Position(item.Position.Row, item.Position.Col));
            }

            if (item.Position.Row == this.Position.Row - 1 && item.Position.Col == this.Position.Col)
            {
                nearObjects.Add(new CurrentMapObjects(item.Position, item.Name, item.Info, "N:"));
                board.cells[item.Position.Row, item.Position.Col] = new BoardCells((char)item.Name, false, new Position(item.Position.Row, item.Position.Col));
            }

            if (item.Position.Row == this.Position.Row + 1 && item.Position.Col == this.Position.Col)
            {
                nearObjects.Add(new CurrentMapObjects(item.Position, item.Name, item.Info, "S:"));
                board.cells[item.Position.Row, item.Position.Col] = new BoardCells((char)item.Name, false, new Position(item.Position.Row, item.Position.Col));
            }

            if (item.Position.Row == this.Position.Row && item.Position.Col == this.Position.Col - 1)
            {
                nearObjects.Add(new CurrentMapObjects(item.Position, item.Name, item.Info, "W:"));
                board.cells[item.Position.Row, item.Position.Col] = new BoardCells((char)item.Name, false, new Position(item.Position.Row, item.Position.Col));
            }

            if (item.Position.Row == this.Position.Row && item.Position.Col == this.Position.Col + 1)
            {
                nearObjects.Add(new CurrentMapObjects(item.Position, item.Name, item.Info, "E:"));
                board.cells[item.Position.Row, item.Position.Col] = new BoardCells((char)item.Name, false, new Position(item.Position.Row, item.Position.Col));
            }

            if (item.Position.Row == this.Position.Row - 1 && item.Position.Col == this.Position.Col - 1)
            {
                nearObjects.Add(new CurrentMapObjects(item.Position, item.Name, item.Info, "NW:"));
                board.cells[item.Position.Row, item.Position.Col] = new BoardCells((char)item.Name, false, new Position(item.Position.Row, item.Position.Col));
            }

            if (item.Position.Row == this.Position.Row - 1 && item.Position.Col == this.Position.Col + 1)
            {
                nearObjects.Add(new CurrentMapObjects(item.Position, item.Name, item.Info, "NE:"));
                board.cells[item.Position.Row, item.Position.Col] = new BoardCells((char)item.Name, false, new Position(item.Position.Row, item.Position.Col));
            }

            if (item.Position.Row == this.Position.Row + 1 && item.Position.Col == this.Position.Col - 1)
            {
                nearObjects.Add(new CurrentMapObjects(item.Position, item.Name, item.Info, "SW:"));
                board.cells[item.Position.Row, item.Position.Col] = new BoardCells((char)item.Name, false, new Position(item.Position.Row, item.Position.Col));
            }

            if (item.Position.Row == this.Position.Row + 1 && item.Position.Col == this.Position.Col + 1)
            {
                nearObjects.Add(new CurrentMapObjects(item.Position, item.Name, item.Info, "SE:"));
                board.cells[item.Position.Row, item.Position.Col] = new BoardCells((char)item.Name, false, new Position(item.Position.Row, item.Position.Col));
            }
        }
        public void DefineBoard(Levels lvl)
        {
            player = new Player((char)Chars.player, currentHealth, new Position(rnd.Next(RowSize), 0), inventory);

            exit = new CurrentMapObjects(new Position(rnd.Next(RowSize), (ColSize - 1)), Chars.exit, "reach the exit!");

            map = new CurrentMapObjects(new Position(rnd.Next(RowSize), rnd.Next(ColSize)), Chars.map, "reveals level info");

            cells = new BoardCells[RowSize, ColSize];

            lvl.Setup(player, exit, map, itemList, pickItems, traps, food, weapons, enemies, RowSize, ColSize, cells);
        }
Esempio n. 3
0
        /// <summary>
        /// this method checks the player's current position and shows what's
        /// on their surroundings (N, S, E, W, NW, SW, NE, SE)
        /// </summary>
        /// <param name="nearObjects">object in map toroidal to player</param>
        /// <param name="item">each item to check</param>
        /// <param name="board">gameboard in use</param>
        internal void Surroundings(List <CurrentMapObjects> nearObjects,
                                   CurrentMapObjects item, GameBoard board)
        {
            // check player's current position items
            if (item.Position.Row == this.Position.Row && item.Position.Col ==
                Position.Col)
            {
                nearObjects.Add(new CurrentMapObjects(item.Position, item.Name,
                                                      item.Info, "on your current position:"));
                board.cells[item.Position.Row, item.Position.Col] =
                    new BoardCells((char)item.Name, false);
            }

            // check player's North items
            if (item.Position.Row == this.Position.Row - 1 && item.Position.Col
                == this.Position.Col)
            {
                nearObjects.Add(new CurrentMapObjects(item.Position, item.Name,
                                                      item.Info, "N:"));
                board.cells[item.Position.Row, item.Position.Col] =
                    new BoardCells((char)item.Name, false);
            }

            // check player's South items
            if (item.Position.Row == this.Position.Row + 1 && item.Position.Col
                == this.Position.Col)
            {
                nearObjects.Add(new CurrentMapObjects(item.Position, item.Name,
                                                      item.Info, "S:"));
                board.cells[item.Position.Row, item.Position.Col] =
                    new BoardCells((char)item.Name, false);
            }

            // check player's West items
            if (item.Position.Row == this.Position.Row && item.Position.Col ==
                this.Position.Col - 1)
            {
                nearObjects.Add(new CurrentMapObjects(item.Position, item.Name,
                                                      item.Info, "W:"));
                board.cells[item.Position.Row, item.Position.Col] = new
                                                                    BoardCells((char)item.Name, false);
            }

            // check player's East items
            if (item.Position.Row == this.Position.Row && item.Position.Col ==
                this.Position.Col + 1)
            {
                nearObjects.Add(new CurrentMapObjects(item.Position, item.Name,
                                                      item.Info, "E:"));
                board.cells[item.Position.Row, item.Position.Col] = new
                                                                    BoardCells((char)item.Name, false);
            }

            // check player's NorthWest items
            if (item.Position.Row == this.Position.Row - 1 && item.Position.Col
                == this.Position.Col - 1)
            {
                nearObjects.Add(new CurrentMapObjects(item.Position,
                                                      item.Name, item.Info, "NW:"));
                board.cells[item.Position.Row, item.Position.Col] = new
                                                                    BoardCells((char)item.Name, false);
            }

            // check player's NorthEast items
            if (item.Position.Row == this.Position.Row - 1 && item.Position.Col
                == this.Position.Col + 1)
            {
                nearObjects.Add(new CurrentMapObjects(item.Position, item.Name,
                                                      item.Info, "NE:"));
                board.cells[item.Position.Row, item.Position.Col] = new
                                                                    BoardCells((char)item.Name, false);
            }

            // check player's SouthWest items
            if (item.Position.Row == this.Position.Row + 1 && item.Position.Col
                == this.Position.Col - 1)
            {
                nearObjects.Add(new CurrentMapObjects(item.Position, item.Name,
                                                      item.Info, "SW:"));
                board.cells[item.Position.Row, item.Position.Col] =
                    new BoardCells((char)item.Name, false);
            }

            // check player's SouthEast items
            if (item.Position.Row == this.Position.Row + 1 && item.Position.Col
                == this.Position.Col + 1)
            {
                nearObjects.Add(new CurrentMapObjects(item.Position,
                                                      item.Name, item.Info, "SE:"));
                board.cells[item.Position.Row, item.Position.Col] = new
                                                                    BoardCells((char)item.Name, false);
            }
        }
        /// <summary>
        /// This Function sets up a level with its specific objects to make a
        /// level for the game
        /// </summary>
        /// <param name="player"> Get player for level</param>
        /// <param name="exit"> Get an exit point for level</param>
        /// <param name="map"> set a map to show objects of level</param>
        /// <param name="items"> For the storation of items</param>
        /// <param name="grabItems"> To grab items on level</param>
        /// <param name="traps"> Set traps on level</param>
        /// <param name="foods"> Set food on level</param>
        /// <param name="weapons"> Set weapons on level</param>
        /// <param name="enemies"> Set enemies on level</param>
        /// <param name="RowSize"> Get row on level </param>
        /// <param name="ColSize"> get col on level</param>
        /// <param name="cells"> get the cells from level</param>
        internal void Setup(Player player, CurrentMapObjects exit,
                            CurrentMapObjects map, List <CurrentMapObjects> items,
                            List <Items> grabItems, List <Trap> traps, List <Food> foods,
                            List <Weapons> weapons, List <Enemy> enemies,
                            int RowSize, int ColSize, BoardCells[,] cells)
        {
            // Max size of objects in Levels
            int maxTrapsInLvl   = Linear(Current, Diff, 2);
            int maxItemsInLvl   = Linear(Current, Diff, 2);
            int maxEnemiesInLvl = Linear(Current, Diff, 2);

            //Add objects to item list
            items.Add(exit);
            items.Add(map);

            // Generate a random numb of objects in level
            int numberOfTraps   = rnd.Next(maxTrapsInLvl);
            int numberOfItems   = rnd.Next(maxItemsInLvl);
            int numberOfEnemies = rnd.Next(maxEnemiesInLvl);

            // Set random Traps around on map and put a trap with its specific
            // information about the object and add it to its lists
            for (int i = 0; i < numberOfTraps; i++)
            {
                int  row  = rnd.Next(RowSize);
                int  col  = rnd.Next(ColSize);
                Trap trap = new Trap((new Position(row, col)), Chars.trap,
                                     $"this is a trap! watch out!", rnd.Next(100));

                traps.Add(trap);
                items.Add(trap);
            }

            // Set random Items around the map and put a map with its specific
            // information about the object and add it to its lists
            for (int i = 0; i < numberOfItems; i++)
            {
                Position foodPosition;
                Position weaponPosition;

                do
                {
                    foodPosition = new Position(rnd.Next(RowSize), rnd.Next(ColSize));
                }while (foodPosition.Row == exit.Position.Row &&
                        foodPosition.Col == exit.Position.Col);

                do
                {
                    weaponPosition = new Position(rnd.Next(RowSize), rnd.Next(ColSize));
                }while (weaponPosition.Row == exit.Position.Row &&
                        weaponPosition.Col == exit.Position.Col);

                Food food = new Food(foodPosition, Chars.food,
                                     " An apple a day keeps god astray", rnd.Next(10),
                                     rnd.Next(100));

                Weapons weapon = new Weapons(weaponPosition,
                                             Chars.weapon, "dagger", rnd.Next(10), rnd.Next(100),
                                             rnd.Next(10));

                items.Add(food);
                grabItems.Add(food);
                foods.Add(food);

                items.Add(weapon);
                grabItems.Add(weapon);
                weapons.Add(weapon);
            }

            // Set random enemies around the map and put them with its specific
            // information about the object and add it to its list
            for (int i = 0; i < numberOfEnemies; i++)
            {
                int row = rnd.Next(RowSize);
                int col = rnd.Next(ColSize);

                Position enemyPosition;

                do
                {
                    enemyPosition = new Position(row, col);
                }while (enemyPosition.Row == exit.Position.Row &&
                        enemyPosition.Col == exit.Position.Col);

                Enemy enemy = new Enemy((new Position(row, col)), Chars.enemy,
                                        " A wild enemy has appeared!", rnd.Next(100));

                enemies.Add(enemy);
                items.Add(enemy);
            }

            // empty cells so the player can't see what's on the map immediately
            for (int i = 0; i < RowSize; i++)
            {
                for (int j = 0; j < ColSize; j++)
                {
                    cells[i, j] = new BoardCells((char)Chars.empty, false);
                }
            }


            cells[player.Position.Row, player.Position.Col] = new BoardCells(player.name, false);
        }
Esempio n. 5
0
        internal void Setup(Player player, CurrentMapObjects exit,
                            CurrentMapObjects map, List <CurrentMapObjects> items, List <Items> grabItems,
                            List <Trap> traps, List <Food> foods, List <Weapons> weapons, List <Enemy> enemies,
                            int RowSize, int ColSize, BoardCells[,] cells)
        {
            // Max size of objects in Levels
            int maxTrapsInLvl   = Linear(Current, Diff, 2);
            int maxItemsInLvl   = Linear(Current, Diff, 2);
            int maxEnemiesInLvl = Linear(Current, Diff, 2);

            //Add objects to item list
            items.Add(exit);
            items.Add(map);


            //
            int numberOfTraps   = rnd.Next(maxTrapsInLvl);
            int numberOfItems   = rnd.Next(maxItemsInLvl);
            int numberOfEnemies = rnd.Next(maxEnemiesInLvl);

            // Set random Traps around on map
            for (int i = 0; i < numberOfTraps; i++)
            {
                int row = rnd.Next(RowSize);
                int col = rnd.Next(ColSize);

                Trap trap = new Trap((new Position(row, col)), Chars.trap, $"this is a trap! watch out!", rnd.Next(100));

                traps.Add(trap);
                items.Add(trap);
            }

            // Set random Items around the map
            for (int i = 0; i < numberOfItems; i++)
            {
                int row = rnd.Next(RowSize);
                int col = rnd.Next(ColSize);


                Food food = new Food((new Position(row, col)), Chars.food, " An apple a day keeps god astray", rnd.Next(10), rnd.Next(100));

                Weapons weapon = new Weapons((new Position(row, col)), Chars.weapon, "dagger", rnd.Next(10), rnd.Next(100), rnd.Next(10));


                items.Add(food);
                grabItems.Add(food);
                foods.Add(food);

                items.Add(weapon);
                grabItems.Add(weapon);
                weapons.Add(weapon);
            }

            // Set random enemies around the map
            for (int i = 0; i < numberOfEnemies; i++)
            {
                int row = rnd.Next(RowSize);
                int col = rnd.Next(ColSize);

                Enemy enemy = new Enemy((new Position(row, col)), Chars.enemy, " A wild enemy has appeared!", rnd.Next(100));

                enemies.Add(enemy);
                items.Add(enemy);
            }


            for (int i = 0; i < RowSize; i++)
            {
                for (int j = 0; j < ColSize; j++)
                {
                    cells[i, j] = new BoardCells((char)Chars.empty, false, new Position(i, j));
                }
            }


            cells[player.Position.Row, player.Position.Col] = new BoardCells(player.name, false, new Position(player.Position.Row, player.Position.Col));
        }