本文介绍了河内流行QUOT Android的AndEngine塔;游戏超过QUOT;当环达到3塔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我无法成功输出游戏结束!当环达到3塔。我可以问你的意见如何做到这一点?

我秉承,这不包括游戏结束的呢,我发现很难添加一个,因为我是新来的Andr​​oid编程。

 私人无效checkForCollisionsWithTowers(铃铃){
    堆叠式和LT;环>堆栈=无效;
    雪碧塔= NULL;    如果(ring.collidesWith(mTower1)及及(mStack1.size()== 0 || ring.getmWeight()&所述; mStack1.peek()getmWeight())){
        堆栈= mStack1;
        塔= mTower1;
    }否则如果(ring.collidesWith(mTower2)及及(mStack2.size()== 0 || ring.getmWeight()&所述; mStack2.peek()getmWeight())){
        堆栈= mStack2;
        塔= mTower2;
    }否则如果(ring.collidesWith(mTower3)及及(mStack3.size()== 0 || ring.getmWeight()&所述; mStack3.peek()getmWeight())){
        堆栈= mStack3;
        塔= mTower3;    }其他{
        堆栈= ring.getmStack();
        塔= ring.getmTower();
    }    。ring.getmStack()删除(环);
    如果(堆栈= NULL&放大器;!&安培;塔= NULL&放大器;!&安培; stack.size()== 0){
        ring.setPosition(tower.getX()+ tower.getWidth()/ 2 - ring.getWidth()/ 2,tower.getY()+ tower.getHeight() - ring.getHeight());
    }否则如果(堆栈=空&放大器;!&放大器;塔=空&放大器;!&放大器; stack.size()大于0){
        ring.setPosition(tower.getX()+ tower.getWidth()/ 2 - ring.getWidth()/ 2,stack.peek()的getY() - ring.getHeight());
    }    stack.add(圈);
    ring.setmStack(栈);
    ring.setmTower(塔);
}

}


解决方案

 私人无效checkForCollisionsWithTowers(铃铃){
        堆叠式和LT;环>堆栈=无效;
        雪碧塔= NULL;
        如果(ring.collidesWith(mTower1)及及(mStack1.size()== 0 || ring.getmWeight()&所述;((环)mStack1.peek())getmWeight())){
            堆栈= mStack1;
            塔= mTower1;
        }否则如果(ring.collidesWith(mTower2)及及(mStack2.size()== 0 || ring.getmWeight()&所述;((环)mStack2.peek())getmWeight())){
            堆栈= mStack2;
            塔= mTower2;
        }否则如果(ring.collidesWith(mTower3)及及(mStack3.size()== 0 || ring.getmWeight()&所述;((环)mStack3.peek())getmWeight())){
            堆栈= mStack3;
            塔= mTower3;
        }其他{
            堆栈= ring.getmStack();
            塔= ring.getmTower();
        }
        。ring.getmStack()删除(环);
        如果(堆栈= NULL&放大器;!&安培;塔= NULL&放大器;!&安培; stack.size()== 0){
            ring.setPosition(tower.getX()+ tower.getWidth()/ 2 - ring.getWidth()/ 2,tower.getY()+ tower.getHeight() - ring.getHeight());
        }否则如果(堆栈=空&放大器;!&放大器;塔=空&放大器;!&放大器; stack.size()大于0){
            ring.setPosition(tower.getX()+ tower.getWidth()/ 2 - ring.getWidth()/ 2,((环)stack.peek())的getY() - ring.getHeight());
        }
        stack.add(圈);
        ring.setmStack(栈);
        ring.setmTower(塔);        isGameOver();
    }    私人无效isGameOver(){
        如果(mStack3.size()== 3){
             字体main_font = FontFactory.create(this.getFontManager(),this.getTextureManager(),256,256,BitmapTextureFormat.RGBA_8888,TextureOptions.BILINEAR_ preMULTIPLYALPHA,Typeface.DEFAULT,60,真实,Color.BLACK_ABGR_PACKED_INT);
             main_font.load();             文本gameOverText =新文本(0,0,main_fontGAMEOVER,this.getVertexBufferObjectManager());
             gameOverText.setPosition(CAMERA_WIDTH / 2 - gameOverText.getWidth()/ 2,CAMERA_HEIGHT / 2 - gameOverText.getHeight()/ 2);
             scene.attachChild(gameOverText);             scene.clearTouchAreas();
       }        }

I am unable to successfully output a "Game Over!" when the rings reach the 3rd tower. May I ask your opinion as to how to do this?

I followed the tutorials of "http://www.raywenderlich.com/12065/how-to-create-a-simple-android-game" which doesn't include a "Game Over" in it and I'm finding it hard to add one since I'm new to android programming.

private void checkForCollisionsWithTowers(Ring ring) {
    Stack<Ring> stack = null;
    Sprite tower = null;

    if(ring.collidesWith(mTower1) && (mStack1.size() == 0 || ring.getmWeight() < mStack1.peek().getmWeight())) {
        stack = mStack1;
        tower = mTower1;
    } else if(ring.collidesWith(mTower2) && (mStack2.size() == 0 || ring.getmWeight() < mStack2.peek().getmWeight())) {
        stack = mStack2;
        tower = mTower2;
    } else if(ring.collidesWith(mTower3) && (mStack3.size() == 0 || ring.getmWeight() < mStack3.peek().getmWeight())) {
        stack = mStack3;
        tower = mTower3;

    } else {
        stack = ring.getmStack();
        tower = ring.getmTower();
    }

    ring.getmStack().remove(ring);
    if(stack != null && tower !=null && stack.size() == 0) {
        ring.setPosition(tower.getX() + tower.getWidth()/2 - ring.getWidth()/2, tower.getY() + tower.getHeight() - ring.getHeight());
    } else if(stack != null && tower !=null && stack.size() > 0) {
        ring.setPosition(tower.getX() + tower.getWidth()/2 - ring.getWidth()/2, stack.peek().getY() - ring.getHeight());
    }

    stack.add(ring);
    ring.setmStack(stack);
    ring.setmTower(tower);
}

}

解决方案
private void checkForCollisionsWithTowers(Ring ring) {
        Stack<Ring> stack = null;
        Sprite tower = null;
        if (ring.collidesWith(mTower1) && (mStack1.size() == 0 || ring.getmWeight() < ((Ring) mStack1.peek()).getmWeight())) {
            stack = mStack1;
            tower = mTower1;
        } else if (ring.collidesWith(mTower2) && (mStack2.size() == 0 || ring.getmWeight() < ((Ring) mStack2.peek()).getmWeight())) {
            stack = mStack2;
            tower = mTower2;
        } else if (ring.collidesWith(mTower3) && (mStack3.size() == 0 || ring.getmWeight() < ((Ring) mStack3.peek()).getmWeight())) {
            stack = mStack3;
            tower = mTower3;
        } else {
            stack = ring.getmStack();
            tower = ring.getmTower();
        }
        ring.getmStack().remove(ring);
        if (stack != null && tower !=null && stack.size() == 0) {
            ring.setPosition(tower.getX() + tower.getWidth()/2 - ring.getWidth()/2, tower.getY() + tower.getHeight() - ring.getHeight());
        } else if (stack != null && tower !=null && stack.size() > 0) {
            ring.setPosition(tower.getX() + tower.getWidth()/2 - ring.getWidth()/2, ((Ring) stack.peek()).getY() - ring.getHeight());
        }
        stack.add(ring);
        ring.setmStack(stack);
        ring.setmTower(tower);

        isGameOver();
    }

    private void isGameOver() {
        if(mStack3.size() == 3){


             Font main_font = FontFactory.create(this.getFontManager(), this.getTextureManager(), 256, 256, BitmapTextureFormat.RGBA_8888, TextureOptions.BILINEAR_PREMULTIPLYALPHA, Typeface.DEFAULT, 60, true, Color.BLACK_ABGR_PACKED_INT);
             main_font.load();

             Text gameOverText = new Text(0, 0, main_font, "GameOver", this.getVertexBufferObjectManager());
             gameOverText.setPosition(CAMERA_WIDTH/2 - gameOverText.getWidth()/2, CAMERA_HEIGHT/2 - gameOverText.getHeight()/2);
             scene.attachChild(gameOverText);

             scene.clearTouchAreas();


       }

        }

这篇关于河内流行QUOT Android的AndEngine塔;游戏超过QUOT;当环达到3塔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 07:54