if (x == null_x && Math.abs(y - null_y) == 1) {
return true;
} else if (y == null_y && Math.abs(x - null_x) == 1) {
return true;
}
用絕對值的方法感覺更方便
return true;
} else if (y == null_y && Math.abs(x - null_x) == 1) {
return true;
}
用絕對值的方法感覺更方便
2016-10-05
講師回答 / 阿旭_
把代碼貼上來吧,我寫這個代碼故意把代碼都寫在了一個MainActivity里,所以你粘過來我看一眼就知道了。猜測是少一行交換點(diǎn)擊位置與空方塊的代碼
2016-09-07
如果把一下兩行調(diào)轉(zhuǎn)一下,豈不妙哉
/**
* 設(shè)置最后一個方塊為空的數(shù)據(jù)
*/
setNullImageView(iv_game_arr[2][4]);
/**
* 隨機(jī)打亂順序
*/
randomMove();
/**
* 設(shè)置最后一個方塊為空的數(shù)據(jù)
*/
setNullImageView(iv_game_arr[2][4]);
/**
* 隨機(jī)打亂順序
*/
randomMove();
2016-08-19
/**
* 手勢的判斷
*
* @param sx
* @param sy
* @param ex
* @param ey
* @return 上下左右 1 2 3 4
*/
public int getDirByGes(float sx, float sy, float ex, float ey) {
// 左右:橫向距離大于豎直距離
// 左 :終點(diǎn)x小于起點(diǎn)x
// 安卓y正軸方向為豎直向下
// 上:終點(diǎn)y小于起點(diǎn)y
return Math.abs(sx-ex)<Math.abs(sy-ey)?(sy>ey?1:2):(sx>ex?3:4);
}
* 手勢的判斷
*
* @param sx
* @param sy
* @param ex
* @param ey
* @return 上下左右 1 2 3 4
*/
public int getDirByGes(float sx, float sy, float ex, float ey) {
// 左右:橫向距離大于豎直距離
// 左 :終點(diǎn)x小于起點(diǎn)x
// 安卓y正軸方向為豎直向下
// 上:終點(diǎn)y小于起點(diǎn)y
return Math.abs(sx-ex)<Math.abs(sy-ey)?(sy>ey?1:2):(sx>ex?3:4);
}
2016-08-19
講師回答 / 阿旭_
如果要是按自己的邏輯實現(xiàn)起來總是錯的,不知道正確的方法。那么可以把a(bǔ)ctivity這個類的代碼都發(fā)過來,我結(jié)果上下文看看是不是其它地方寫錯了
2016-08-19
已采納回答 / 阿旭_
我這邊按照我的邏輯應(yīng)該是沒講錯,因為最終結(jié)果是對的啊。建議以實際運(yùn)行效果為準(zhǔn)。方法不唯一,只要清算自己寫的x, y分別代表什么用自己的邏輯實現(xiàn)就好,
2016-08-18