Or operand with int in if statement

前端 未结 12 1949
傲寒
傲寒 2021-01-25 07:45

My problem is that program is not reading codes as i intended \"he\" would.

I have

if (hero.getPos() == (6 | 11 | 16)) {
    move = new Object[] {\"Up\",         


        
12条回答
  •  北荒
    北荒 (楼主)
    2021-01-25 08:20

    The other answers are correct, just thinking differently you may use Sets.

    static final Set positions = new HashSet();
    static{
        positions.add(6);
        positions.add(11);
        positions.add(16);
    }
    
    if (positions.contains(hero.getPos())){
        move = new Object[] {"Up", "Right", "Left"};
    } else {
        move = new Object[] {"Up", "Down", "Right", "Left"};
    }
    

提交回复
热议问题