public class ChessPiece
{
public string Name { get; set; } // 象、獅、虎...
public Color Color { get; set; } // 紅/黑
public int Index { get; set; } // 階級權重 0~7
public bool IsFaceUp { get; set; } // 是否翻開
public int Row { get; set; }
public int Col { get; set; }
}
var listChess = new List<ChessPiece>();
listChess.Add(new ChessPiece { Name = "象", Color = Colors.Red, Index = 7 });
listChess.Add(new ChessPiece { Name = "獅", Color = Colors.Red, Index = 6 });
listChess.Add(new ChessPiece { Name = "虎", Color = Colors.Red, Index = 5 });
// ... 依序加入豹、狼、狗、貓、鼠,紅黑各 8 枚共 16 枚
// 打亂順序並對應至 4x4 棋盤格位
private bool CanEat(ChessPiece attacker, ChessPiece defender)
{
if (attacker.Color == defender.Color) return false; // 同色不可互吃
// 特殊規則:鼠吃象
if (attacker.Name == "鼠" && defender.Name == "象") return true;
if (attacker.Name == "象" && defender.Name == "鼠") return false;
// 一般階級比較
return attacker.Index >= defender.Index; // 同階 Index 相等 => 雙亡(上層邏輯處理)
}
參考開源專案 WPF 3D Rotate 實現翻牌立體轉動,提升遊戲質感。
採用 Silverlight 中國高手動畫樣式 美化棋盤與棋子外觀。
