Přidány základy generování mapy (zatím pouze server-side, bez zrcadlení do clienta)
This commit is contained in:
parent
8a3267cc4b
commit
8801a7c919
6 changed files with 100 additions and 1 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=_002Fhome_002Fperry_002FRiderProjects_002FFNAF_005FClone_002FFNAF_005FClone_002Flib_002FMonoGameLibrary_002Edll/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=_002Fhome_002Fperry_002FRiderProjects_002FFNAF_005FClone_002FFNAF_005FClone_002Flib_002FMonoGameLibrary_002Edll/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACore_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F4e0fe18725844db38e9480edfd0e34983e00_003Fb5_003F8dc24573_003FCore_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACore_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F4e0fe18725844db38e9480edfd0e34983e00_003Fb5_003F8dc24573_003FCore_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEnumerable_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F419320464d0849fb89a7e518f7ff8bc978a00_003Fe8_003F1faf66e3_003FEnumerable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AINetSerializable_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003F0f_003Fe2eeb2cd_003FINetSerializable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AINetSerializable_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003F0f_003Fe2eeb2cd_003FINetSerializable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AKeyValuePair_00602_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F384e456bc26f45f5a6a6a20ae50c6e0dd1a400_003Fe8_003F7272ae72_003FKeyValuePair_00602_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANetSerializer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003Fcc_003F8a34584a_003FNetSerializer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANetSerializer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F3d47105f47a240929625d0f531812b9e1c000_003Fcc_003F8a34584a_003FNetSerializer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
|
using FNAF_Server.Map;
|
||||||
using PacketLib;
|
using PacketLib;
|
||||||
|
|
||||||
namespace FNAF_Server;
|
namespace FNAF_Server;
|
||||||
|
|
||||||
public class GameLogic {
|
public class GameLogic {
|
||||||
|
|
||||||
|
public static void Init() {
|
||||||
|
MapManager.InitMap();
|
||||||
|
}
|
||||||
public static void Update() {
|
public static void Update() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
47
FNAF_Server/Map/MapManager.cs
Normal file
47
FNAF_Server/Map/MapManager.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
namespace FNAF_Server.Map;
|
||||||
|
|
||||||
|
public static class MapManager {
|
||||||
|
private static MapTile[,] map = new MapTile[5, 5];
|
||||||
|
|
||||||
|
private static Dictionary<(int x1, int y1), (int x2, int y2, int value)[]> halfConnectors = new(){
|
||||||
|
[(0, 0)] =[(1, 0, 1), (0, 1, 1)],
|
||||||
|
[(1, 0)] =[(2, 0, 1), (1, 1, 1)],
|
||||||
|
[(3, 0)] =[(2, 0, 1), (4, 0, 1), (3, 1, 1)],
|
||||||
|
[(4, 0)] =[(4, 1, 1)],
|
||||||
|
[(0, 1)] =[(1, 1, 1)],
|
||||||
|
[(1, 1)] =[(1, 2, 1)],
|
||||||
|
[(2, 1)] =[(2, 2, 1), (2, 0, 1)],
|
||||||
|
[(3, 1)] =[(3, 2, 1), (4, 1, 1)]
|
||||||
|
};
|
||||||
|
|
||||||
|
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)]
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void InitMap() { // TODO: make map size not hardcoded
|
||||||
|
for (int i = 0; i < 5; i++){
|
||||||
|
for (int j = 0; j < 2; j++){
|
||||||
|
map[i, j] = new MapTile(i * 5 + j, null); // TODO: implement ownership
|
||||||
|
}
|
||||||
|
map[i, 2] = new MapTile(i * 5 + 2, null);
|
||||||
|
for (int j = 3; j < 5; j++){
|
||||||
|
map[i, j] = new MapTile(i * 5 + j, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var con in mainHallwayConnectors){
|
||||||
|
map[con.Key.x1, con.Key.y1].AddConnectors(con.Value.Select(c => (map[c.x2, c.y2], TileConnector.ConnectorType.HALL, c.value)).ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var con in halfConnectors){
|
||||||
|
map[con.Key.x1, con.Key.y1].AddConnectors(con.Value.Select(c => (map[c.x2, c.y2], TileConnector.ConnectorType.HALL, c.value)).ToArray());
|
||||||
|
}
|
||||||
|
foreach (var con in halfConnectors){
|
||||||
|
map[4 - con.Key.x1, 4 - con.Key.y1].AddConnectors(con.Value.Select(c => (map[4 - c.x2, 4 - c.y2], TileConnector.ConnectorType.HALL, c.value)).ToArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
25
FNAF_Server/Map/MapTile.cs
Normal file
25
FNAF_Server/Map/MapTile.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
namespace FNAF_Server.Map;
|
||||||
|
|
||||||
|
public class MapTile {
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public ServerPlayer Owner { get; private set; }
|
||||||
|
public bool Lit { get; set; } = false;
|
||||||
|
|
||||||
|
private List<TileConnector> Connectors { get; set; } = 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 / 5}, {Id % 5}]"; // for debug purposes
|
||||||
|
|
||||||
|
}
|
||||||
18
FNAF_Server/Map/TileConnector.cs
Normal file
18
FNAF_Server/Map/TileConnector.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
namespace FNAF_Server.Map;
|
||||||
|
|
||||||
|
public struct TileConnector(MapTile tile1, MapTile tile2, TileConnector.ConnectorType type, int value) {
|
||||||
|
public (MapTile, MapTile) Tiles { get; set; } = (tile1, tile2);
|
||||||
|
public ConnectorType Type { get; set; } = type;
|
||||||
|
public bool Blocked { get; set; } = false;
|
||||||
|
public int Value{ get; set; } = value;
|
||||||
|
|
||||||
|
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,
|
||||||
|
VENT
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -61,7 +61,7 @@ public class Server {
|
||||||
};
|
};
|
||||||
|
|
||||||
server.Start(port);
|
server.Start(port);
|
||||||
|
|
||||||
Run();
|
Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,6 +115,9 @@ public class Server {
|
||||||
else{
|
else{
|
||||||
P2 = newPlayer;
|
P2 = newPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameLogic.Init(); // TODO: implement a way to start the game once both players join
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod) {
|
public static void OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue