private void updateScorePoints() { Ball b; Barrier barrier; long score = 0; synchronized (m_newScorePoints) { Iterator<ScorePoint> it = m_newScorePoints.iterator(); ScorePoint sp; while (it.hasNext()) { sp = it.next(); sp.reduceAlpha(); if (sp.getAlpha() <= 0) it.remove(); } } synchronized (m_balls) { for (int i = 0; i < m_balls.size(); i++) { b = m_balls.get(i); synchronized (m_barriers) { for (int j = 0; j < m_barriers.size(); j++) { barrier = m_barriers.get(j); if (barrier.isPassed()) continue; if (b.center().y() >= barrier.rect().top) { addScore(b, m_points); barrier.setPassed(true); playSound("points"); break; } } } } } score = m_score + mStartScore; // verifica nivel if (score > 700 && m_points == 2) { // m_sleep = m_sleep + 30; ScorePoint.color = Color.YELLOW; m_defaultSpeed = m_speed = 2; m_points = 3; } else if (score > 1400 && m_points == 3) { // m_sleep = m_sleep + 20; ScorePoint.color = Color.RED; m_defaultSpeed = m_speed = 3; m_points = 4; } else if (score > 2800 && m_points == 4) { ScorePoint.color = Color.DKGRAY; // m_sleep = m_sleep + 20; m_defaultSpeed = m_speed = 4; m_points = 5; } else if (score > 5600 && m_points == 5) { ScorePoint.color = Color.BLACK; // m_sleep = m_sleep + 10; m_defaultSpeed = m_speed = 5; m_points = 6; } }
public void moveScenario() { float height = getScreenSize().height() + m_spaceBetweenRectangles; float minBottom = 0; Barrier barrier; synchronized (m_barriers) { Iterator<Barrier> it = m_barriers.iterator(); while (it.hasNext()) { barrier = it.next(); barrier.goUp(); if (barrier.isOut()) { it.remove(); continue; } if (barrier.rect().bottom > minBottom) minBottom = barrier.rect().bottom; } } // cria novas barreiras if (Math.abs(height - minBottom) >= m_spaceBetweenRectangles) { synchronized (m_barriers) { m_barriers.add(new Barrier(this, height)); } float bonus_release = (float) (0.1 * m_points); if (random.nextFloat() < bonus_release) { BonusBall bonusBall = null; float rand = random.nextFloat(); float radius = m_spaceBetweenRectangles / 5; int cx = (int) (random.nextInt((int) (m_view.getWidth() - (radius + 1)))); if (cx < radius + 1) cx = (int) radius + 1; int cy = (int) (height - radius); if (rand < 0.2) { bonusBall = new ColorBonusBall(this, cx, cy, radius); } else if (rand >= 0.2 && rand < 0.55) { bonusBall = new BombBonusBall(this, cx, cy, radius); } else if (rand >= 0.55 && rand < 0.95) { bonusBall = new TimeBonusBall(this, cx, cy, radius); } else if (rand >= 0.95) { bonusBall = new FailBonusball(this, cx, cy, radius); } if (bonusBall != null) { synchronized (m_bonusBalls) { m_bonusBalls.add(bonusBall); } } } } }
@Override public void federationSynchronized( String synchronizationPointLabel, FederateHandleSet failedToSyncSet) throws FederateInternalError { if (_federationSynchronizedBarrier != null) { if (_federationSynchronizedBarrier.getSuppliedValue().equals(synchronizationPointLabel)) { _federationSynchronizedBarrier.lower(null); } else { _userInterface.post("�(4.10)federationSynchronized at:" + synchronizationPointLabel); } } else { _userInterface.post("ERROR: federationSynchronized with no barrier set"); } }
@Override public void synchronizationPointRegistrationSucceeded(String synchronizationPointLabel) throws FederateInternalError { if (_synchronizationPointRegistrationSucceededBarrier != null) { if (_synchronizationPointRegistrationSucceededBarrier .getSuppliedValue() .equals(synchronizationPointLabel)) { _synchronizationPointRegistrationSucceededBarrier.lower(null); } else { _userInterface.post( "�(4.7)synchronizationPointRegistrationSucceeded; label: " + synchronizationPointLabel); } } else { _userInterface.post("ERROR: synchronizationPointRegistrationSucceeded with no barrier set"); } }
@Override public void timeRegulationEnabled(LogicalTime theFederateTime) throws FederateInternalError { if (_enableTimeRegulationBarrier != null) { Object[] returnedTime = {theFederateTime}; _enableTimeRegulationBarrier.lower(returnedTime); } else { _userInterface.post("ERROR: timeRegulationEnabled with no barrier set"); } }
/* ============================================================================= * main * ============================================================================= */ public static void main(String argv[]) throws Exception { System.gc(); Thread.sleep(1000); Manager managerPtr; Client clients[]; long start; long stop; /* Initialization */ Vacation vac = new Vacation(); vac.parseArgs(argv); managerPtr = vac.initializeManager(); clients = vac.initializeClients(managerPtr); int numThread = vac.CLIENTS; /* Run transactions */ System.out.println("Running clients... "); Barrier.setBarrier(numThread + 1); for (int i = 0; i < numThread; i++) { clients[i].start(); } Barrier.enterBarrier(); start = System.currentTimeMillis(); Barrier.enterBarrier(); stop = System.currentTimeMillis(); Barrier.assertIsClear(); System.out.print("done."); long diff = stop - start; System.out.println("TIME=" + diff); vac.checkTables(managerPtr); /* Clean up */ System.out.println("Deallocating memory... "); /* * TODO: The contents of the manager's table need to be deallocated. */ System.out.println("done."); }
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; } } } } } }
public void paintComponent(Graphics gr) { if (Commons.CLEAR_FILED) gr.clearRect(0, 0, Commons.WIDTH, Commons.HEIGHT); if (Commons.DRAW_BACKGROUND) { if (!gr.drawImage(background, 0, 0, null)) { repaint(); } } if (Commons.SHOW_SKINS) { if (active_skin != null) { Image img = active_skin.skin; int width = Commons.WIDTH / 2 - active_skin.skin.getWidth(null) / 2; int height = Commons.HEIGHT / 2 - active_skin.skin.getHeight(null); if (!gr.drawImage(img, width, height, null)) repaint(); } else { System.out.println("skin1"); } return; } for (Barrier b : barriers) { b.draw(gr); } if (Commons.MUSHROOM_EFFECT) { int t = (int) (Math.random() * 400); boolean st = (int) (Math.random() * 3) == 1 ? true : false; if (st) { int c = (int) (Math.random() * 4); switch (c) { case 0: gr.setColor(Color.BLUE); break; case 1: gr.setColor(Color.GREEN); break; case 2: gr.setColor(Color.YELLOW); break; case 3: gr.setColor(Color.RED); break; } try { System.out.println("sl"); Thread.sleep(t); } catch (InterruptedException e) { e.printStackTrace(); } gr.fillRect(0, 0, Commons.WIDTH, Commons.HEIGHT); } else { Image t1 = loadImage("/ru/klim/assets/barriers/mush1.png"); Image t2 = loadImage("/ru/klim/assets/barriers/mush2.png"); int x1 = (int) (Math.random() * Commons.WIDTH - t1.getWidth(null)); int y1 = (int) (Math.random() * Commons.HEIGHT - t1.getHeight(null)); int x2 = (int) (Math.random() * Commons.WIDTH - t2.getWidth(null)); int y2 = (int) (Math.random() * Commons.HEIGHT - t2.getHeight(null)); gr.drawImage(t1, x1, y1, null); gr.drawImage(t2, x2, y2, null); } } boolean st = ((int) (System.currentTimeMillis() / 200 % 2)) == 1 ? true : false; boolean r = st && dieTime > 0; pony.draw(gr, r); }