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

熱點內容
塞巴斯蒂安電影1976資源 瀏覽:28
解壓是不是要軟體 瀏覽:103
壓縮空氣儲氣罐材質 瀏覽:141
程序員的設備有哪些 瀏覽:614
龍貓電影免費觀看普通話 瀏覽:253
pubg體驗服為什麼伺服器爆滿 瀏覽:62
鈑金編程排版哪裡有視頻可以參考 瀏覽:32
文件夾用於干什麼 瀏覽:510
如色房加密路線 瀏覽:42
阿帕奇web伺服器干什麼用 瀏覽:14
豆豆的書在哪個app可以看 瀏覽:431
基本的編程思想 瀏覽:979
app慕課在哪裡綁定微信 瀏覽:183
加密貨幣央行最新消息 瀏覽:974
伺服器L12是什麼意思 瀏覽:405
關於大海的英語電影 瀏覽:564
日本推理電影榜 瀏覽:571
快手上的影視小短片哪裡找的 瀏覽:59
大香蕉人在線觀看1 瀏覽:922
android獲得根目錄 瀏覽:95