Code smells
This commit is contained in:
47
Gameboard.ShogiUI.BoardState/Pieces/Piece.cs
Normal file
47
Gameboard.ShogiUI.BoardState/Pieces/Piece.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using PathFinding;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Gameboard.ShogiUI.BoardState.Pieces
|
||||
{
|
||||
[DebuggerDisplay("{WhichPiece} {Owner}")]
|
||||
public abstract class Piece : IPlanarElement
|
||||
{
|
||||
protected MoveSet promotedMoveSet;
|
||||
protected MoveSet moveSet;
|
||||
|
||||
public MoveSet MoveSet => IsPromoted ? promotedMoveSet : moveSet;
|
||||
public abstract Piece DeepClone();
|
||||
public WhichPiece WhichPiece { get; }
|
||||
public WhichPlayer Owner { get; private set; }
|
||||
public bool IsPromoted { get; private set; }
|
||||
public bool IsUpsideDown => Owner == WhichPlayer.Player2;
|
||||
|
||||
public Piece(WhichPiece piece, WhichPlayer owner)
|
||||
{
|
||||
WhichPiece = piece;
|
||||
Owner = owner;
|
||||
IsPromoted = false;
|
||||
}
|
||||
|
||||
public bool CanPromote => !IsPromoted
|
||||
&& WhichPiece != WhichPiece.King
|
||||
&& WhichPiece != WhichPiece.GoldenGeneral;
|
||||
|
||||
public void ToggleOwnership()
|
||||
{
|
||||
Owner = Owner == WhichPlayer.Player1
|
||||
? WhichPlayer.Player2
|
||||
: WhichPlayer.Player1;
|
||||
}
|
||||
|
||||
public void Promote() => IsPromoted = CanPromote;
|
||||
|
||||
public void Demote() => IsPromoted = false;
|
||||
|
||||
public void Capture()
|
||||
{
|
||||
ToggleOwnership();
|
||||
Demote();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user