文章目录

一、每日例会二、昨天已完成的工作三、今天计划完成的工作四、工作中遇到的困难五、项目燃尽图六、代码签入七、适当的项目程序八、每日总结

一、每日例会

二、昨天已完成的工作

昨日已完成任务第一篇Scrum冲刺博客

三、今天计划完成的工作

今日计划完成任务完善游戏相关功能,编写能实现“棋子行进规则、悔棋、判断输赢”等功能的代码

四、工作中遇到的困难

五、项目燃尽图

六、代码签入

/**

* 功能:判断棋子是否可以放到目标位置

* 参数:_mapChess -> 棋子

* 参数:_newRow -> 目标行位置

* 参数:_newColumn -> 目标列位置

* 备注:点空位或对方棋子上,已方棋子略

*/

private boolean isAbleToMove(Map _mapChess,int _newRow,int _newColumn)

{

int oldRow = -1; //移动前行位置

int oldColulmn = -1; //移动前列位置

int index = -1; //目标索引

String type = ""; //棋子类型

String direction = ""; //棋子方向(T-上方,B-下方)

//死亡棋子不能移动

if("T".equals(_mapChess.get("dead"))){return false;}

oldRow = Integer.parseInt(_mapChess.get("newRow"));

oldColulmn = Integer.parseInt(_mapChess.get("newColumn"));

type = _mapChess.get("type");

direction = _mapChess.get("direction");

index = this.gamePanel.chessBoradState[_newRow][_newColumn];

//不能吃自己伙的棋子

if(index != -1 && Integer.parseInt(this.gamePanel.mapChess[index].get("color")) == Integer.parseInt(_mapChess.get("color"))){return false;}

//不能吃自身

if(oldRow == _newRow && oldColulmn == _newColumn) {return false;}

if("king".equals(type)) //将帅

{

//不能出九宫

if((_newRow > 2 && _newRow < 7) || _newColumn < 3 || _newColumn > 5){return false;}

//一次只能走一格

if(Math.abs(_newRow - oldRow) > 1 || Math.abs(_newColumn - oldColulmn) > 1){return false;}

//不能走斜线

if((_newRow - oldRow) * (_newColumn - oldColulmn) != 0){return false;}

//将帅不能露脸

if(index != -1 && "king".equals(this.gamePanel.mapChess[index].get(type)) && oldColulmn == _newColumn) //目标棋子是将帅并且在同一列上

{

//判断中间是否有棋子

int count = 0;

int min = Math.min(oldRow,_newRow);

int max = Math.max(oldRow,_newRow);

for(int row=min+1;row

{

if(this.gamePanel.chessBoradState[row][_newColumn] != -1){count++;}

}

if(count == 0){return false;}

}

}

else if("guard".equals(type)) //士仕

{

//不能出九宫

if((_newRow > 2 && _newRow < 7) || _newColumn < 3 || _newColumn > 5){return false;}

//一次只能走一格

if(Math.abs(_newRow - oldRow) > 1 || Math.abs(_newColumn - oldColulmn) > 1){return false;}

//不能走横线或竖线

if((_newRow - oldRow) * (_newColumn - oldColulmn) == 0){return false;}

}

else if("elephant".equals(type)) //象相

{

//不能越界

if("T".equals(direction))

{

if(_newRow > 4){return false;}

}

else

{

if(_newRow < 5){return false;}

}

//不能走横线或竖线

if((_newRow - oldRow) * (_newColumn - oldColulmn) == 0){return false;}

//一次只能走二格

if(Math.abs(_newRow - oldRow) != 2 || Math.abs(_newColumn - oldColulmn) != 2){return false;}

//是否堵象眼

if(this.gamePanel.chessBoradState[Math.min(oldRow,_newRow) + 1][Math.min(oldColulmn,_newColumn) + 1] != -1){return false;}

}

else if("horse".equals(type)) //马(8种跳法,4种别腿)

{

//必须走日字格

if( Math.abs((_newRow - oldRow)) * Math.abs((_newColumn - oldColulmn)) != 2){return false;}

//向上跳

if(_newRow - oldRow == -2)

{

if(this.gamePanel.chessBoradState[oldRow - 1][oldColulmn] != -1){return false;}

}

//向下跳

if(_newRow - oldRow == 2)

{

if(this.gamePanel.chessBoradState[oldRow + 1][oldColulmn] != -1){return false;}

}

//向左跳

if(_newColumn - oldColulmn == -2)

{

if(this.gamePanel.chessBoradState[oldRow][oldColulmn - 1] != -1){return false;}

}

//向右跳

if(_newColumn - oldColulmn == 2)

{

if(this.gamePanel.chessBoradState[oldRow][oldColulmn + 1] != -1){return false;}

}

}

else if("rook".equals(type)) //车

{

//不能走斜线

if((_newRow - oldRow) * (_newColumn - oldColulmn) != 0){return false;}

//竖走

if(_newColumn == oldColulmn)

{

//判断中间是否有棋子

int min = Math.min(oldRow,_newRow);

int max = Math.max(oldRow,_newRow);

for(int row=min+1;row

{

if(this.gamePanel.chessBoradState[row][_newColumn] != -1){return false;}

}

}

//横走

if(_newRow == oldRow)

{

//判断中间是否有棋子

int min = Math.min(oldColulmn,_newColumn);

int max = Math.max(oldColulmn,_newColumn);

for(int column=min+1;column

{

if(this.gamePanel.chessBoradState[_newRow][column] != -1){return false;}

}

}

}

else if("cannon".equals(type)) //炮

{

int count = 0;

//不能走斜线

if((_newRow - oldRow) * (_newColumn - oldColulmn) != 0){return false;}

//竖走

if(_newColumn == oldColulmn)

{

//判断中间是否有棋子

int min = Math.min(oldRow,_newRow);

int max = Math.max(oldRow,_newRow);

for(int row=min+1;row

{

if(this.gamePanel.chessBoradState[row][_newColumn] != -1){count++;}

}

}

//横走

if(_newRow == oldRow)

{

//判断中间是否有棋子

int min = Math.min(oldColulmn,_newColumn);

int max = Math.max(oldColulmn,_newColumn);

for(int column=min+1;column

{

if(this.gamePanel.chessBoradState[_newRow][column] != -1){count++;}

}

}

//开始判断是否可以移动或吃棋子

if(count > 1)

{

return false;

}

else if(count == 1)

{

if(this.gamePanel.chessBoradState[_newRow][_newColumn] == -1){return false;} //打空炮的不要

}

else

{

if(this.gamePanel.chessBoradState[_newRow][_newColumn] != -1){return false;}

}

}

else if("soldier".equals(type)) //卒兵

{

//不能走斜线

if((_newRow - oldRow) * (_newColumn - oldColulmn) != 0){return false;}

//一次只能走一格

if(Math.abs(_newRow - oldRow) > 1 || Math.abs(_newColumn - oldColulmn) > 1){return false;}

//小卒过河不回头

if("T".equals(direction)) //上方

{

if(oldRow > 4) //过河了

{

if(_newRow < oldRow){return false;} //不许向后退

}

else

{

if(_newColumn == oldColulmn && _newRow > oldRow){} //只能往前走

else

{

return false;

}

}

}

else //下方

{

if(oldRow < 5) //过河了

{

if(_newRow > oldRow){return false;} //不许向后退

}

else

{

if(_newColumn == oldColulmn && _newRow < oldRow){} //只能往前走

else

{

return false;

}

}

}

}

return true;

}

七、适当的项目程序

/**

* 功能:判断下一步是红棋下还是黑棋下

*/

private int getNextChessColor()

{

int chessColor = -1;

//得到上一步信息

if(this.gamePanel.listChess.size() > 0)

{

Map mapLast = this.gamePanel.listChess.get(this.gamePanel.listChess.size() - 1);

if(Integer.parseInt(mapLast.get("color")) == this.gamePanel.BLACKCHESS)

{

chessColor = this.gamePanel.REDCHESS;

}

else

{

chessColor = this.gamePanel.BLACKCHESS;

}

}

else

{

if(this.gamePanel.fightType == 0) //人机对战

{

if(this.gamePanel.playFirst == 1) //玩家先手

{

chessColor = this.gamePanel.chessColor;

}

else //电脑先手(这是不想赢啊)

{

if(this.gamePanel.chessColor == this.gamePanel.BLACKCHESS)

{

chessColor = this.gamePanel.REDCHESS;

}

else

{

chessColor = this.gamePanel.BLACKCHESS;

}

}

}

else //人人对战

{

chessColor = this.gamePanel.chessColor;

}

}

return chessColor;

}

/**

* 功能:将军提示

*/

private void check()

{

//全体循环,不知道将哪头的军

for(int i=0;i

{

this.getMoveRoute(this.gamePanel.mapChess[i]);

for(int j=0;j

{

Map map = this.gamePanel.listMove.get(j);

int index = this.gamePanel.chessBoradState[map.get("row")][map.get("column")];

if(index != -1 && "king".equals(this.gamePanel.mapChess[index].get("type")))

{

JOptionPane.showMessageDialog(null,"将军,十万火急!");

break;

}

}

}

this.gamePanel.listMove.clear();

this.gamePanel.repaint();

}

八、每日总结

加油,变得比昨天更强!

文章来源

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。