记忆游戏卡翻转问题

时间:2015-08-10 19:54:59

标签: java android eclipse handler

我正在开发一款简单的记忆游戏,你基本上匹配相同的牌。如果两者都不匹配,我希望这些卡能够翻转。翻页代码如下:

 mT1.unselect();
 mT2.unselect();

当我把它放在else语句中时,卡片会立即翻转,所以我使用了一个处理程序来减慢它的速度。

Handler handler = new Handler(); 
                handler.postDelayed(new Runnable() { 
                     public void run() { 
                         mT1.unselect();
                         mT2.unselect();
                         playSound( SOUND_FAILED );
                     } 
                }, 2000); 

但是当我测试时它没有翻转,但声音在给定时间后播放。问题是什么?

完整代码:

   public void onPosition(int position)
{
    if (position == mLastPosition)
    {

        return;
    }
    mLastPosition = position;
    Tile tile = mList.get(position);
    tile.select();
    int sound = tile.mResId % mSounds.length;
    playSound(sound);

    switch (mSelectedCount)
    {
        case 0:
            mT1 = tile;
            break;

        case 1:
            mT2 = tile;
            if (mT1.getResId() == mT2.getResId())
            {
                mT1.setFound(true);
                mT2.setFound(true);
                mFoundCount += 2;
                playSound(SOUND_SUCCEED);
            }
            else
            {

                Handler handler = new Handler(); 
                handler.postDelayed(new Runnable() { 
                     public void run() { 
                         mT1.unselect();
                         mT2.unselect();
                         playSound( SOUND_FAILED );
                     } 
                }, 2000); 

            }
            break;

        case 2:
            if (mT1.getResId() != mT2.getResId())
            {

            }
            mSelectedCount = 0;
            mT1 = tile;
            break;
    }
    mSelectedCount++;
    mMoveCount++;
    updateView();
    checkComplete();
}

1 个答案:

答案 0 :(得分:1)

与上一个问题一样,你还没有给我们足够的背景,但我会在黑暗中狂奔 - 也许你需要打电话:

updateView();

在您Runnable的{​​{1}}方法中。

也许如果您发布run()方法以及更多有关其工作方式的背景信息,如果此猜测无法修复,我们可能会提供更多帮助。

相关问题