예제 #1
0
  public void fixCollisions() {

    synchronized (m_bonusBalls) {
      for (int i = 0; i < m_bonusBalls.size() - 1; i++) {
        m_bonusBalls.get(i).moveOnOverlap(m_bonusBalls, i + 1, m_bonusBalls.size());
      }

      synchronized (m_balls) {
        for (Ball ball : m_balls) {
          ball.moveOnOverlap(m_bonusBalls, 0, m_bonusBalls.size());
        }
      }
    }

    synchronized (m_bonusBalls) {
      for (BonusBall ball : m_bonusBalls) {
        synchronized (m_barriers) {
          for (Barrier barrier : m_barriers) {
            if (ball.moveOnOverlap(barrier)) break;
          }
        }
      }
    }

    synchronized (m_balls) {
      for (Ball ball : m_balls) {
        synchronized (m_barriers) {
          for (Barrier barrier : m_barriers) {
            if (barrier.isPassed()) continue;

            if (!(Barrier.hasColor() && barrier.color() == ball.color())) {
              if (ball.moveOnOverlap(barrier)) break;
            }
          }
        }
      }
    }
  }
 @Override
 public void execute(Bag bag, Ball ball) throws YellowBallMaxLimitExceedException {
   if (ball.color() == Color.YELLOW && bag.countBalls(Color.YELLOW) >= 0.4 * bag.totalBalls())
     throw new YellowBallMaxLimitExceedException();
 }