導航:首頁 > 編程語言 > 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跳棋相關的資料

熱點內容
php教材下載 瀏覽:906
什麼解壓密碼最好 瀏覽:582
資料庫與伺服器如何連接 瀏覽:436
架構師需要閱讀的源碼 瀏覽:475
ch編譯器 瀏覽:448
java必須自己寫一個編譯器嗎 瀏覽:936
如何製作androidrom 瀏覽:468
單片機萬能板怎麼寫入程序 瀏覽:19
邁銳寶xl壓縮比 瀏覽:340
靠演算法買彩票 瀏覽:497
程序員考核d 瀏覽:239
自助游中國pdf 瀏覽:746
安卓p40是什麼手機 瀏覽:87
24cxx編程器 瀏覽:591
陰陽師如何查看哪個伺服器有ID 瀏覽:316
公務員照片壓縮 瀏覽:458
編譯的時候怎麼找未定義的函數 瀏覽:352
有什麼我的世界伺服器 瀏覽:306
伺服器亮綠燈是什麼意思 瀏覽:637
python畫的圖如何保存高清版 瀏覽:499