導航:首頁 > 編程語言 > java跳棋

java跳棋

發布時間:2023-12-02 19:07:41

Ⅰ 僅用c語言能編出哪些小游戲

可以編寫狼追兔子游戲,擲骰子游戲,24點游戲,井字棋游戲,農夫過河游戲,掃雷小游戲,人機猜數游戲,三色球游戲, 推箱子游戲,坦克大戰游戲,貪吃蛇游戲等。

Ⅱ Java 跳棋的程序 急~~

先導入三個按鈕圖片
正常顯示的圖片"Begin1.jpg"
滑鼠移動到按鈕上時顯示的圖片"Begin2.jpg"
按下滑鼠時顯示的圖片"Begin1.jpg"
final ImageLoader imageBegin1 = new ImageLoader(sShell.getDisplay(), "Begin1.jpg");
final ImageLoader imageBegin2 = new ImageLoader(sShell.getDisplay(), "Begin2.jpg");
final ImageLoader imageBegin3 = new ImageLoader(sShell.getDisplay(),"Begin1.jpg");
創建按鈕
lblBegin = new Label(parent, SWT.NO_BACKGROUND);
lblBegin.setImage(imageBegin1.getImage());
lblBegin.setBounds(70, 40, 75, 38);
為按鈕各事件寫入代碼
lblBegin.addMouseTrackListener(new MouseTrackAdapter() {
public void mouseEnter(MouseEvent e) { //滑鼠移動到按鈕上方
lblBegin.setImage(imageBegin2.getImage());
}
public void mouseExit(MouseEvent e) { //滑鼠從按鈕上方移開
lblBegin.setImage(imageBegin1.getImage());
}
});
lblBegin.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
if (e.button == 1) {//按下滑鼠左鍵
lblBegin.setImage(imageBegin3.getImage()); //在這里寫入單擊事件代碼
}
}
public void mouseUp(MouseEvent e) {
if (e.button == 1) {//釋放滑鼠左鍵
lblBegin.setImage(imageBegin2.getImage());

}
}

});

如圖所示,當X坐標為1時,Y的坐標只能為5,當X坐標為2時,Y的坐標可以5或6。於是我們建立一個數組:
final static private int[][] pos = {
{5,5}, //X坐標為1,Y的上限是5,下限是5
{5,6}, //X坐標為2,Y的上限是5,下限是6
{5,7}, //X坐標為3,Y的上限是5,下限是7
{5,8}, //X坐標為4,Y的上限是5,下限是8
{1,13}, //X坐標為5,Y的上限是1,下限是13
{2,13}, //6
{3,13}, //7
{4,13}, //8
{5,13}, //9
{5,14}, //10
{5,15}, //11
{5,16}, //12
{5,17}, //13
{10,13}, //14
{11,13}, //15
{12,13}, //16
{13,13}, //17
};
在Position類中IsLegalPosition函數可以確定一個坐標是否合法
public static boolean IsLegalPosition(int x, int y) {
if ((x < 1) || (x > 17)) {
return false;
}
if ((y < pos[x - 1][0]) || (y > pos[x - 1][1])) {
return false;
}
return true;
}

3. 棋盤類(ChessBoard)中棋子和坐標的索引關系
棋盤中所有Chess集合
private Chess[] chesses = null;//所有棋子對象都保存這個數組當中
下面函數可以根據索引號返回棋子對象
public Chess getChess(int index) {
return chesses[index];
}
棋子和坐標的對應關系
private Position[] chessesPosition = null;//所有棋子坐標都保存在這個數組當中
下面函數可以根據棋子對象或棋子索引號返回坐標
public Position getPosition(Chess chess) {
return chessesPosition[chess.getindex()];
}

public Position getPosition(int index) {
return chessesPosition[index];
}
坐標和棋子的對應關系
private Chess[][] chessesIndex = new Chess[17][17];//數組保存了17*17個棋子對象指針
下面函數可以根據棋子坐標返回該位置上的棋子,如果沒有棋子返回Null
public Chess getChess(Position position) {
if (position == null){
return null;
}
return chessesIndex[position.getx() - 1][position.gety() - 1];
}

閱讀全文

與java跳棋相關的資料

熱點內容
磁力計校正演算法 瀏覽:491
解壓縮後變小了 瀏覽:957
智友文件夾 瀏覽:81
android操作系統開發的操作系統 瀏覽:478
原神手機怎麼改b站伺服器 瀏覽:296
樁基箍筋加密區高度規范 瀏覽:91
手機櫻花動漫app怎麼用 瀏覽:382
php科學計數法轉換 瀏覽:642
sip認證演算法 瀏覽:785
androidapp卡頓原因 瀏覽:905
25編程器電路 瀏覽:849
安卓九是什麼東西 瀏覽:939
隱藏nodejs命令行窗口 瀏覽:62
人體與寫生素描pdf 瀏覽:883
java集合性能 瀏覽:143
單片機三線通信 瀏覽:209
崑山ug編程培訓學費 瀏覽:628
黃色app怎麼盈利的 瀏覽:957
怎麼修改linux密碼 瀏覽:703
國家發展中心app長什麼樣子 瀏覽:243