initialize repo

This commit is contained in:
2025-08-08 15:36:09 +02:00
parent d6a2c37a5f
commit cabf13d164
92 changed files with 2160 additions and 2 deletions

View File

@@ -0,0 +1,56 @@
using Civilization.Core.Game;
using Civilization.Core.Interfaces;
namespace Civilization.Core.Units;
public class Unit : IOnTurnListener, IEntity
{
public Guid Id { get; } = Guid.NewGuid();
public int OwnerId { get; }
public UnitType Type { get; }
public UnitData Data { get; }
public Vec2I Position { get; set; }
public int MaxActionPoints { get; }
public int ActionPoints { get; set; }
public Unit(int ownerId, UnitType type, Vec2I position)
{
Id = Guid.NewGuid();
OwnerId = ownerId;
Type = type;
Position = position;
Data = UnitDataRegistry.Get(Type);
MaxActionPoints = Data.MaxActionPoints;
ActionPoints = MaxActionPoints;
}
public void ResetActionPoints()
{
ActionPoints = MaxActionPoints;
}
public bool CanMoveTo(Vec2I destination, GameMap map)
{
if (ActionPoints <= 0) return false;
if (!map.Grid.IsValidPosition(destination)) return false;
var distance = Math.Abs(Position.X - destination.X) + Math.Abs(Position.Y - destination.Y);
return distance <= Data.MoveRange;
}
public bool HasTag(UnitTag tag) => Data.HasTag(tag);
public void OnTurnStart(GameState state)
{
ResetActionPoints();
}
public void OnTurnEnd(GameState state)
{
}
}

View File

@@ -0,0 +1,11 @@
namespace Civilization.Core.Units;
public class UnitData
{
public string Name { get; init; }
public int MaxActionPoints { get; init; }
public int MoveRange { get; init; } = 1;
public HashSet<UnitTag> Tags { get; init; } = [];
public bool HasTag(UnitTag tag) => Tags.Contains(tag);
}

View File

@@ -0,0 +1,17 @@
namespace Civilization.Core.Units;
public class UnitDataRegistry
{
private static readonly Dictionary<UnitType, UnitData> _registry = new()
{
[UnitType.Settler] = new UnitData
{
Name = "Settler",
MaxActionPoints = 1,
MoveRange = 1,
Tags = new() { UnitTag.Settle, }
}
};
public static UnitData Get(UnitType unitType) => _registry[unitType];
}

View File

@@ -0,0 +1,6 @@
namespace Civilization.Core.Units;
public enum UnitTag
{
Settle,
}

View File

@@ -0,0 +1,6 @@
namespace Civilization.Core.Units;
public enum UnitType
{
Settler,
}