Skip to content
Snippets Groups Projects
Commit b7792590 authored by Villard PierreFrederic's avatar Villard PierreFrederic
Browse files

Extract JeuPhysique and BouclePrincipal in the main package

parent cf09e40d
No related branches found
No related tags found
No related merge requests found
package main;
import controle.ControleurClavier; import controle.ControleurClavier;
public class BouclePrincipale { public class BouclePrincipale {
String nom="Mon super Jeu"; public String nom="Mon super Jeu";
int fps=100; public int fps=100;
JeuPhysique jeuPhysique; public JeuPhysique jeuPhysique;
//creation du controleur //creation du controleur
ControleurClavier cClavier; public ControleurClavier cClavier;
public void setName(String nom){ public void setName(String nom){
... ...
......
package main;
/* ========================================================== */ /* ========================================================== */
/* Bibliotheque MoteurDeJeu */ /* Bibliotheque MoteurDeJeu */
/* -------------------------------------------- */ /* -------------------------------------------- */
...@@ -17,10 +19,10 @@ import java.io.IOException; ...@@ -17,10 +19,10 @@ import java.io.IOException;
public class JeuPhysique{ public class JeuPhysique{
//le moteur physique //le moteur physique
MoteurPhysique moteurPhys; public MoteurPhysique moteurPhys;
//le rendu //le rendu
Afficheur affiche; public Afficheur affiche;
int i=0; int i=0;
... ...
......
...@@ -10,10 +10,73 @@ ...@@ -10,10 +10,73 @@
/* ========================================================== */ /* ========================================================== */
package miscellaneous; package miscellaneous;
import main.BouclePrincipale;
import controle.ControleurClavier;
/** /**
*
* *
* @author Pierre-Frederic Villard * @author Pierre-Frederic Villard
*/ */
public class BouclePrincipaleCool extends BouclePrincipale{ public class BouclePrincipaleCool extends BouclePrincipale{
@Override
public void lanceBouclePrincipale() throws Exception {
//ControleurClavier cClavier=new ControleurClavier(true);
jeuPhysique.affiche.addKeyListener(cClavier);
//mettre l'acces au controleur dans monde
jeuPhysique.moteurPhys.monde.c=cClavier.c;
//afficher
System.out.println("\n\n**************************************************");
System.out.println("* "+nom);
System.out.println("* *");
System.out.println("*** touche 'Q' pour arreter jeu ***");
System.out.println("****************************************************");
System.out.println("\n\n");
//fps
long dureeBoucle=1000000/fps;
System.out.println(" ---> duree d'une boucle "+dureeBoucle/1000.);
//lancement
Thread.sleep(1000);
jeuPhysique.affiche.requestFocusInWindow();
// boucle
long beforeTime = System.nanoTime();
long l = System.currentTimeMillis();
//nombre iterations
int n=0;
while(!ControleurClavier.fin)
{
n++;
jeuPhysique.update();
jeuPhysique.render();
//apres le render en nanos
long timafter=System.nanoTime();
//sleep en millisecond
while(System.nanoTime()-beforeTime-dureeBoucle*1000L<0)
{
}
beforeTime=System.nanoTime();
}
long l2 = System.currentTimeMillis();
// statistiques
System.out.println("\n\n\n************************\n");
System.out.println("Iterations = "+n);
System.out.println("FPS = " + (n * 1000.0 / (l2 - l)));
System.out.println("\n************************");
System.exit(0);
}
} }
import main.BouclePrincipale;
import afficheur.Afficheur; import afficheur.Afficheur;
import controle.ControleurClavier; import controle.ControleurClavier;
import miscellaneous.MurCool; import miscellaneous.MurCool;
... ...
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
* @author Pierre-Frederic Villard * @author Pierre-Frederic Villard
*/ */
import main.BouclePrincipale;
import miscellaneous.MurCool; import miscellaneous.MurCool;
import afficheur.Afficheur; import afficheur.Afficheur;
import afficheur.Repere; import afficheur.Repere;
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment