Ejemplo n.º 1
0
 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);
     }
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        private void CleanupAfterDrop(PieceView piece)
        {
            foreach (var highlight in highlights)
            {
                highlight.RemoveFromSuperview();
            }

            highlights.Clear();

            if (piece != null)
            {
                piece.Frame = piece.CurrentFrame;
            }
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
 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);
 }
Ejemplo n.º 8
0
        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;
        }
Ejemplo n.º 9
0
        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);
            }
        }
Ejemplo n.º 10
0
        private void CleanupAfterDrop(PieceView piece)
        {
            foreach (var highlight in highlights)
                highlight.RemoveFromSuperview();

            highlights.Clear();

            if (piece != null)
                piece.Frame = piece.CurrentFrame;
        }