Ejemplo n.º 1
0
        private string GetCellSymbol(int x, int y, IAreaMap map, Point playerPosition)
        {
            if (playerPosition.X == x && playerPosition.Y == y)
            {
                return("+");
            }

            var cell = map.GetCell(x, y);

            if (cell.Objects.OfType <DoorBase>().Any())
            {
                return("▒");
            }

            if (cell.Objects.OfType <WallBase>().Any())
            {
                return("█");
            }

            if (cell.Objects.OfType <DungeonTrapDoor>().Any())
            {
                return("v");
            }

            if (cell.Objects.OfType <DungeonStairs>().Any())
            {
                return("^");
            }

            return(" ");
        }
Ejemplo n.º 2
0
        public void Update(Point position)
        {
            energyLeft--;
            if (energyLeft > 0)
            {
                return;
            }

            CurrentGame.Map.RemoveObject(position, this);
        }
Ejemplo n.º 3
0
        public void Update(Point position)
        {
            var cell = CurrentGame.Map.GetCell(position);

            if (cell.Temperature() < SmallFireTemperature)
            {
                CurrentGame.Map.RemoveObject(position, this);
                return;
            }

            temperature = cell.Temperature();
        }
Ejemplo n.º 4
0
        public IAreaMap GenerateNewMap(int level, out Point playerPosition)
        {
            Log.Debug($"Generating map for level {level}.");
            var stopwatch = Stopwatch.StartNew();

            try
            {
                return(PerformMapGeneration(level, out playerPosition));
            }
            finally
            {
                stopwatch.Stop();
                Log.Debug($"Map generation took {stopwatch.ElapsedMilliseconds} milliseconds total.");
            }
        }
Ejemplo n.º 5
0
 private void WriteMapToFile(IAreaMap map, Point playerPosition)
 {
     using (var file = File.CreateText(@".\Map.txt"))
     {
         for (int y = 0; y < map.Height; y++)
         {
             var line = string.Empty;
             for (int x = 0; x < map.Width; x++)
             {
                 line += GetCellSymbol(x, y, map, playerPosition);
             }
             file.WriteLine(line);
         }
     }
 }
Ejemplo n.º 6
0
        private IAreaMap GenerateMap(
            int level,
            MapSize size,
            out Point playerPosition)
        {
            var mapType   = GenerateMapType(level);
            var generator = generators[mapType];
            var map       = generator.Generate(level, size, out playerPosition);

            if (writeMapFile)
            {
                WriteMapToFile(map, playerPosition);
            }

            return(map);
        }
Ejemplo n.º 7
0
        private IAreaMap PerformMapGeneration(int level, out Point playerPosition)
        {
            for (var attempt = 0; attempt < 500; attempt++)
            {
                try
                {
                    var size = GenerateMapSize();
                    var map  = GenerateMap(level, size, out playerPosition);
                    Log.Info($"Map was generated for {attempt + 1} attempts.");
                    return(map);
                }
                catch (MapGenerationException ex)
                {
                    Log.Debug("Error when generating map.", ex);
                }
            }

            throw new ApplicationException("Unable to generate map.");
        }