如何检查拼图是否完成没有? [英] How to check whether the jigsaw puzzle is completed or not?

查看:106
本文介绍了如何检查拼图是否完成没有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是preparing一个小小的游戏,如拼图,对,我现在用9的ImageView与布局中的9种不同的图像。设置图像的ImageView在启动这些都是实际图像的时间,经过洗牌的用户会做滑动图像来完成拼图,我想检查与实际图像的修改后的图像,天气是等于或不如果这些都是平等的弹出消息,像GAMEOVER。

我想这样

1.by图像(可绘),但与使用AND运算符不吉利的。

2,使用执行setLevel()的图像,滑动还是不幸后的比较与getLevel值图像的执行setLevel值..这里的问题是,如果我点击ImageView的一次getLevel()给出正确的值,如果我点击更多不止一次它赋予零值。为什么会发生这样的..

请帮助我,如果你发现我的code任何差错,否则引导我有良好的技术。

  XML code这样的
< RelativeLayout的
   // 9的ImageView
 

在java的code这样的 如果用户点击的ImageView就会掉图像的

  img_View11.setOnClickListener(新View.OnClickListener(){
    公共无效的onClick(视图v){

        如果(img_View21.getDrawable()== default_img ||
                                    img_View12.getDrawable()== default_img){

            的System.out.println(是);
            ++点击;
            Noof_moves.setText(移动+点击)
            ImageView的IV =(ImageView的)V;
            D11 = iv.getDrawable();
            prev_img = prev_imgView.getDrawable();

            LA11 = d11.getLevel();
            的System.out.println(D11值是+ LA11);

            prev_imgView.setImageDrawable(D11);

            img_View11.setImageDrawable(prev_img);
            prev_imgView = img_View11;

            检查();
            }
        其他{的System.out.println(无); }
        }
    });

空白支票(){

    的System.out.println(在检查条件);
    如果((LB11 == LA11)及及(LB12 == LA12)及及(lb13 == LA13)及及(LB21 == LA21)及及(lb22 == LA22)
        &功放;&安培; (lb23 == LA23)及&安培; (lb31 == LA31)及&安培; (lb32 == LA32)及&安培; (LB33 == LA33)){
            上下文C = getBaseContext();
            的System.out.println(GAMEOVER);
            Toast.makeText(C,GAMEOVER,Toast.LENGTH_SHORT).show();
    }其他{的System.out.println(codition未选中); }
}
//这里磅=前水平滑动
滑坡后// LA =水平..
 

解决方案

好吧,这里是你做的解决方案。

  1. 在保持一组新的可绘制其标记为你最初曾原可绘制的。 可能会像

绘制og11 = imageView11.getDrawable(); 洗牌之前做到这一点的一部分。现在你有原来的可绘,存储在可绘制的形式。

  1. 在每一次点击,检查是否og11 == imageView11.getDrawable(),...等等在拼图的所有图像,如果匹配,它匹配,否则,他们不知道。

HTH。

i am preparing one small game like jigsaw , for that i am using 9 imageview's with 9 different images in the layout. set the images to imageview at the time of starting those are actual images, after shuffle user will do sliding the images to complete puzzle, i want to check the modified image with actual image's, weather it's equal or not if those are equal popup a message, like gameover.

i tried like this

1.by using AND operator between the images(Drawables) but unlucky.

2.Using setLevel() for the images, compare those setLevel values with getLevel values for images after sliding still Unlucky.. here the problem is if i click on imageview one time getLevel() gives correct value, if i click more than once it gives zero value. Why it happens like this..

Please help me if you find any mistake in my code, otherwise guide me with good technique..

Xml code like this
<RelativeLayout
   //9 imageview's  

in jave code like this if user will click on imageview it will swap the image's

 img_View11.setOnClickListener(new View.OnClickListener()  {            
    public void onClick(View v)  { 

        if(img_View21.getDrawable() == default_img || 
                                    img_View12.getDrawable() == default_img) {

            System.out.println("yes");
            ++click;
            Noof_moves.setText("Moves: " +click);
            ImageView iv = (ImageView)v;                 
            d11 = iv.getDrawable();   
            prev_img = prev_imgView.getDrawable();

            la11 = d11.getLevel();
            System.out.println("d11 value is " +la11);                  

            prev_imgView.setImageDrawable(d11);                 

            img_View11.setImageDrawable(prev_img);                
            prev_imgView = img_View11;

            check();
            }
        else { System.out.println("no");  }
        }
    });

void check(){

    System.out.println("in checking condition");
    if((lb11==la11) && (lb12==la12) && (lb13==la13) && (lb21==la21) && (lb22==la22)
        && (lb23==la23) && (lb31==la31) && (lb32==la32) && (lb33==la33)) {
            Context c = getBaseContext();
            System.out.println("gameover");
            Toast.makeText(c, " GameOver ", Toast.LENGTH_SHORT).show();
    }else{ System.out.println(" codition not checked "); }
} 
//here lb=level before sliding
//     la=level after sliding..

解决方案

Ok, here is what you do for the solution.

  1. maintain a new set of drawables marking them as original drawables that you had initially. may be like

drawable og11 = imageView11.getDrawable(); do this part before shuffling. now you have original drawables, stored in the form of drawables.

  1. After every click , check if og11 == imageView11.getDrawable(),... and so on for all the images in the jigsaw, if they match , it matches, else, they don't.

HTH.

这篇关于如何检查拼图是否完成没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆