diff --git a/TanksServer/GameLogic/MapService.cs b/TanksServer/GameLogic/MapService.cs index e12251d..4699e85 100644 --- a/TanksServer/GameLogic/MapService.cs +++ b/TanksServer/GameLogic/MapService.cs @@ -1,3 +1,5 @@ +using System.IO; + namespace TanksServer.GameLogic; internal sealed class MapService @@ -7,31 +9,33 @@ internal sealed class MapService public const ushort TileSize = 8; public const ushort PixelsPerRow = TilesPerRow * TileSize; public const ushort PixelsPerColumn = TilesPerColumn * TileSize; + private readonly string _map; + private readonly ILogger _logger; - private readonly string _map = - """ - #######.##########################.######### - #...................##.....................# - #...................##.....................# - #.....####......................####.......# - #..........................................# - #............###...........###.............# - #............#...............#.............# - #...##.......#....#....#.....#......##.....# - #....#..............................#......# - .....#...#......................#...#....... - .....#...#......................#...#....... - #....#..............................#......# - #...##.......#....#....#.....#......##.....# - #............#...............#.............# - #............###...........###.............# - #..........................................# - #.....####......................####.......# - #...................##.....................# - #...................##.....................# - #######.##########################.######### - """ - .ReplaceLineEndings(string.Empty); + private string[] LoadMaps() => Directory.EnumerateFiles("./assets/maps/", "*.txt") + .Select(LoadMap) + .Where(s => s != null) + .Select(s => s!) + .ToArray(); + + private string? LoadMap(string file) + { + var text = File.ReadAllText(file).ReplaceLineEndings(string.Empty).Trim(); + if (text.Length != TilesPerColumn * TilesPerRow) + { + _logger.LogWarning("cannot load map {}: invalid length", file); + return null; + } + + return text; + } + + public MapService(ILogger logger) + { + _logger = logger; + var maps = LoadMaps(); + _map = maps[Random.Shared.Next(0, maps.Length)]; + } private char this[int tileX, int tileY] => _map[tileX + tileY * TilesPerRow]; diff --git a/TanksServer/TanksServer.csproj b/TanksServer/TanksServer.csproj index bbfdc06..3796240 100644 --- a/TanksServer/TanksServer.csproj +++ b/TanksServer/TanksServer.csproj @@ -27,6 +27,7 @@ + @@ -40,10 +41,7 @@ + - - - - - + diff --git a/TanksServer/assets/maps/buggie.txt b/TanksServer/assets/maps/buggie.txt new file mode 100644 index 0000000..7e3c412 --- /dev/null +++ b/TanksServer/assets/maps/buggie.txt @@ -0,0 +1,20 @@ +######......####################......###### +#..........................................# +#.....#####......................#####.....# +#..........#....................#..........# +#...........#####..........#####...........# +#..........................................# +#.........##....................##.........# +#............#..#..........#..#............# +#..............#............#..............# +#.............#..............#.............# +#....................##....................# +#....................##....................# +#....................##....................# +#.............#......##......#.............# +#...........#..#............#..#...........# +#.........#.....#..........#.....#.........# +#.......#............##............#.......# +#........#........................#........# +#..........................................# +######......####################......###### diff --git a/TanksServer/assets/maps/orig.txt b/TanksServer/assets/maps/orig.txt new file mode 100644 index 0000000..2a8d04f --- /dev/null +++ b/TanksServer/assets/maps/orig.txt @@ -0,0 +1,20 @@ +#######.##########################.######### +#...................##.....................# +#...................##.....................# +#.....####......................####.......# +#..........................................# +#............###...........###.............# +#............#...............#.............# +#...##.......#....#....#.....#......##.....# +#....#..............................#......# +.....#...#......................#...#....... +.....#...#......................#...#....... +#....#..............................#......# +#...##.......#....#....#.....#......##.....# +#............#...............#.............# +#............###...........###.............# +#..........................................# +#.....####......................####.......# +#...................##.....................# +#...................##.....................# +#######.##########################.######### diff --git a/TanksServer/assets/maps/tanks.txt b/TanksServer/assets/maps/tanks.txt new file mode 100644 index 0000000..25fa716 --- /dev/null +++ b/TanksServer/assets/maps/tanks.txt @@ -0,0 +1,20 @@ +#####......................................# +..#........................................# +..#........................................# +..#......###...............................# +..#.....#...#..............................# +........#####..............................# +........#...#...#...#......................# +........#...#...##..#......................# +................#.# #......................# +................#..##...#...#..............# +................#...#...#..#...............# +........................###................# +........................#..#......###......# +........................#...#...#..........# +.................................###.......# +....................................#...#..# +................................####....#..# +........................................#..# +...........................................# +........................................#..# diff --git a/TanksServer/assets/maps/upside_down.txt b/TanksServer/assets/maps/upside_down.txt new file mode 100644 index 0000000..5d408b3 --- /dev/null +++ b/TanksServer/assets/maps/upside_down.txt @@ -0,0 +1,20 @@ +............................................ +#.........##.....#.........................# +#........#..#..............................# +#.........##...............................# +#..................#.......................# +#.........#........##.............#........# +#....#.........#....#............#.........# +#....#.....................................# +#............#.............#..........#....# +#.........##.....#......................#..# +#........#..#..............................# +#.........##..................#............# +#..........................................# +#....#..............#...........#..........# +#....................#...##...#............# +#..........##..........#....#.........#....# +#.........#...#........#....#..............# +#.........#...#......#...##...#............# +#..........##......#............#.......#..# +............................................ diff --git a/tank-frontend/src/ClientScreen.css b/tank-frontend/src/ClientScreen.css index 3304737..b0405a9 100644 --- a/tank-frontend/src/ClientScreen.css +++ b/tank-frontend/src/ClientScreen.css @@ -6,4 +6,7 @@ max-width: 100vw; max-height: 100vh; flex-shrink: 0; + + border: solid var(--border-size-thick); + border-color: var(--color-primary); } diff --git a/tank-frontend/src/Controls.css b/tank-frontend/src/Controls.css index 2f7cbfa..3344d3d 100644 --- a/tank-frontend/src/Controls.css +++ b/tank-frontend/src/Controls.css @@ -14,7 +14,7 @@ kbd { --kbd-key-size: 2em; - background: var(--color-secondary); + background: var(--color-primary); padding: var(--padding-normal); display: block;