-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLevel1.js
66 lines (55 loc) · 1.99 KB
/
Level1.js
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
export default class Level1 extends Phaser.Scene {
constructor() {
super('Level1');
}
preload() {
this.load.image('background', 'assets/background1.png');
}
create() {
this.add.image(400, 300, 'background');
this.story = [
"The Barrier of Flames is under attack! Repair it.",
"Unauthorized traffic detected. Block it.",
"Inspect firewall integrity for vulnerabilities."
];
this.currentStep = 0;
this.showStory(this.story[this.currentStep]);
this.choices = [
{ text: 'Repair the Firewall', correct: true },
{ text: 'Block Unauthorized Traffic', correct: false },
{ text: 'Inspect Firewall Integrity', correct: false }
];
this.showChoices();
}
showStory(text) {
document.getElementById('storyText').style.display = 'block';
document.getElementById('storyText').innerText = text;
}
showChoices() {
this.choices = Phaser.Utils.Array.Shuffle(this.choices);
let y = 450;
this.choices.forEach(choice => {
let text = this.add.text(400, y, choice.text, { fill: choice.correct ? '#00FF00' : '#FF0000' })
.setInteractive()
.on('pointerdown', () => this.handleChoice(choice));
y += 50;
});
}
handleChoice(choice) {
if (choice.correct) {
this.currentStep++;
if (this.currentStep < this.story.length) {
this.showStory(this.story[this.currentStep]);
this.clearChoices();
this.showChoices();
} else {
this.scene.start('Level2');
}
} else {
document.getElementById('feedbackText').innerText = "Incorrect! Try again.";
}
}
clearChoices() {
this.children.getAll('text').forEach(child => child.destroy());
}
}