This commit is contained in:
Simoes Lukas
2025-11-06 15:20:51 +01:00
parent 9b1257f3da
commit c730f07c1b
13 changed files with 874 additions and 8 deletions

View File

@@ -24,7 +24,7 @@ public class JGrilleDeJeu extends JComponent {
this.controleur = new ControleurClavier();
this.fenetre.addKeyListener(controleur);
this.directionActuelle = "Right";
this.intervalleTimer = 500;
this.intervalleTimer = 150;
Random r = new Random();
int coordXPomme = Math.abs(r.nextInt() % TAILLE_GRILLE);
@@ -145,13 +145,6 @@ public class JGrilleDeJeu extends JComponent {
}
this.coordSnake.addFirst(aAjouter);
this.coordSnake.addFirst(coordQueue);
if (this.intervalleTimer != 200) {
this.intervalleTimer -= 50;
this.timer.cancel();
this.timer = new Timer();
this.timer.scheduleAtFixedRate(new TacheTimer(this), 0, this.intervalleTimer);
}
}
try {

Binary file not shown.

View File

@@ -0,0 +1,16 @@
import java.util.Map;
import java.util.Map.Entry;
public class Main {
public static void main(String[] args) {
Map<Thread, StackTraceElement[]> threads = Thread.getAllStackTraces();
for (Map.Entry<Thread, StackTraceElement[]> thread : threads.entrySet()) {
System.out.println(thread.getKey().getName() + " :");
for (StackTraceElement trace : thread.getValue()) {
System.out.println(" " + trace.getClassName() + "." + trace.getMethodName() + "(" + trace.getFileName() + ":" + trace.getLineNumber() + ")");
}
System.out.println();
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,25 @@
import javax.swing.event.*;
import java.util.Map;
import java.util.HashMap;
import javax.swing.*;
import java.awt.Color;
public class ControleurListe implements ListSelectionListener {
private String actuel;
private JPanel panneau;
private Map dictCouleurs;
private JList liste;
public ControleurListe(JPanel panneau, Map dictCouleurs, JList liste) {
this.panneau = panneau;
this.dictCouleurs = dictCouleurs;
this.liste = liste;
}
@Override
public void valueChanged(ListSelectionEvent e) {
this.panneau.setBackground((Color) this.dictCouleurs.get(this.liste.getSelectedValue()));
this.panneau.repaint();
}
}

Binary file not shown.

View File

@@ -0,0 +1,26 @@
import java.awt.*;
import javax.swing.*;
import java.util.Map;
import java.util.HashMap;
public class Fenetre extends JFrame {
public Fenetre() {
this.setSize(300, 200);
this.setLocation(100, 100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new GridLayout(1, 2));
LectureFichier donnees = new LectureFichier();
Map<String, Color> dictCouleurs = donnees.getDictCouleurs();
JList<String> listeCouleurs = new JList<>(dictCouleurs.keySet().toArray(new String[2]));
JPanel couleur = new JPanel();
couleur.setBackground(Color.WHITE);
JScrollPane scroll = new JScrollPane(listeCouleurs);
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
this.add(scroll);
this.add(couleur);
listeCouleurs.addListSelectionListener(new ControleurListe(couleur, dictCouleurs, listeCouleurs));
}
}

Binary file not shown.

View File

@@ -0,0 +1,48 @@
import java.io.*;
import java.util.Map;
import java.util.HashMap;
import java.util.Arrays;
import java.awt.*;
public class LectureFichier {
private Map<String, Color> dictCouleurs;
public LectureFichier() {
this.dictCouleurs = new HashMap<>();
try {
BufferedReader lecture = new BufferedReader(new FileReader("rgb.txt"));
try {
String ligne = lecture.readLine();
while(ligne != null) {
String r = ligne.substring(0, 3).trim();
String g = ligne.substring(4, 7).trim();
String b = ligne.substring(8, 11).trim();
String nomCouleur = ligne.substring(11).strip();
this.dictCouleurs.put(nomCouleur, new Color(Integer.parseInt(r), Integer.parseInt(g), Integer.parseInt(b)));
ligne = lecture.readLine();
}
} catch(IOException e) {
System.err.println("Erreur de lecture dans rgb.txt !");
}
try {
lecture.close();
} catch(IOException e) {
System.err.println("Erreur de fermeture de rgb.txt !");
}
} catch(FileNotFoundException e) {
System.err.println("Erreur d'ouverture de rgb.txt !");
}
}
public Map<String, Color> getDictCouleurs() {
return this.dictCouleurs;
}
}

Binary file not shown.

View File

@@ -0,0 +1,6 @@
public class Main {
public static void main(String[] args) {
Fenetre fenetre = new Fenetre();
fenetre.setVisible(true);
}
}

File diff suppressed because it is too large Load Diff