Projekt přejmenován. Neko nastaven na výchozí pozici
This commit is contained in:
parent
1a27dd6fab
commit
ceac37920b
104 changed files with 873 additions and 208 deletions
104
ONDServer/Map/MapManager.cs
Normal file
104
ONDServer/Map/MapManager.cs
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
using GlobalClassLib;
|
||||
|
||||
namespace ONDServer.Map;
|
||||
|
||||
public static class MapManager {
|
||||
private static MapTile[,] map = new MapTile[5, 5];
|
||||
private static List<TileConnector> doors = new();
|
||||
private static List<TileConnector> doorsP1 = new();
|
||||
private static List<TileConnector> doorsP2 = new();
|
||||
|
||||
public static MapTile Get((int x, int y) coords) => map[coords.x, coords.y];
|
||||
public static MapTile Get(int tileId) => Get(IdToCoords(tileId));
|
||||
|
||||
|
||||
private static Dictionary<(int x1, int y1), (int x2, int y2, int value, ConnectorType type)[]> halfConnectors = new(){
|
||||
[(0, 0)] =[(1, 0, 1, ConnectorType.HALL), (0, 1, 1, ConnectorType.DOOR_REMOTE)],
|
||||
[(1, 0)] =[(2, 0, 1, ConnectorType.DOOR_OFFICE), (1, 1, 1, ConnectorType.DOOR_REMOTE)],
|
||||
[(3, 0)] =[(2, 0, 1, ConnectorType.DOOR_OFFICE), (4, 0, 1, ConnectorType.HALL), (3, 1, 1, ConnectorType.DOOR_REMOTE)],
|
||||
[(4, 0)] =[(4, 1, 1, ConnectorType.DOOR_REMOTE)],
|
||||
[(0, 1)] =[(1, 1, 1, ConnectorType.HALL)],
|
||||
[(1, 1)] =[(1, 2, 1, ConnectorType.DOOR_REMOTE)],
|
||||
[(2, 1)] =[(2, 2, 2, ConnectorType.HALL), (2, 0, 1, ConnectorType.DOOR_OFFICE)],
|
||||
[(3, 1)] =[(3, 2, 1, ConnectorType.DOOR_REMOTE), (4, 1, 1, ConnectorType.HALL)]
|
||||
};
|
||||
|
||||
private static Dictionary<(int x1, int y1), (int x2, int y2, int value)[]> mainHallwayConnectors = new(){
|
||||
[(0,2)] = [(1,2,1)],
|
||||
[(1,2)] = [(2,2,1)],
|
||||
[(2,2)] = [(3,2,1)],
|
||||
[(3,2)] = [(4,2,1)]
|
||||
};
|
||||
|
||||
private static (int x, int y)[] ventTiles =[(0, 1), (4, 1), (2, 2), (0, 3), (4, 3)];
|
||||
|
||||
public static void InitMap() {
|
||||
for (int i = 0; i < 5; i++){
|
||||
for (int j = 0; j < 2; j++){
|
||||
map[i, j] = new MapTile(CoordsToId(i, j)){Owner = Server.P1};
|
||||
}
|
||||
map[i, 2] = new MapTile(CoordsToId(i, 2)){Lit = true};
|
||||
for (int j = 3; j < 5; j++){
|
||||
map[i, j] = new MapTile(CoordsToId(i, j)){Owner = Server.P2};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var con in mainHallwayConnectors){
|
||||
map[con.Key.x1, con.Key.y1].AddConnectors(con.Value.Select(c => new TileConnector(map[c.x2, c.y2], ConnectorType.HALL, c.value)).ToArray());
|
||||
}
|
||||
|
||||
foreach (var con in halfConnectors){
|
||||
map[con.Key.x1, con.Key.y1].AddConnectors(con.Value.Select(c => new TileConnector(map[c.x2, c.y2], c.type, c.value){Owner = Server.P1}).ToArray());
|
||||
}
|
||||
foreach (var con in halfConnectors){
|
||||
map[4 - con.Key.x1, 4 - con.Key.y1].AddConnectors(con.Value.Select(c => new TileConnector(map[4 - c.x2, 4 - c.y2], c.type, c.value){Owner = Server.P2}).ToArray());
|
||||
}
|
||||
|
||||
doors = GetAllConnectors().Where(c => c.Type == ConnectorType.DOOR_OFFICE || c.Type == ConnectorType.DOOR_REMOTE).ToList();
|
||||
doorsP1 = doors.Where(c => c.Owner == Server.P1).ToList();
|
||||
doorsP2 = doors.Where(c => c.Owner == Server.P2).ToList();
|
||||
|
||||
foreach (var tile1Coords in ventTiles){
|
||||
MapTile tile1 = map[tile1Coords.x, tile1Coords.y];
|
||||
foreach (var tile2Coords in ventTiles){
|
||||
MapTile tile2 = map[tile2Coords.x, tile2Coords.y];
|
||||
if(tile1.GetConnector(tile2) != null || tile1 == tile2) continue;
|
||||
tile1.AddConnector(new TileConnector(tile2, ConnectorType.VENT, 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static TileConnector[] GetAllConnectors() {
|
||||
List<TileConnector> connectors = new();
|
||||
|
||||
for (int i = 0; i < 5; i++){
|
||||
for (int j = 0; j < 5; j++){
|
||||
MapTile tile = map[i, j];
|
||||
Array.ForEach(tile.GetAllConnectors(), c => {
|
||||
if(tile.Id < c.OtherTile(tile).Id)
|
||||
connectors.Add(c);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return connectors.ToArray();
|
||||
}
|
||||
|
||||
public static MapTile[] GetAllTiles() {
|
||||
List<MapTile> tiles = new();
|
||||
|
||||
foreach (var tile in map){
|
||||
tiles.Add(tile);
|
||||
}
|
||||
|
||||
return tiles.ToArray();
|
||||
}
|
||||
|
||||
public const int ID_X_OFFSET = 5; // map grid height
|
||||
public static int CoordsToId(int x, int y) => x * ID_X_OFFSET + y;
|
||||
public static (int, int) IdToCoords(int id) => (id / ID_X_OFFSET, id % ID_X_OFFSET);
|
||||
|
||||
public static TileConnector[] GetDoors() => doors.ToArray();
|
||||
public static TileConnector[] GetDoors(ServerPlayer player) => player == Server.P1 ? doorsP1.ToArray() : doorsP2.ToArray();
|
||||
}
|
||||
43
ONDServer/Map/MapTile.cs
Normal file
43
ONDServer/Map/MapTile.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using System.Net.Security;
|
||||
using GlobalClassLib;
|
||||
|
||||
namespace ONDServer.Map;
|
||||
|
||||
public class MapTile : GlobalMapTile<TileConnector, MapTile> {
|
||||
public ServerPlayer? Owner{ get; set; }
|
||||
|
||||
public MapTile(int id) : base(id, MapManager.IdToCoords(id)) {
|
||||
}
|
||||
|
||||
// public int Id { get; private set; }
|
||||
// public ServerPlayer Owner { get; private set; }
|
||||
// public bool Lit { get; set; } = false;
|
||||
//
|
||||
// private List<TileConnector> connectors = new();
|
||||
//
|
||||
// public MapTile(int id, ServerPlayer owner) {
|
||||
// Id = id;
|
||||
// Owner = owner;
|
||||
// }
|
||||
// public void AddConnector(MapTile tile, TileConnector.ConnectorType type, int value) {
|
||||
// connectors.Add(new TileConnector(this, tile, type, value));
|
||||
// tile.connectors.Add(new TileConnector(tile, this, type, value));
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public void AddConnectors((MapTile tile, TileConnector.ConnectorType type, int value)[] connectors) =>
|
||||
// Array.ForEach(connectors, c => AddConnector(c.tile, c.type, c.value));
|
||||
//
|
||||
// public override string ToString() => $"{PositionAsString} -> {string.Join(", ", connectors.Select(c => c.Tiles.Item2.PositionAsString))}";
|
||||
// public string PositionAsString => $"[{Id}]"; // for debug purposes
|
||||
//
|
||||
// public TileConnector? GetConnector(int id) {
|
||||
// foreach (var con in connectors){
|
||||
// if (con.Tiles.Item2.Id == id) return con;
|
||||
// }
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
|
||||
}
|
||||
45
ONDServer/Map/TileConnector.cs
Normal file
45
ONDServer/Map/TileConnector.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
using GlobalClassLib;
|
||||
|
||||
namespace ONDServer.Map;
|
||||
|
||||
public class TileConnector : GlobalTileConnector<MapTile,TileConnector> {
|
||||
public int Value{ get; set; }
|
||||
public ServerPlayer? Owner{ get; set; }
|
||||
public TileConnector(MapTile tile1, MapTile tile2, ConnectorType type, int value) : base(tile1, tile2, type) {
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public TileConnector(MapTile tile2, ConnectorType type, int value) : base(tile2, type) {
|
||||
Value = value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// private readonly MapTile _tile1;
|
||||
// private readonly MapTile _tile2;
|
||||
//
|
||||
// public TileConnector(MapTile tile1, MapTile tile2, TileConnector.ConnectorType type, int value) {
|
||||
// _tile1 = tile1;
|
||||
// _tile2 = tile2;
|
||||
// Type = type;
|
||||
// Value = value;
|
||||
// }
|
||||
//
|
||||
// public (MapTile, MapTile) Tiles => (tile1: _tile1, tile2: _tile2);
|
||||
//
|
||||
// public ConnectorType Type { get; set; }
|
||||
// public bool Blocked { get; set; } = false;
|
||||
// public int Value{ get; set; }
|
||||
//
|
||||
// public MapTile OtherTile(MapTile tile) => Tiles.Item1 == tile ? Tiles.Item2 : Tiles.Item1;
|
||||
//
|
||||
// public override string ToString() => $"Con ({Tiles.Item1.PositionAsString} -> {Tiles.Item2.PositionAsString})";
|
||||
// public enum ConnectorType {
|
||||
// HALL,
|
||||
// DOOR_REMOTE,
|
||||
// DOOR_OFFICE,
|
||||
// VENT
|
||||
// }
|
||||
|
||||
public override TileConnector Clone() => new(Tiles.tile1, Tiles.tile2, Type, Value){Owner = Owner};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue