郁闷死了,见到鬼了,这么简单的问题,怎么会,无语中。。。。。。。。。。

thb28 2005-04-11 04:53:44
我弄了个二维数组,存放一个棋盘,比如0是没有棋子,1代表红车,2代表红马,依次类推

private int chessBoard[][] = { {1, 2, 3, 4, 5, 4, 3, 2, 1}, //棋盘数组
{0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 6, 0, 0, 0, 0, 0, 6, 0},
{7, 0, 7, 0, 7, 0, 7, 0, 7},
{0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0},
{14,0,14, 0,14, 0,14, 0,14},
{0,13, 0, 0, 0, 0, 0,13, 0},
{0, 0 ,0 ,0 ,0 ,0 ,0, 0, 0},
{8, 9,10,11,12,11,10, 9, 8}

};

然后写了个函数,根据数组的内容画出相应的界面,函数为:
public void paintChesses(int chessBoard [][],Graphics g)
{
int i = 0;
int j = 0;

g.setColor(0,0,0);
// System.out.println(chessBoard[2][1]);



for( ;i < 10; i++)

for( ; j < 9 ;j++)

switch(chessBoard[i][j])


{
case 1: //画红车

g.drawString("车",empty + chessMapGridsOfWidthLength * j,empty + chessMapGridsOfHeight * i,Graphics.TOP|Graphics.LEFT);

//System.out.println( empty + chessMapGridsOfWidthLength * i );


break;

case 2: //画红马


g.drawString("马",empty + chessMapGridsOfWidthLength * j,empty + chessMapGridsOfHeight * i,Graphics.TOP|Graphics.LEFT);

//System.out.println( empty + chessMapGridsOfWidthLength * i );

break;

case 3:

g.drawString("相",empty + chessMapGridsOfWidthLength * j,empty + chessMapGridsOfHeight * i,Graphics.TOP|Graphics.LEFT);

//System.out.println( empty + chessMapGridsOfWidthLength * i );


break;


case 4:

g.drawString("仕",empty + chessMapGridsOfWidthLength * j,empty + chessMapGridsOfHeight * i,Graphics.TOP|Graphics.LEFT);

//System.out.println( empty + chessMapGridsOfWidthLength * i );


break;
case 5:

g.drawString("帅",empty + chessMapGridsOfWidthLength * j,empty + chessMapGridsOfHeight * i,Graphics.TOP|Graphics.LEFT);

//System.out.println( empty + chessMapGridsOfWidthLength * i );


break;


case 6:

g.drawString("帅",100,100,Graphics.TOP|Graphics.LEFT);

//System.out.println( empty + chessMapGridsOfWidthLength * i );


break;


case 7:

g.drawString("兵",empty + chessMapGridsOfWidthLength * j,empty + chessMapGridsOfHeight * i,Graphics.TOP|Graphics.LEFT);

//System.out.println( empty + chessMapGridsOfWidthLength * i );


break;
case 8:

g.drawString("车",empty + chessMapGridsOfWidthLength * j,empty + chessMapGridsOfHeight * i,Graphics.TOP|Graphics.LEFT);

//System.out.println( empty + chessMapGridsOfWidthLength * i );


break;
case 9:

g.drawString("马",empty + chessMapGridsOfWidthLength * j,empty + chessMapGridsOfHeight * i,Graphics.TOP|Graphics.LEFT);

//System.out.println( empty + chessMapGridsOfWidthLength * i );


break;
case 10:

g.drawString("象",empty + chessMapGridsOfWidthLength * j,empty + chessMapGridsOfHeight * i,Graphics.TOP|Graphics.LEFT);

//System.out.println( empty + chessMapGridsOfWidthLength * i );


break;
case 11:

g.drawString("士",empty + chessMapGridsOfWidthLength * j,empty + chessMapGridsOfHeight * i,Graphics.TOP|Graphics.LEFT);

//System.out.println( empty + chessMapGridsOfWidthLength * i );


break;
case 12:

g.drawString("将",empty + chessMapGridsOfWidthLength * j,empty + chessMapGridsOfHeight * i,Graphics.TOP|Graphics.LEFT);

//System.out.println( empty + chessMapGridsOfWidthLength * i );


break; case 13:

g.drawString("炮",empty + chessMapGridsOfWidthLength * j,empty + chessMapGridsOfHeight * i,Graphics.TOP|Graphics.LEFT);

//System.out.println( empty + chessMapGridsOfWidthLength * i );


break; case 14:

g.drawString("卒",empty + chessMapGridsOfWidthLength * j,empty + chessMapGridsOfHeight * i,Graphics.TOP|Graphics.LEFT);

//System.out.println( empty + chessMapGridsOfWidthLength * i );


break;





}


}


问题出来了,第一行的棋子都绘出了,可是其他的棋子比如炮哦,兵啊就出不来了,极度郁闷中啊,谁来救我啊
...全文
177 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
efei 2005-04-11
  • 打赏
  • 举报
回复
楼主应该调试一下呀

后面的都没有执行,一调试就出来了

单步就是强,呵呵
thb28 2005-04-11
  • 打赏
  • 举报
回复
楼上的
太谢谢了
以前写for( int i =0; i < = 9;i ++)
这种形式写惯了,所以以下子没有注意到,
太谢谢了啊
jFresH_MaN 2005-04-11
  • 打赏
  • 举报
回复
上面错了
应该是
for( ;i < 10; i++) {
for( ; j < 9 ;j++) {
switch ...... {
}
}
这里要把j=0;不然下面循环就不执行了

}
jFresH_MaN 2005-04-11
  • 打赏
  • 举报
回复
for( ;i < 10; i++)
for( ; j < 9 ;j++) {
switch ...... {
}
这里要把j=0;不然下面循环就不执行了

}
thb28 2005-04-11
  • 打赏
  • 举报
回复
难道没有人吗
thb28 2005-04-11
  • 打赏
  • 举报
回复
问题不在这里啊
DreamDragon_NEU 2005-04-11
  • 打赏
  • 举报
回复
case 5 和case 6重复了~~~

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧