Esempio n. 1
0
        /// <summary>
        /// Runs the game loop. Moving tokens and otherwise
        /// </summary>
        /// <param name="map">The Current Map</param>
        /// <returns></returns>
        private bool RunMapGameLoop(Map map, List <ICharacter> entityPile, List <Tile> specialTilePile, EncounterProg encounter)
        {
            Console.Clear();
            Display_Map.DisplayMap(map);
            List <ICharacter> npcs   = new List <ICharacter>();
            ICharacter        player = new PlayerToken(encounter);
            int    tickCounter       = 1;
            Random randomMovement    = new Random();
            bool   updateDisplay     = false;
            bool   gameOver          = false;

            int randomTick = randomMovement.Next(40, 400 / _currentLevel);

            while (true)
            {
                foreach (ICharacter entity in entityPile)
                {
                    if (entity.GetType() != typeof(PlayerToken))
                    {
                        npcs.Add(entity);
                    }
                    else
                    {
                        player = entity;
                    }
                }
                Console.CursorVisible = false;
                bool  isOver   = false;
                Drone toRemove = new Drone();
                foreach (ICharacter entity in entityPile) //Moves each entity which was added to the list of them.
                {
                    if (entity.GetType() == typeof(PlayerToken))
                    {
                        entity.Move(map);
                    }
                    else if (tickCounter == randomTick && toRemove != entity)
                    {
                        entity.Move(map);
                    }
                    foreach (Tile special in specialTilePile)
                    {
                        map.SetTilePosition(special.Position, special.InstanValue);
                        if (IsColliding.IsCurrentlyColliding(special, entity) && entity.GetType() == typeof(PlayerToken) && special.GetType() != typeof(InnTile))
                        {
                            map.SetEntityPosition(entity);
                            map.BuildMapDisplay();
                            Display_Map.DisplayMap(map);
                            isOver = true;
                            break;
                        }
                    }
                    foreach (Drone npc in npcs)
                    {
                        if (IsColliding.IsCurrentlyColliding(npc, player) && npc != toRemove)
                        {
                            map.BuildMapDisplay();
                            Display_Map.DisplayMap(map);

                            if (npc.GetType() == typeof(BossToken))
                            {
                                gameOver = encounter.RunEncounterProg(_currentLevel, _bossSeed);
                            }
                            else
                            {
                                gameOver = encounter.RunEncounterProg(_currentLevel);
                            }
                            isOver = gameOver;

                            toRemove = npc;

                            Console.Clear();

                            if (!gameOver)
                            {
                                map.BuildMapDisplay();
                                Display_Map.DisplayMap(map);
                            }
                        }
                    }
                    map.BuildMapDisplay();
                    npcs.Remove(toRemove);
                    if (entity.DidMove)
                    {
                        updateDisplay = true;
                    }
                }
                entityPile.Remove(toRemove);


                if (isOver)
                {
                    break;
                }

                if (tickCounter >= randomTick + 1)
                {
                    tickCounter = 1;
                    randomTick  = randomMovement.Next(100, 200);
                }

                npcs.Clear();
                map.SetEntityPosition(player);
                if (updateDisplay)
                {
                    map.BuildMapDisplay();
                    Display_Map.DisplayMap(map);
                }

                updateDisplay = false;
                tickCounter++;
            }

            return(!gameOver);
        }
Esempio n. 2
0
        /// <summary>
        /// Runs the logic around the game loop
        /// </summary>
        /// <param name="difficulty">Difficulty of the game</param>
        /// <param name="newPlayer">The current player</param>
        /// <returns>Whether or not the game will continue</returns>
        public void RunMapGame()
        {
            EncounterProg encounter = new EncounterProg();

            encounter.RunCharacterCreation();

            Random randomNumberSeed = new Random();

            bool newMap = true;

            int height = 8, width = 20;

            while (newMap)
            {
                PlayerToken player = new PlayerToken(encounter);

                Console.WriteLine("Loading New Map...");
                Console.WriteLine("This may take up to 60 seconds...");

                Map     map     = new Map(width, height);
                TownMap townMap = new TownMap(width, height);
                Dictionary <int, CaveMap> caveMapStorage = new Dictionary <int, CaveMap>();
                List <Tile> specialTilePile = new List <Tile>();

                int randomSeed = randomNumberSeed.Next(_currentLevel - 1, _currentLevel + 2);
                if (_currentLevel == 1)
                {
                    randomSeed = randomNumberSeed.Next(0, 3);
                }
                else if (_currentLevel == 2)
                {
                    randomSeed = randomNumberSeed.Next(1, 3);
                }
                for (int i = 0; i < randomSeed; i++)
                {
                    double   randomWidthSeed  = randomNumberSeed.Next(2, 4);
                    double   randomHeightSeed = randomNumberSeed.Next(1, 1);
                    CaveMap  caveMap          = new CaveMap((int)(width / (randomWidthSeed)), (int)(height / (randomHeightSeed)));
                    CaveTile caveTile         = new CaveTile();
                    caveTile.AssociationNum = i + 1;
                    specialTilePile.Add(caveTile);
                    caveMapStorage.Add(i + 1, caveMap);
                }
                TownMapTile currentTownMapTile = new TownMapTile();
                ExitTile    endTile            = new ExitTile();
                endTile.Position            = new int[2];
                currentTownMapTile.Position = FindTileOrEntitySpawn.StartingPostion(map, currentTownMapTile);
                specialTilePile.Add(currentTownMapTile);
                specialTilePile.Add(endTile);


                List <ICharacter> entityPile = new List <ICharacter>();
                randomSeed = randomNumberSeed.Next(_currentLevel, _currentLevel * 5);

                bool isTownMap = true;
                bool isCaveMap = true;
                while ((isTownMap || isCaveMap) && newMap)
                {
                    newMap = RunWorldMap(encounter, player, map, specialTilePile, randomSeed, endTile, entityPile);

                    isTownMap = false;
                    isCaveMap = false;
                    foreach (Tile tile in specialTilePile)
                    {
                        if (tile.GetType() == typeof(CaveTile) && IsColliding.IsCurrentlyColliding(tile, player))
                        {
                            newMap    = RunCaveMap(encounter, player, caveMapStorage, endTile, tile);
                            isCaveMap = true;
                        }
                        else if (tile.GetType() == typeof(TownMapTile) && IsColliding.IsCurrentlyColliding(currentTownMapTile, player))
                        {
                            encounter.TownReplenish();
                            newMap    = RunTownMap(encounter, player, townMap, currentTownMapTile, endTile);
                            isTownMap = true;
                        }
                    }
                }

                width  += 10;
                height += 2;
                if (width == 100)
                {
                    newMap = false;
                }

                _currentLevel++;
            }

            Console.WriteLine("Game Over");
        }