-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathrules.js
More file actions
47 lines (41 loc) · 1.72 KB
/
rules.js
File metadata and controls
47 lines (41 loc) · 1.72 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
class Start extends Scene {
create() {
this.engine.show(this.engine.storyData.Title); // TODO: replace this text using this.engine.storyData to find the story title
this.engine.addChoice("Begin the story");
//console.log(this.engine.storyData.Title);
}
handleChoice() {
this.engine.gotoScene(Location, this.engine.storyData.InitialLocation); // TODO: replace this text by the initial location of the story
//console.log(this.engine.storyData.InitialLocation);
}
}
class Location extends Scene {
create(key) {
let locationData = this.engine.storyData.Locations[key]; // TODO: use `key` to get the data object for the current story location
//console.log(locationData)
this.engine.show(locationData.Body); // TODO: replace this text by the Body of the location data
if("Choices" in locationData) { // TODO: check if the location has any Choices
for(let choice of locationData.Choices) { // TODO: loop over the location's Choices
this.engine.addChoice(choice.Text, choice); // TODO: use the Text of the choice
// TODO: add a useful second argument to addChoice so that the current code of handleChoice below works
}
} else {
this.engine.addChoice("The end.")
}
}
handleChoice(choice) {
if(choice) {
this.engine.show("> "+choice.Text);
this.engine.gotoScene(Location, choice.Target);
} else {
this.engine.gotoScene(End);
}
}
}
class End extends Scene {
create() {
this.engine.show("<hr>");
this.engine.show(this.engine.storyData.Credits);
}
}
Engine.load(Start, 'myStory.json');