private static string GetPieceCode(PieceView Piece) { if (Piece is Pawn) { return(""); } else if (Piece is Queen) { return("Q"); } else if (Piece is Bishop) { return("B"); } else if (Piece is Knight) { return("N"); } else if (Piece is Rook) { return("R"); } else if (Piece is King) { return("K"); } else { throw new InvalidOperationException("Invalid Piece type: " + Piece.GetType().Name); } }
private bool IsPossibleMove(PieceView piece, int x, int y) { if (x < 0 || y < 0 || x > 7 || y > 7) { return(false); } var existing = GetPieceOn(x, y); if (existing != null) { if (existing.Color == piece.Color) { return(false); } if (piece is Pawn && piece.X == existing.X) { return(false); } if (existing is King) { return(false); } } return(true); }
public void DrawPiece(PieceView piece) { var image = UIImage.FromFile(string.Format("figures/{0}-{1}.png", piece.Color.ToString().ToLowerInvariant(), piece.GetType().Name.ToLowerInvariant())); piece.Image = image; piece.Frame = new RectangleF(GetX(piece.X), GetY(piece.Y), CellWidth, CellWidth); piece.CurrentFrame = piece.Frame; Add(piece); }
private void CleanupAfterDrop(PieceView piece) { foreach (var highlight in highlights) { highlight.RemoveFromSuperview(); } highlights.Clear(); if (piece != null) { piece.Frame = piece.CurrentFrame; } }
private void HighlightPossibleMoves(PieceView piece) { var moves = piece.GetMoves(); foreach (var move in moves) { if (!IsPossibleMove(piece, move.Item1, move.Item2)) { continue; } var highlight = new UIView(); highlight.BackgroundColor = UIColor.LightGray; highlight.Frame = new RectangleF(GetX(move.Item1), GetY(move.Item2), CellWidth, CellWidth); Add(highlight); SendSubviewToBack(highlight); highlights.Add(highlight); } }
private static string GetPieceCode(PieceView Piece) { if (Piece is Pawn) return ""; else if (Piece is Queen) return "Q"; else if (Piece is Bishop) return "B"; else if (Piece is Knight) return "N"; else if (Piece is Rook) return "R"; else if (Piece is King) return "K"; else throw new InvalidOperationException("Invalid Piece type: " + Piece.GetType().Name); }
private bool IsPossibleMove(PieceView piece, int x, int y) { if (x < 0 || y < 0 || x > 7 || y > 7) return false; var existing = GetPieceOn(x, y); if (existing != null) { if (existing.Color == piece.Color) return false; if (piece is Pawn && piece.X == existing.X) return false; if (existing is King) return false; } return true; }
private void HighlightPossibleMoves(PieceView piece) { var moves = piece.GetMoves(); foreach (var move in moves) { if (!IsPossibleMove(piece, move.Item1, move.Item2)) continue; var highlight = new UIView(); highlight.BackgroundColor = UIColor.LightGray; highlight.Frame = new RectangleF(GetX(move.Item1), GetY(move.Item2), CellWidth, CellWidth); Add(highlight); SendSubviewToBack(highlight); highlights.Add(highlight); } }
private void CleanupAfterDrop(PieceView piece) { foreach (var highlight in highlights) highlight.RemoveFromSuperview(); highlights.Clear(); if (piece != null) piece.Frame = piece.CurrentFrame; }