郁闷死了,见到鬼了,这么简单的问题,怎么会,无语中。。。。。。。。。。
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;
}
}
问题出来了,第一行的棋子都绘出了,可是其他的棋子比如炮哦,兵啊就出不来了,极度郁闷中啊,谁来救我啊