第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

正在回答

2 回答

抱歉,慕課不許我發(fā)源碼,你可以看看其它同學(xué)做的。

zzlandroid

照著老師的教程敲的一個(gè)樣例:https://github.com/kiritozzl/PuzzleGame

王正一

我實(shí)現(xiàn)的項(xiàng)目源碼:https://github.com/wangzhengyi/HYPinTu

慕粉3288933

我寫(xiě)了代碼,地址在https://github.com/jowang2016/pintumooc 但是判斷程序結(jié)束那里總是沒(méi)有提示


1 回復(fù) 有任何疑惑可以回復(fù)我~

public class MainActivity extends Activity {
? ?private boolean isAnimRun = false;
? ?//判斷游戲是否開(kāi)始
? ?private boolean isGameStart = false;
? ?private ImageView [] [] iv_game_arr = new ImageView[3][5];
? ?private GridLayout gl_main_game;
? ?private ImageView iv_null_ImageView;
? ?private GestureDetector mDetector;

? ?@Override
? ?public boolean onTouchEvent(MotionEvent event) {
? ? ? ?return mDetector.onTouchEvent(event);
? ?}

? ?@Override
? ?public boolean dispatchTouchEvent(MotionEvent ev) {
? ? ? ?mDetector.onTouchEvent(ev);

? ? ? ?return super.dispatchTouchEvent(ev);
? ?}

? ?@Override
? ?protected void onCreate(Bundle savedInstanceState) {
? ? ? ?super.onCreate(savedInstanceState);
? ? ? ?setContentView(R.layout.activity_main);
? ? ? ?mDetector = new GestureDetector(this, new GestureDetector.OnGestureListener() {
? ? ? ? ? ?@Override
? ? ? ? ? ?public boolean onDown(MotionEvent motionEvent) {
? ? ? ? ? ? ? ?return false;
? ? ? ? ? ?}

? ? ? ? ? ?@Override
? ? ? ? ? ?public void onShowPress(MotionEvent motionEvent) {

? ? ? ? ? ?}

? ? ? ? ? ?@Override
? ? ? ? ? ?public boolean onSingleTapUp(MotionEvent motionEvent) {
? ? ? ? ? ? ? ?return false;
? ? ? ? ? ?}

? ? ? ? ? ?@Override
? ? ? ? ? ?public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
? ? ? ? ? ? ? ?return false;
? ? ? ? ? ?}

? ? ? ? ? ?@Override
? ? ? ? ? ?public void onLongPress(MotionEvent motionEvent) {

? ? ? ? ? ?}

? ? ? ? ? ?@Override
? ? ? ? ? ?public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
? ? ? ? ? ? ? ?int type = getDirByGes(motionEvent.getX(),motionEvent.getY(),motionEvent1.getX(),motionEvent1.getY());
// ? ? ? ? ? ? ? ?Toast.makeText(MainActivity.this,""+type,Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ?changeByDir(type);
? ? ? ? ? ? ? ?return false;
? ? ? ? ? ?}
? ? ? ?});
? ? ? ?Bitmap bigBm = ((BitmapDrawable) getResources().getDrawable(R.drawable.ic_game_tu)).getBitmap();
? ? ? ?int tuWandH = bigBm.getWidth()/5;
? ? ? ?int ivWandH = getWindowManager().getDefaultDisplay().getWidth()/5;
? ? ? ?for (int i=0;i<iv_game_arr.length;i++){
? ? ? ? ? ?for(int j=0;j<iv_game_arr[0].length;j++){
? ? ? ? ? ? ? ?Bitmap bm = Bitmap.createBitmap(bigBm,j*tuWandH,i*tuWandH,tuWandH,tuWandH);
? ? ? ? ? ? ? ?iv_game_arr[i][j]=new ImageView(this);
? ? ? ? ? ? ? ?iv_game_arr[i][j].setImageBitmap(bm);
? ? ? ? ? ? ? ?iv_game_arr[i][j].setLayoutParams(new RelativeLayout.LayoutParams(ivWandH,ivWandH));
? ? ? ? ? ? ? ?iv_game_arr[i][j].setPadding(2,2,2,2);
? ? ? ? ? ? ? ?iv_game_arr[i][j].setTag(new GameData(i,j,bm));
? ? ? ? ? ? ? ?iv_game_arr[i][j].setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? ? ? ? ?@Override
? ? ? ? ? ? ? ? ? ?public void onClick(View v) {
? ? ? ? ? ? ? ? ? ? ? ?boolean flag = isHasByNullImageView((ImageView)v);
? ? ? ? ? ? ? ? ? ? ? ?//Toast.makeText(MainActivity.this,"位置關(guān)系是否存在:"+flag,Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? ? ? ? ?if(flag){
? ? ? ? ? ? ? ? ? ? ? ? ? ?changeDataByImageView((ImageView) v);
? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?});
? ? ? ? ? ?}
? ? ? ?}
? ? ? ?gl_main_game = (GridLayout) findViewById(R.id.gl_main_game);
? ? ? ?for(int i=0;i<iv_game_arr.length;i++){
? ? ? ? ? ?for(int j=0;j<iv_game_arr[0].length;j++){
? ? ? ? ? ? ? ?gl_main_game.addView(iv_game_arr[i][j]);
? ? ? ? ? ?}
? ? ? ?}
? ? ? ?//設(shè)置最后一個(gè)方塊為空
? ? ? ?setNullImageView(iv_game_arr[2][4]);
? ? ? ?//隨機(jī)打亂順序
? ? ? ?randomMove();
? ? ? ?isGameStart = true;
? ?}

? ?//隨機(jī)打亂順序
? ?public void randomMove(){
? ? ? ?for(int i=0;i<100;i++){
? ? ? ? ? ?int type = (int) ((Math.random()*4)+1);
? ? ? ? ? ?changeByDir(type,false);
? ? ? ?}
? ?}
? ?public void changeByDir(int type){
? ? ? ? changeByDir(type,true);
? ?}

? ?public void changeByDir(int type ,boolean isAnim){
? ? ? ?GameData mNullGameData = (GameData) iv_null_ImageView.getTag();
? ? ? ?int new_x = mNullGameData.x;
? ? ? ?int new_y = mNullGameData.y;
? ? ? ?if(type == 1){
? ? ? ? ? ?new_x++;
? ? ? ?}else if(type == 2){
? ? ? ? ? ?new_x--;
? ? ? ?}else if(type == 3){
? ? ? ? ? ?new_y++;
? ? ? ?}else if(type == 4){
? ? ? ? ? ?new_y--;
? ? ? ?}
? ? ? ?if(new_x>=0&&new_x<iv_game_arr.length&&new_y>=0&&new_y<iv_game_arr[0].length){
? ? ? ? ? ?if(isAnim){
? ? ? ? ? ? ? ?changeDataByImageView(iv_game_arr[new_x][new_y]);
? ? ? ? ? ?}else {
? ? ? ? ? ? ? ?changeDataByImageView(iv_game_arr[new_x][new_y],isAnim);
? ? ? ? ? ?}
? ? ? ?}else {

? ? ? ?}
? ?}
? ?//判斷結(jié)束的方法
? ?public void isGameOver(){
? ? ? ?boolean isGameOver = true;
? ? ? ?for(int i=0;i<iv_game_arr.length;i++){
? ? ? ? ? ?for(int j=0;j<iv_game_arr[0].length;j++){
? ? ? ? ? ? ? ?if(iv_game_arr[i][j]==iv_null_ImageView){
? ? ? ? ? ? ? ? ? ?continue;
? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?GameData mGameData = (GameData) iv_game_arr[i][j].getTag();
? ? ? ? ? ? ? ?if(!mGameData.isTrue()){
? ? ? ? ? ? ? ? ? ?isGameOver = false;
? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ?}
? ? ? ? ? ?}

? ? ? ? ? ?}
? ? ? ?if(isGameOver){
? ? ? ? ? ?Toast.makeText(MainActivity.this,"游戲結(jié)束",Toast.LENGTH_SHORT).show();
? ? ? ?}
? ?}
? ?public int getDirByGes(float start_x, float start_y, float end_x, float end_y){
? ? ? ?boolean isLeftOrRight = (Math.abs(start_x-end_x)>Math.abs(start_y-end_y))?true:false;
? ? ? ?if(isLeftOrRight){
? ? ? ? ? ?boolean isLeft = start_x-end_x>0?true:false;
? ? ? ? ? ?if(isLeft){
? ? ? ? ? ? ? ?return 3;
? ? ? ? ? ?}else {
? ? ? ? ? ? ? ?return 4;
? ? ? ? ? ?}
? ? ? ?}else {
? ? ? ? ? ?boolean isUp = start_y-end_y>0?true:false;
? ? ? ? ? ?if(isUp){
? ? ? ? ? ? ? ?return 1;
? ? ? ? ? ?}else {
? ? ? ? ? ? ? ?return 2;
? ? ? ? ? ?}
? ? ? ?}
? ?}

? ?public void setNullImageView(ImageView mImageView){
? ? ? ?mImageView.setImageBitmap(null);
? ? ? ?iv_null_ImageView = mImageView;
? ?}

? ?public void changeDataByImageView(final ImageView mImageView){
? ? ? ?changeDataByImageView(mImageView,true);
? ?}

? ?public void changeDataByImageView(final ImageView mImageView, boolean isAnim){
? ? ? ?if(isAnimRun){
? ? ? ? ? ?return;
? ? ? ?}
? ? ? ?if(!isAnim){
? ? ? ? ? ?GameData mGameData = (GameData) mImageView.getTag();
? ? ? ? ? ?iv_null_ImageView.setImageBitmap(mGameData.bm);
? ? ? ? ? ?GameData mNullGameData = (GameData) iv_null_ImageView.getTag();
? ? ? ? ? ?mNullGameData.bm = mGameData.bm;
? ? ? ? ? ?mNullGameData.p_x = mGameData.p_x;
? ? ? ? ? ?mNullGameData.p_y = mGameData.p_y;
? ? ? ? ? ?setNullImageView(mImageView);//設(shè)置當(dāng)前點(diǎn)擊的是空方塊
? ? ? ? ? ?if(isGameStart){
? ? ? ? ? ? ? ?//成功時(shí),彈出Toast
? ? ? ? ? ? ? ?isGameOver();
? ? ? ? ? ?}
? ? ? ? ? ?return;
? ? ? ?}
? ? ? ?TranslateAnimation translateAnimation = null;
? ? ? ?if(mImageView.getX()>iv_null_ImageView.getX()){
? ? ? ? ? ?translateAnimation = new TranslateAnimation(0.1f,-mImageView.getWidth(),0.1f,0.1f);
? ? ? ?}else if(mImageView.getX()<iv_null_ImageView.getX()){
? ? ? ? ? ?translateAnimation = new TranslateAnimation(0.1f,mImageView.getWidth(),0.1f,0.1f);
? ? ? ?}else if(mImageView.getY()>iv_null_ImageView.getY()){
? ? ? ? ? ?translateAnimation = new TranslateAnimation(0.1f,0.1f,0.1f,-mImageView.getWidth());
? ? ? ?}else if(mImageView.getY()<iv_null_ImageView.getY()){
? ? ? ? ? ?translateAnimation = new TranslateAnimation(0.1f,0.1f,0.1f,mImageView.getWidth());
? ? ? ?}
? ? ? ?//設(shè)置動(dòng)畫(huà)時(shí)長(zhǎng)
? ? ? ?translateAnimation.setDuration(70);
? ? ? ?//結(jié)束設(shè)置后是否停留
? ? ? ?translateAnimation.setFillAfter(true);
? ? ? ?translateAnimation.setAnimationListener(new Animation.AnimationListener() {
? ? ? ? ? ?@Override
? ? ? ? ? ?public void onAnimationStart(Animation animation) {
? ? ? ? ? ? ? ?isAnimRun = true;
? ? ? ? ? ?}

? ? ? ? ? ?@Override
? ? ? ? ? ?public void onAnimationEnd(Animation animation) {
? ? ? ? ? ? ? ?isAnimRun = false;
? ? ? ? ? ? ? ?mImageView.clearAnimation();
? ? ? ? ? ? ? ?GameData mGameData = (GameData) mImageView.getTag();
? ? ? ? ? ? ? ?iv_null_ImageView.setImageBitmap(mGameData.bm);
? ? ? ? ? ? ? ?GameData mNullGameData = (GameData) iv_null_ImageView.getTag();
? ? ? ? ? ? ? ?mNullGameData.bm = mGameData.bm;
? ? ? ? ? ? ? ?mNullGameData.p_x = mGameData.p_x;
? ? ? ? ? ? ? ?mNullGameData.p_y = mGameData.p_y;
? ? ? ? ? ? ? ?setNullImageView(mImageView);//設(shè)置當(dāng)前點(diǎn)擊的是空方塊
? ? ? ? ? ? ? ?if(isGameStart){
? ? ? ? ? ? ? ? ? ?//成功時(shí),彈出Toast
? ? ? ? ? ? ? ? ? ?isGameOver();
? ? ? ? ? ? ? ?}
? ? ? ? ? ?}

? ? ? ? ? ?@Override
? ? ? ? ? ?public void onAnimationRepeat(Animation animation) {

? ? ? ? ? ?}
? ? ? ?});
? ? ? ?//執(zhí)行動(dòng)畫(huà)
? ? ? ?mImageView.startAnimation(translateAnimation);
? ?}

? ?public boolean isHasByNullImageView(ImageView mImageView){
? ? ? ?GameData mNullGameData = (GameData) iv_null_ImageView.getTag();
? ? ? ?GameData mGameData = (GameData) mImageView.getTag();
? ? ? ?if(mNullGameData.y==mGameData.y && mGameData.x+1==mNullGameData.x){
? ? ? ? ? ?return true;
? ? ? ?}else if(mNullGameData.y==mGameData.y && mGameData.x-1==mNullGameData.x){
? ? ? ? ? ?return true;
? ? ? ?}else if(mNullGameData.y==mGameData.y+1 && mGameData.x==mNullGameData.x){
? ? ? ? ? ?return true;
? ? ? ?}else if(mNullGameData.y==mGameData.y-1 && mGameData.x==mNullGameData.x){
? ? ? ? ? ?return true;
? ? ? ?}
? ? ? ?return false;
? ?}
? ?class GameData{
? ? ? ?public int x = 0;
? ? ? ?public int y = 0;
? ? ? ?public Bitmap bm;
? ? ? ?public int p_x = 0;
? ? ? ?public int p_y = 0;

? ? ? ?public GameData(int x, int y, Bitmap bm) {
? ? ? ? ? ?super();
? ? ? ? ? ?this.x = x;
? ? ? ? ? ?this.y = y;
? ? ? ? ? ?this.bm = bm;
? ? ? ? ? ?this.p_x = x;
? ? ? ? ? ?this.p_y = y;
? ? ? ?}
? ? ? ?//判斷游戲是否結(jié)束的方法
? ? ? ?public boolean isTrue() {
? ? ? ? ? ?if(x==p_x&&y==p_y){
? ? ? ? ? ? ? ?return true;
? ? ? ? ? ?}
? ? ? ? ? ?return false;
? ? ? ?}
? ?}

}

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

daniel661839@163.com 能發(fā)我一份嗎?

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)