应用系统的面向对象设计与分析综合性实验报告--中国象棋打谱软件(编辑修改稿)内容摘要:

{ int x=point[i][j].getX()。 int y=point[i][j].getY()。 if((x,y)) { startI=i。 startJ=j。 break。 } } } } 10 } public void mouseMoved(MouseEvent e) { } public void mouseDragged(MouseEvent e) { ChessPiece piece=null。 if(() instanceof ChessPiece) { piece=(ChessPiece)()。 move=true。 e=(piece,e,this)。 } if(()==this) { if(moveamp。 amp。 piece!=null) { x=()。 y=()。 if(红方走棋 amp。 amp。 (( ()).equals(红方颜色 ))) { (()/2,()/2)。 } if(黑方走棋 amp。 amp。 ( ().equals(黑方颜色 ))) { (()/2,()/2)。 } } } } public void mouseReleased(MouseEvent e) { ChessPiece piece=null。 move=false。 Rectangle rect=null。 if(() instanceof ChessPiece) { piece=(ChessPiece)()。 rect=()。 e=(piece,e,this)。 11 } if(()==this) { boolean containChessPoint=false。 int x=0,y=0。 int m=0,n=0。 if(piece!=null) { for(int i=1。 i=x轴长。 i++) { for(int j=1。 j=y轴长。 j++) { x=point[i][j].getX()。 y=point[i][j].getY()。 if((x,y)) { containChessPoint=true。 m=i。 n=j。 break。 } } } } if(piece!=nullamp。 amp。 containChessPoint) { Color pieceColor= ()。 if(point[m][n].isPiece()) { Color c=(point[m][n].getPiece()).获取棋子颜色 ()。 if(()==()) { (startX,startY)。 (point[startI][startJ]).set有棋子 (true)。 } else { boolean ok=(piece,startI,startJ, m,n)。 if(ok) { ChessPiece pieceRemoved=point[m][n].getPiece()。 point[m][n].reMovePiece(pieceRemoved,this)。 12 point[m][n].setPiece(piece,this)。 (point[startI][startJ]).set有棋子 (false)。 (piece,startI,startJ,m,n)。 (pieceRemoved)。 if( ().equals(红方颜色 )) { 红方走棋 =false。 黑方走棋 =true。 } if( ().equals(黑方颜色 )) { 黑方走棋 =false。 红方走棋 =true。 } validate()。 repaint()。 } else { (startX,startY)。 (point[startI][startJ]).set有棋子 (true)。 } } } else { boolean ok=(piece,startI,startJ, m,n)。 if(ok) { point[m][n].setPiece(piece,this)。 (point[startI][startJ]).set有棋子 (false)。 (piece,startI,startJ,m,n)。 (没吃棋子 )。 if( ().equals(红方颜色 )) { 红方走棋 =false。 黑方走棋 =true。 } if( ().equals(黑方颜色 )) { 黑方走棋 =false。 红方走棋 =true。 } 13 } else { (startX,startY)。 (point[startI][startJ]).set有棋子 (true)。 } } } if(piece!=nullamp。 amp。 !containChessPoint) { (startX,startY)。 (point[startI][startJ]).set有棋子 (true)。 } } } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mouseClicked(MouseEvent e) { } } import .*。 import .*。 import .*。 public class ChessPiece extends JLabel { String name。 Color backColor=null,foreColor。 String 颜色类别 =null。 ChessBoard board=null。 int width,height。 public ChessPiece(String name,Color fc,Color bc,int width,int height,ChessBoard board) { =name。 =board。 =width。 =height。 14 foreColor=fc。 backColor=bc。 setSize(width,height)。 setBackground(bc)。 addMouseMotionListener(board)。 addMouseListener(board)。 } public void paint(Graphics g) { (foreColor)。 (2,2,width2,height2)。 ()。 (new Font(隶书 ,28))。 (name,7,height8)。 ()。 (2,2,width2,height2)。 } public int getWidth()。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。