如果布尔值中的任何一个为假,则使布尔值为假,但当它们都不为假时,我想使其为真

时间:2018-06-23 20:24:29

标签: java android boolean

我需要知道所有数组类的变量移动是否为真

  public boolean move,move2;


public ArrayList<DownBlocks> getBlocks() {
    return blocks;
}

public ArrayList<DownBlocks> getDones() {
    return dones;
}

 @Override
    public void render(float delta) {

  for (DownBlocks downBlocks:getBlocks()){
            if (!downBlocks.move){move=false;} }

如果move中的任何一个为假,则此代码可以使downblocks.moves为假,但当它们都不为假时,我想使它为真

3 个答案:

答案 0 :(得分:1)

使用此设置:

move = downBlocks.move && downBlocks.move1 && downBlocks.move2;

move仅在所有downBlocks.move???为真时才为真,否则为假。

答案 1 :(得分:1)

您可以尝试以下方法:

move = downblocks.moves1 && downblocks.moves2 && ... && downblocks.movesN;

答案 2 :(得分:1)

尝试一下:

move = true;    
for (DownBlocks downBlocks:getBlocks()){
    move = (move && downBlocks.move)
    if (!move) {break};
}