Example #1
0
 void CellPanel_Click(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         if (this.board.SourceCell == null)
         {
             this.board.SourceCell = this.board.LogicBoard.getCell(this.cellID);
             this.board.MovePiece  = this.board.SourceCell.getPiece();
             //Check if cell contains piece
             if (this.board.MovePiece == null)
             {
                 this.board.SourceCell = null;
             }
             //Check if player click their alliance pieces
             else if (this.board.LogicBoard.CurrentPlayer.getAlliance() != this.board.MovePiece.getSide())
             {
                 this.board.SourceCell = null;
             }
             else
             {
                 this.hightlight();
                 this.hightlightLegalMoves();
             }
         }
         else
         {
             this.board.DesCell = this.board.LogicBoard.getCell(this.cellID);
             Move move = MoveFactory.createMove(this.board.LogicBoard, this.board.SourceCell.getCellCoordinate(), this.board.DesCell.getCellCoordinate());
             if (move.isPromote())
             {
                 this.choosePiece((PawnPromotionMove)move);
             }
             if (move != ChessEngine.Move.NULL_MOVE)
             {
                 MoveTransition transition = this.board.LogicBoard.CurrentPlayer.makeMove(move);
                 if (transition.getMoveStatus().isDone())
                 {
                     this.board.executeMove(transition, move);
                     move = this.board.GameForm.getAI().getMove(this.board.LogicBoard);
                     if (move != ChessEngine.Move.NULL_MOVE)
                     {
                         transition = this.board.LogicBoard.CurrentPlayer.makeMove(move);
                         if (transition.getMoveStatus().isDone())
                         {
                             this.board.executeMove(transition, move);
                         }
                     }
                 }
                 else
                 {
                     //Clear source cell and legal cells that has been click;
                     this.board.resetClick();
                 }
             }
         }
     }
     if (e.Button == MouseButtons.Right)
     {
         this.board.resetClick();
     }
 }