para_bellum

ScheduledThreadPollExecutor

May 3rd, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. public class Game {
  2.     private int corePoolSize=2;
  3.     private static ScheduledThreadPoolExecutor stpe;
  4.     protected static Hashtable<Integer, Rock> rocksList;
  5.     protected static Hashtable<Integer, Shot> shotsList;
  6.     protected static Enumeration<Rock> enumAst;
  7.     protected static Enumeration<Shot> enumShot;
  8.     protected static Rock tempRock;
  9.     protected static Ship ship;
  10.     protected static Shot shots;
  11.  
  12.     public void methodeEnCaca() {
  13.         Game.stpe = new ScheduledThreadPoolExecutor(this.corePoolSize);
  14.         Game.stpe.scheduleAtFixedRate(new GameThread(), 1, 20, TimeUnit.MILLISECONDS);
  15.     }
  16. }
  17.  
  18.  
  19. public class GameThread extends Game implements Runnable {
  20.  
  21.     public GameThread(){}
  22.    
  23.     public void run() {
  24.         detectCollision();
  25.        
  26.         /*
  27.          * boucle demandant à tous les éléments de la liste de mettre leur vue à jour
  28.          */
  29.         Game.enumAst = Game.rocksList.elements();
  30.         while(enumAst.hasMoreElements()) {
  31.             Game.tempRock=enumAst.nextElement();
  32.             Game.tempRock.updatePosition();
  33.         }
  34.        
  35.         Game.enumShot = Game.shotsList.elements();
  36.         while(enumShot.hasMoreElements()) {
  37.             Game.shots=enumShot.nextElement();
  38.             Game.shots.updatePosition();
  39.         }
  40.        
  41.         if(Game.ship!=null) {
  42.             Game.ship.updatePosition();
  43.         }
  44.        
  45.         refreshView(); //méthode demandant à la vue de faire un repaint()
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment