fix(Rankboard.java): ajout arraylist clone

This commit is contained in:
2025-11-09 19:17:48 +01:00
parent 65371cc2b1
commit 72eccbf721
2 changed files with 13 additions and 7 deletions

View File

@@ -243,14 +243,17 @@ public class Game
* *
* @throws InterruptedException si le thread est interrompu pendant wait() * @throws InterruptedException si le thread est interrompu pendant wait()
*/ */
private synchronized void step() throws InterruptedException private void step() throws InterruptedException
{ {
for (int i = 0; i < cars.size(); i++) for (Car car : cars)
{ {
while (isPaused) synchronized(this)
wait(); {
while (isPaused)
wait();
}
cars.get(i).run(); car.run();
for (GObserver o : obs) for (GObserver o : obs)
{ {

View File

@@ -47,10 +47,13 @@ public class Rankboard extends GameView
*/ */
private void updateRankText() private void updateRankText()
{ {
cars.sort(Comparator.comparingInt(Car::getScore).reversed()); // cloner pour de modifier la classe principale
ArrayList<Car> cars_clone = new ArrayList<>(cars);
cars_clone.sort(Comparator.comparingInt(Car::getScore).reversed());
StringBuilder s = new StringBuilder(); StringBuilder s = new StringBuilder();
s.append("<html><table>"); s.append("<html><table>");
for (Car c : cars) for (Car c : cars_clone)
{ {
s.append("<tr><td>" + c + ": " + c.getScore() + "%</td></tr>"); s.append("<tr><td>" + c + ": " + c.getScore() + "%</td></tr>");
} }