如何检查拼图是否完成?

How to check whether the jigsaw puzzle is completed or not?(如何检查拼图是否完成?)

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

问题描述

我正在准备一个像拼图这样的小游戏,为此我在布局中使用了 9 个图像视图和 9 个不同的图像.在启动时将图像设置为 imageview 那些是实际图像,在随机播放用户将滑动图像以完成拼图后,我想用实际图像检查修改后的图像,如果它们相等,则天气是否相等弹出一条消息,比如游戏结束.

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.

我试过这样

1.通过在图像(Drawables)之间使用AND运算符但不走运.

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

2.对图像使用 setLevel(),将这些 setLevel 值与滑动后图像的 getLevel 值进行比较 仍然不幸..这里的问题是,如果我点击 imageview 一次 getLevel() 给出正确的值,如果我点击更多而不是一次它给出零值.为什么会这样..

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  

在这样的java代码中如果用户点击 imageview 它将交换图像的

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. 维护一组新的可绘制对象,将它们标记为您最初拥有的原始可绘制对象.可能像

可绘制 og11 = imageView11.getDrawable();在洗牌之前做这部分.现在你有了原始的drawable,以drawable的形式存储.

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

  1. 每次点击后,检查 og11 == imageView11.getDrawable(),... 是否对拼图中的所有图像进行检查,如果匹配,则匹配,否则不匹配.

HTH.

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

本文标题为:如何检查拼图是否完成?

基础教程推荐