Chessistics/chessistics-engine/Model/PieceState.cs

55 lines
1.5 KiB
C#
Raw Permalink Normal View History

namespace Chessistics.Engine.Model;
public class PieceState
{
public int Id { get; }
public PieceKind Kind { get; }
public int Level { get; }
public Coords StartCell { get; private set; }
public Coords EndCell { get; private set; }
public Coords CurrentCell { get; set; }
public CargoType? Cargo { get; set; }
public CargoType? CargoFilter { get; set; }
public int SocialStatus { get; }
public int PlacementOrder { get; }
public PieceState(int id, PieceKind kind, Coords startCell, Coords endCell, int placementOrder, int level = 1)
{
Id = id;
Kind = kind;
Level = level;
StartCell = startCell;
EndCell = endCell;
CurrentCell = startCell;
Cargo = null;
SocialStatus = PieceRules.GetSocialStatus(kind);
PlacementOrder = placementOrder;
}
/// <summary>
/// Returns the cell this piece will move to next.
/// </summary>
public Coords TargetCell => CurrentCell == StartCell ? EndCell : StartCell;
/// <summary>
/// Relocate this piece (drag & drop).
/// </summary>
public void SetPosition(Coords newStart, Coords newEnd)
{
StartCell = newStart;
EndCell = newEnd;
CurrentCell = newStart;
}
public PieceState Clone()
{
var clone = new PieceState(Id, Kind, StartCell, EndCell, PlacementOrder, Level)
{
CurrentCell = CurrentCell,
Cargo = Cargo,
CargoFilter = CargoFilter
};
return clone;
}
}