This repository was archived by the owner on Jun 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_Phase4.java
More file actions
105 lines (87 loc) · 3.79 KB
/
Copy path_Phase4.java
File metadata and controls
105 lines (87 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
public class _Phase4 {
static Scanner scanner;
public static void main(Scanner scanner) {
Player.updatePhase(4);
_Phase4.scanner = scanner;
UI.clearScreen();
System.out.println("\n==============================================");
System.out.println(" HUNTER x HUNTER - MATH CHALLENGE");
System.out.println(" Phase 4 of Hunter Exam");
System.out.println("==============================================");
UI.printGreyText("\nPress enter to continue...");
scanner.nextLine();
UI.clearScreen();
System.out.println("Lippo: Welcome to Zevil Island. This phase will test not only your survival skills but also your intellect.");
scanner.nextLine();
System.out.println("Lippo: Answer the following math problems correctly to proceed. Remember, only those who can think swiftly will survive.\n");
scanner.nextLine();
List<Question> selectedQuestions = getRandomQuestions();
int score = 0;
int questionNumber = 1;
for (Question q : selectedQuestions) {
int answer;
while (true) {
UI.clearScreen();
System.out.println("Question " + questionNumber + ": " + q.text);
System.out.print("Your answer: ");
try {
answer = Integer.parseInt(scanner.nextLine());
if (answer >= 1 && answer <= 404) break;
else System.out.println("\rEnter a number between 1 and 404:");
} catch (NumberFormatException e) {
System.out.println("\rPlease enter a valid number:");
}
}
if (answer == q.answer) {
UI.printBox("Correct!");
score++;
} else {
UI.printBox("Wrong. Correct answer: " + q.answer);
}
UI.printGreyText("\nPress enter to continue...");
scanner.nextLine();
questionNumber++;
}
System.out.println("You scored " + score + " out of 5.");
if (score >= 3) {
System.out.println("Lippo: Impressive. You've demonstrated both intellect and composure under pressure.");
scanner.nextLine();
System.out.println("Lippo: Proceed to the final phase. Your journey as a Hunter continues.\n");
scanner.nextLine();
Player.currentScore += 100;
Player.updateScore();
UI.printGreyText("\nPress enter to go to the next phase");
scanner.nextLine();
_PhaseFinal.main(scanner);
} else {
Player.failHunterExam();
System.out.println("Lippo: Unfortunately, you did not meet the required score.");
scanner.nextLine();
System.out.println("Lippo: Survival on Zevil Island is unforgiving. Better luck next time.\n");
scanner.nextLine();
UI.printGreyText("\nPress Enter To Continue...");
scanner.nextLine();
_PlayerScreen.main(scanner);
}
}
static List<Question> getRandomQuestions() {
List<Question> questions = new ArrayList<>();
List<String> result = SQL.runGetResultAll("SELECT * FROM p4Questions ORDER BY RAND() LIMIT 5;");
for (String line : result) {
String[] parts = line.split("::");
questions.add(new Question(parts[1], Integer.parseInt(parts[2])));
}
return questions;
}
static class Question {
String text;
int answer;
Question(String text, int answer) {
this.text = text;
this.answer = answer;
}
}
}