/** Boucle principale de la simulation */ import java.awt.Color ; public class Anim { /** Effectue une pause de la duree indiquee en millisecondes */ public static void pause(int duree) { try { Thread.currentThread().sleep(duree) ; } catch (InterruptedException e) {} } /** Boucle principale */ public void go() { int compteur = 0; Plateau plat ; Robot[] robots ; plat = new Plateau(800, 600) ; robots = new Robot[7] ; robots[0] = new Robot("Aphrodite", "Images/mini1.png", 200, 100, plat, Color.RED, 0) ; robots[1] = new Robot("Arès", "Images/mini2.png", 600, 100, plat, Color.GREEN, 1) ; robots[2] = new Indestructible("Zeus", "Images/mini3.png", 200, 500, plat, Color.YELLOW, 2) ; robots[3] = new Cyborg("Déméter", "Images/mini7.png", 600, 500, plat, Color.PINK, 7, 3) ; robots[4] = new Cyborg("Poséidon", "Images/mini4.png", 400, 300, plat, Color.BLUE, 5, 4) ; robots[5] = new Killer("Hermès", "Images/mini5.png", 700, 300, plat, Color.GRAY, 5, 3) ; robots[6] = new Killer("Athéna", "Images/mini6.png", 100, 300, plat, Color.ORANGE, 6, 8) ; // On repete la boucle d'animation sans arret while (true) { // On fait evoluer chaque robot for (int i = 0 ; i < robots.length ; i++) { robots[i].bouge () ; } // Puis on teste les collisions deux a deux for (int i = 0 ; i < robots.length ; i++) { for (int j = i+1 ; j < robots.length ; j++) { robots[i].testeCollision(robots[j]) ; } } // Pour chaque robot, on met un petit cercle if (compteur % 10 == 0){ for (int i = 0 ; i < robots.length ; i++) { plat.setColor(robots[i].col); plat.drawCircle(robots[i].x, robots[i].y, 5); } } compteur++; // Petite pause java.awt.Toolkit.getDefaultToolkit().sync(); // Sinon l'animation est saccadée - probablement à cause du Window Manager. this.pause(12) ; } } public static void main(String[] args) { Anim an = new Anim() ; Images.init () ; an.go () ; } }