|
1 | | -public class GameApp { |
| 1 | +public class Main { |
2 | 2 | public static void main(String[] args) { |
3 | 3 | Player alice = new Player("Alice", new int[] {10, 15, 20}); |
4 | 4 | Player bob = new Player("Bob", new int[] {5, 7}); |
5 | | - Player charlie = new Player("Charlie", new int[] {}); // empty scores |
| 5 | + Player charlie = new Player("Charlie", new int[] {}); |
6 | 6 |
|
7 | 7 | System.out.println("=== Scoreboard ==="); |
8 | 8 |
|
9 | 9 | printPlayerStats(alice); |
10 | 10 | printPlayerStats(bob); |
11 | 11 | printPlayerStats(charlie); |
12 | 12 |
|
13 | | - // Intentionally pass a null player to show a null‑related bug |
14 | 13 | Player mystery = null; |
15 | 14 | System.out.println("\nMystery total score (should handle null):"); |
16 | 15 | int total = ScoreUtils.totalScore(mystery); |
17 | 16 | System.out.println("Total: " + total); |
18 | | - |
19 | | - // Level Loader demo for Level 4 |
20 | | - demoLevels(); |
21 | 17 | } |
22 | 18 |
|
23 | 19 | private static void printPlayerStats(Player player) { |
24 | 20 | int[] scores = player.getScores(); |
| 21 | + int scoreLength = (scores == null) ? 0 : scores.length; |
25 | 22 |
|
26 | 23 | double avg = ScoreUtils.averageScore(scores); |
27 | 24 | int best = ScoreUtils.bestScore(scores); |
28 | | - int total = ScoreUtils.totalScore(player); |
| 25 | + int lineTotal = ScoreUtils.totalScore(player); |
29 | 26 |
|
30 | 27 | System.out.println("Player: " + player.getName()); |
31 | 28 | System.out.println(" Average: " + avg); |
32 | 29 | System.out.println(" Best: " + best); |
33 | | - System.out.println(" Total: " + total); |
| 30 | + System.out.println(" Total: " + lineTotal); |
34 | 31 | System.out.println(); |
35 | 32 | } |
36 | | - |
37 | | - private static void demoLevels() { |
38 | | - System.out.println("=== Level Loader Demo ==="); |
39 | | - |
40 | | - String input = "level: 4"; // note the space before 4 |
41 | | - System.out.println("Parsing input: \"" + input + "\""); |
42 | | - |
43 | | - int level = InputParser.parseLevel(input); |
44 | | - System.out.println("Parsed level: " + level); |
45 | | - |
46 | | - int[] enemies = LevelLoader.loadEnemiesForLevel(level); |
47 | | - int difficulty = LevelLoader.computeDifficulty(enemies); |
48 | | - |
49 | | - System.out.println("Total difficulty for level " + level + ": " + difficulty); |
50 | | - } |
51 | 33 | } |
52 | | - |
0 commit comments