Example #1
0
        public void doMove(bool cap, BoardTile from, BoardTile to)
        {
            to.setPiece(from.getPiece());

            if (to.y == 0 || to.y == 7)
            {
                to.getPiece().setKing(true);
            }

            from.remPiece();

            if (!cap)
            {
                turn = 1 - turn; //Switch player
            }
            else
            {
                if (to.x > from.x)
                {
                    if (to.y > from.y)
                    {
                        //LR
                        boardRecs[from.x + 1, from.y + 1].remPiece();

                    }
                    else
                    {
                        //UR
                        boardRecs[from.x + 1, from.y - 1].remPiece();

                    }

                }
                else
                {
                    if (to.y > from.y)
                    {
                        //LL
                        boardRecs[from.x - 1, from.y + 1].remPiece();

                    }
                    else
                    {
                        //UL
                        boardRecs[from.x - 1, from.y - 1].remPiece();

                    }

                }
            }
            moves = new List<BoardTile>();
            caps = new List<BoardTile>();
        }
Example #2
0
        public Board(Texture2D spriteSheet)
        {
            Sprites = spriteSheet;

            boardRecs = new BoardTile[8, 8];

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    boardRecs[i, j] = new BoardTile(i, j, new Rectangle(i * S_LENGTH, j * S_LENGTH, S_LENGTH, S_LENGTH));
                }
            }
        }
Example #3
0
        public void onClick(MouseState m)
        {
            BoardTile sel = getClicked(m);

            if (sel == null) return;

            //See if sel is in moves

            foreach (BoardTile bt in moves)
            {
                if (sel.Equals(bt))
                {
                    doMove(false, selected, sel);
                    return;
                }
            }

            foreach (BoardTile bt in caps)
            {
                if (sel.Equals(bt))
                {
                    doMove(true, selected, sel);
                    return;
                }
            }

            selected = sel;

            //Set move options

            moves = new List<BoardTile>();
            caps = new List<BoardTile>();

            if (!selected.hasPiece()) return; //No piece, return

            Piece p = selected.getPiece();

            if (p.getColor() != turn) return; //Not correct color, return

            BoardTile t_move;
            //Black

            if (p.getColor() == PColor.black)
            {
                ////////////////////// Upper - Left

                if (selected.x > 0 && selected.y > 0)
                {
                    t_move = boardRecs[selected.x - 1, selected.y - 1];

                    if (t_move.hasPiece())
                    {
                        //Test for capture
                        if (t_move.getPiece().getColor() != turn)
                        {
                            if (selected.x > 1 && selected.y > 1)
                            {
                                if (!boardRecs[selected.x - 2, selected.y - 2].hasPiece())
                                {
                                    //Can capture
                                    caps.Add(boardRecs[selected.x - 2, selected.y - 2]);

                                }

                            }
                        }
                    }
                    else
                    {
                        //Empty
                        moves.Add(t_move);
                    }

                }

                ///////////////////////////// Upper - Right

                if (selected.x < 7 && selected.y > 0)
                {
                    t_move = boardRecs[selected.x + 1, selected.y - 1];

                    if (t_move.hasPiece())
                    {
                        //Test for capture
                        if (t_move.getPiece().getColor() != turn)
                        {
                            if (selected.x < 6 && selected.y > 1)
                            {
                                if (!boardRecs[selected.x + 2, selected.y - 2].hasPiece())
                                {
                                    //Can capture
                                    caps.Add(boardRecs[selected.x + 2, selected.y - 2]);
                                }

                            }
                        }
                    }
                    else
                    {
                        //Empty
                        moves.Add(t_move);
                    }

                }

                ////////////////////////// Kings Only
                if (p.isKing())
                {
                    //////////////////////// Lower - Left

                    if (selected.x > 0 && selected.y < 7)
                    {
                        t_move = boardRecs[selected.x - 1, selected.y + 1];

                        if (t_move.hasPiece())
                        {
                            //Test for capture
                            if (t_move.getPiece().getColor() != turn)
                            {
                                if (selected.x > 1 && selected.y < 6)
                                {
                                    if (!boardRecs[selected.x - 2, selected.y + 2].hasPiece())
                                    {
                                        //Can capture
                                        caps.Add(boardRecs[selected.x - 2, selected.y + 2]);
                                    }

                                }
                            }
                        }
                        else
                        {
                            //Empty
                            moves.Add(t_move);
                        }

                    }

                    /////////////////////// Lower - Right

                    if (selected.x < 7 && selected.y < 7)
                    {
                        t_move = boardRecs[selected.x + 1, selected.y + 1];

                        if (t_move.hasPiece())
                        {
                            //Test for capture
                            if (t_move.getPiece().getColor() != turn)
                            {
                                if (selected.x < 6 && selected.y < 6)
                                {
                                    if (!boardRecs[selected.x + 2, selected.y + 2].hasPiece())
                                    {
                                        //Can capture
                                        caps.Add(boardRecs[selected.x + 2, selected.y + 2]);
                                    }

                                }
                            }
                        }
                        else
                        {
                            //Empty
                            moves.Add(t_move);
                        }

                    }

                } // End Kings

            } // End Black
            else
            {
                ///////////// Red

                //////////////////////// Lower - Left

                if (selected.x > 0 && selected.y < 7)
                {
                    t_move = boardRecs[selected.x - 1, selected.y + 1];

                    if (t_move.hasPiece())
                    {
                        //Test for capture
                        if (t_move.getPiece().getColor() != turn)
                        {
                            if (selected.x > 1 && selected.y < 6)
                            {
                                if (!boardRecs[selected.x - 2, selected.y + 2].hasPiece())
                                {
                                    //Can capture
                                    caps.Add(boardRecs[selected.x - 2, selected.y + 2]);
                                }

                            }
                        }
                    }
                    else
                    {
                        //Empty
                        moves.Add(t_move);
                    }

                }

                /////////////////////// Lower - Right

                if (selected.x < 7 && selected.y < 7)
                {
                    t_move = boardRecs[selected.x + 1, selected.y + 1];

                    if (t_move.hasPiece())
                    {
                        //Test for capture
                        if (t_move.getPiece().getColor() != turn)
                        {
                            if (selected.x < 6 && selected.y < 6)
                            {
                                if (!boardRecs[selected.x + 2, selected.y + 2].hasPiece())
                                {
                                    //Can capture
                                    caps.Add(boardRecs[selected.x + 2, selected.y + 2]);
                                }

                            }
                        }
                    }
                    else
                    {
                        //Empty
                        moves.Add(t_move);
                    }

                }

                ////////////////////////// Kings Only
                if (p.isKing())
                {
                    ////////////////////// Upper - Left

                    if (selected.x > 0 && selected.y > 0)
                    {
                        t_move = boardRecs[selected.x - 1, selected.y - 1];

                        if (t_move.hasPiece())
                        {
                            //Test for capture
                            if (t_move.getPiece().getColor() != turn)
                            {
                                if (selected.x > 1 && selected.y > 1)
                                {
                                    if (!boardRecs[selected.x - 2, selected.y - 2].hasPiece())
                                    {
                                        //Can capture
                                        caps.Add(boardRecs[selected.x - 2, selected.y - 2]);
                                    }

                                }
                            }
                        }
                        else
                        {
                            //Empty
                            moves.Add(t_move);
                        }

                    }

                    ///////////////////////////// Upper - Right

                    if (selected.x < 7 && selected.y > 0)
                    {
                        t_move = boardRecs[selected.x + 1, selected.y - 1];

                        if (t_move.hasPiece())
                        {
                            //Test for capture
                            if (t_move.getPiece().getColor() != turn)
                            {
                                if (selected.x < 6 && selected.y > 1)
                                {
                                    if (!boardRecs[selected.x + 2, selected.y - 2].hasPiece())
                                    {
                                        //Can capture
                                        caps.Add(boardRecs[selected.x + 2, selected.y - 2]);
                                    }

                                }
                            }
                        }
                        else
                        {
                            //Empty
                            moves.Add(t_move);
                        }

                    }

                } // End Kings

            } //End Red
        }