import java.util.ArrayList;
public class InitPieceLocation implements java.io.Serializable{
Point [][] playPoint;
ChessPiece [] redPiece,blackPiece;
ChessBox redChessBox,blackChessBox;
public void setPoint(Point [][] p){
playPoint=p;
}
public void setRedChessPiece(ChessPiece [] redPiece){
this.redPiece=redPiece;
}
public void setBlackChessPiece(ChessPiece [] blackPiece){
this.blackPiece=blackPiece;
}
public void setRedChessBox(ChessBox redChessBox){
this.redChessBox=redChessBox;
}
public void setBlackChessBox(ChessBox blackChessBox){
this.blackChessBox=blackChessBox;
}
public void putAllPieceToPlayChessArea(){
for(int i=0;i<playPoint.length;i++){
for(int j=0;j<playPoint[i].length;j++){
playPoint[i][j].setHaveChessPiece(false);
}
}
ArrayList<ChessPiece> pieceList=new ArrayList<ChessPiece>();
for(int i=0;i<redPiece.length;i++){
pieceList.add(redPiece[i]);pieceList.add(blackPiece[i]);
}
for(int i=0;i<blackPiece.length;i++){
pieceList.add(blackPiece[i]);
}
for(int k=0;k<pieceList.size();k++){
ChessPiece piece=pieceList.get(k);
int w=piece.getBounds().width;
int h=piece.getBounds().height;
Point p=null;
p=piece.getAtPoint();
if(p!=null)
p.setHaveChessPiece(false);
String name=piece.getName();
if(name.equals("帅")&&piece.getIsRed()){
piece.setLocation(playPoint[9][4].getX()-w/2,playPoint[9][4].getY()-h/2);
piece.setAtPoint(playPoint[9][4]);
playPoint[9][4].setHaveChessPiece(true);
playPoint[9][4].setChessPiece(piece);
}
if((name.equals("士")||name.equals("仕"))&&piece.getIsRed()){
if(playPoint[9][3].isHaveChessPiece()==false){
piece.setLocation(playPoint[9][3].getX()-w/2,playPoint[9][3].getY()-h/2);
piece.setAtPoint(playPoint[9][3]);
playPoint[9][3].setHaveChessPiece(true);
playPoint[9][3].setChessPiece(piece);
}
else{
piece.setLocation(playPoint[9][5].getX()-w/2,playPoint[9][5].getY()-h/2);
piece.setAtPoint(playPoint[9][5]);
playPoint[9][5].setHaveChessPiece(true);
playPoint[9][5].setChessPiece(piece);
}
}
if(name.equals("相")&&piece.getIsRed()){
if(playPoint[9][2].isHaveChessPiece()==false){
piece.setLocation(playPoint[9][2].getX()-w/2,playPoint[9][2].getY()-h/2);
piece.setAtPoint(playPoint[9][2]);
playPoint[9][2].setHaveChessPiece(true);
playPoint[9][2].setChessPiece(piece);
}
else{
piece.setLocation(playPoint[9][6].getX()-w/2,playPoint[9][6].getY()-h/2);
piece.setAtPoint(playPoint[9][6]);
playPoint[9][6].setHaveChessPiece(true);
playPoint[9][6].setChessPiece(piece);
}
}
if((name.equals("马")||name.equals("馬"))&&piece.getIsRed()){
if(playPoint[9][1].isHaveChessPiece()==false){
piece.setLocation(playPoint[9][1].getX()-w/2,playPoint[9][1].getY()-h/2);
piece.setAtPoint(playPoint[9][1]);
playPoint[9][1].setHaveChessPiece(true);
playPoint[9][1].setChessPiece(piece);
}
else{
piece.setLocation(playPoint[9][7].getX()-w/2,playPoint[9][7].getY()-h/2);
piece.setAtPoint(playPoint[9][7]);
playPoint[9][7].setHaveChessPiece(true);
playPoint[9][7].setChessPiece(piece);
}
}
if((name.equals("车")||name.equals("車"))&&piece.getIsRed()){
if(playPoint[9][0].isHaveChessPiece()==false){
piece.setLocation(playPoint[9][0].getX()-w/2,playPoint[9][0].getY()-h/2);
piece.setAtPoint(playPoint[9][0]);
playPoint[9][0].setHaveChessPiece(true);
playPoint[9][0].setChessPiece(piece);
}
else{
piece.setLocation(playPoint[9][8].getX()-w/2,playPoint[9][7].getY()-h/2);
piece.setAtPoint(playPoint[9][8]);
playPoint[9][8].setHaveChessPiece(true);
playPoint[9][8].setChessPiece(piece);
}
}
if(name.equals("炮")&&piece.getIsRed()){
if(playPoint[7][1].isHaveChessPiece()==false){
piece.setLocation(playPoint[7][1].getX()-w/2,playPoint[7][1].getY()-h/2);
piece.setAtPoint(playPoint[7][1]);
playPoint[7][1].setHaveChessPiece(true);
playPoint[7][1].setChessPiece(piece);
}
else{
piece.setLocation(playPoint[7][7].getX()-w/2,playPoint[7][7].getY()-h/2);
piece.setAtPoint(playPoint[7][7]);
playPoint[7][7].setHaveChessPiece(true);
playPoint[7][7].setChessPiece(piece);
}
}
if(name.equals("兵")&&piece.getIsRed()){
if(playPoint[6][0].isHaveChessPiece()==false){
piece.setLocation(playPoint[6][0].getX()-w/2,playPoint[6][0].getY()-h/2);
piece.setAtPoint(playPoint[6][0]);
playPoint[6][0].setHaveChessPiece(true);
playPoint[6][0].setChessPiece(piece);
}
else if(playPoint[6][2].isHaveChessPiece()==false){
piece.setLocation(playPoint[6][2].getX()-w/2,playPoint[6][2].getY()-h/2);
piece.setAtPoint(playPoint[6][2]);
playPoint[6][2].setHaveChessPiece(true);
playPoint[6][2].setChessPiece(piece);
}
else if(playPoint[6][4].isHaveChessPiece()==false){
piece.setLocation(playPoint[6][4].getX()-w/2,playPoint[6][4].getY()-h/2);
piece.setAtPoint(playPoint[6][4]);
playPoint[6][4].setHaveChessPiece(true);
playPoint[6][4].setChessPiece(piece);
}
else if(playPoint[6][6].isHaveChessPiece()==false){
piece.setLocation(playPoint[6][6].getX()-w/2,playPoint[6][6].getY()-h/2);
piece.setAtPoint(playPoint[6][6]);
playPoint[6][6].setHaveChessPiece(true);
playPoint[6][6].setChessPiece(piece);
}
else{
piece.setLocation(playPoint[6][8].getX()-w/2,playPoint[6][8].getY()-h/2);
piece.setAtPoint(playPoint[6][8]);
playPoint[6][8].setHaveChessPiece(true);
playPoint[6][8].setChessPiece(piece);
}
}
if(name.equals("将")&&piece.getIsBlack()){
piece.setLocation(playPoint[0][4].getX()-w/2,playPoint[0][4].getY()-h/2);
piece.setAtPoint(playPoint[0][4]);
playPoint[0][4].setHaveChessPiece(true);
playPoint[0][4].setChessPiece(piece);
}
if((name.equals("士")||name.equals("仕"))&&piece.getIsBlack()){
if(playPoint[0][3].isHaveChessPiece()==false){
piece.setLocation(playPoint[0][3].getX()-w/2,playPoint[0][3].getY()-h/2);
piece.setAtPoint(playPoint[0][3]);
playPoint[0][3].setHaveChessPiece(true);
playPoint[0][3].setChessPiece(piece);
}
else{
piece.setLocation(playPoint[0][5].getX()-w/2,playPoint[0][5].getY()-h/2);
piece.setAtPoint(playPoint[0][5]);
playPoint[0][5].setHaveChessPiece(true);
仰望IT星空
- 粉丝: 0
- 资源: 1
最新资源
- YOLOv8完整网络结构图详细visio
- LCD1602电子时钟程序
- 西北太平洋热带气旋【灾害风险统计】及【登陆我国次数评估】数据集-1980-2023
- 全球干旱数据集【自校准帕尔默干旱程度指数scPDSI】-190101-202312-0.5x0.5
- 基于Python实现的VAE(变分自编码器)训练算法源代码+使用说明
- 全球干旱数据集【标准化降水蒸发指数SPEI-12】-190101-202312-0.5x0.5
- C语言小游戏-五子棋-详细代码可运行
- 全球干旱数据集【标准化降水蒸发指数SPEI-03】-190101-202312-0.5x0.5
- spring boot aop记录修改前后的值demo
- 全球干旱数据集【标准化降水蒸发指数SPEI-01】-190101-202312-0.5x0.5
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈