Skip to content

Commit 87728fe

Browse files
authored
Merge pull request #20 from okaybenji/replay-save-system
Replay save system
2 parents cd8d0ac + b853fa5 commit 87728fe

File tree

8 files changed

+383
-377
lines changed

8 files changed

+383
-377
lines changed

game-disks/demo-disk.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const demoDisk = {
1+
const demoDisk = () => ({
22
roomId: 'foyer', // the ID of the room the player starts in
33
rooms: [
44
{
@@ -14,7 +14,7 @@ const demoDisk = {
1414
const room = getRoom('foyer');
1515
room.desc = `You are currently standing in the foyer. There's a huge **MONSTERA** plant to your right, and a massive **WINDOW** to your left bathing the room in natural light. Both the **PLANT** and the **WINDOW** stretch to the ceiling, which must be at least 25 feet high.
1616
17-
***Rooms** form the foundation of the engine's design. At any given time, your player will be standing in one of the rooms you built for them. These can be literal rooms like the foyer you find yourself in now, or metaphorical rooms like **The End of Time** or **Purgatory**.
17+
***Rooms** form the foundation of the engine's design. At any given time, your player will be standing in one of the rooms you built for them. These can be literal rooms like the foyer you find yourself in now, or metaphorical rooms like **The End of Time** or **A Dream**.
1818
1919
Each room you create should have a description. (That's what you're reading now!)
2020
@@ -38,7 +38,7 @@ const demoDisk = {
3838
block: `It's far too large for you to carry.`, // optional reason player cannot pick up this item
3939
// when player looks at the plant, they discover a shiny object which turns out to be a key
4040
onLook: () => {
41-
if (getItemInRoom('shiny', 'foyer') || getItemInInventory('shiny')) {
41+
if (getItem('shiny')) {
4242
// the key is already in the pot or the player's inventory
4343
return;
4444
}
@@ -48,7 +48,7 @@ const demoDisk = {
4848
// put the silver key in the pot
4949
foyer.items.push({
5050
name: ['shiny thing', 'something shiny', 'pot'],
51-
onUse: () => {
51+
onUse() {
5252
const room = getRoom(disk.roomId);
5353
if (room.id === 'foyer') {
5454
println(`There's nothing to unlock in the foyer.`);
@@ -58,15 +58,15 @@ const demoDisk = {
5858
const exit = getExit('east', room.exits);
5959
delete exit.block;
6060
// this item can only be used once
61-
const key = getItemInInventory('shiny');
61+
const key = getItem('shiny');
6262
key.onUse = () => println(`The lab has already been unlocked.`);
6363
} else {
6464
println(`There's nothing to unlock here.`);
6565
}
6666
},
6767
desc: `It's a silver **KEY**!`,
68-
onLook: () => {
69-
const key = getItemInInventory('shiny') || getItemInRoom('shiny', 'foyer');
68+
onLook() {
69+
const key = getItem('shiny');
7070

7171
// now that we know it's a key, place that name first so the engine calls it by that name
7272
key.name.unshift('silver key');
@@ -78,10 +78,10 @@ const demoDisk = {
7878
delete key.onLook;
7979
},
8080
isTakeable: true,
81-
onTake: () => {
81+
onTake() {
8282
println(`You took it.`);
8383
// update the monstera's description, removing everything starting at the line break
84-
const plant = getItemInRoom('plant', 'foyer');
84+
const plant = getItem('plant');
8585
plant.desc = plant.desc.slice(0, plant.desc.indexOf('\n'));
8686
},
8787
});
@@ -97,7 +97,7 @@ const demoDisk = {
9797
9898
Type **INV** to see a list of items in your inventory.*`),
9999
// using the dime randomly prints HEADS or TAILS
100-
onUse: () => {
100+
onUse() {
101101
const side = Math.random() > 0.5 ? 'HEADS' : 'TAILS';
102102
println(`You flip the dime. It lands on ${side}.`);
103103
},
@@ -128,7 +128,7 @@ const demoDisk = {
128128
{
129129
name: 'door',
130130
desc: `There are 4" metal letters nailed to the door. They spell out: "RESEARCH LAB".`,
131-
onUse: () => {
131+
onUse() {
132132
const reception = getRoom('reception');
133133
const exit = getExit('east', reception.exits);
134134
if (exit.block) {
@@ -195,7 +195,7 @@ const demoDisk = {
195195

196196
// add a special item to the player's inventory
197197
disk.inventory.push({
198-
name: 'style-changer',
198+
name: ['style-changer', 'stylechanger'],
199199
desc: `This is a magical item. Type **USE STYLE-CHANGER** to try it out!`,
200200
onUse: () => {
201201
const currentStylesheet = document.getElementById('styles').getAttribute('href');
@@ -275,7 +275,7 @@ const demoDisk = {
275275
},
276276
{
277277
option: `What is a **DISK**?`,
278-
line: `A disk is a JavaScript object which describes your game. At minimum, it must have these two top-level properties:
278+
line: `A disk is a JavaScript function returning an object which describes your game. At minimum, the returned object must have these two top-level properties:
279279
280280
**roomId** (*string*) - This is a reference to the room the player currently occupies. Set this to the **ID** of the room the player should start in.
281281
@@ -440,9 +440,15 @@ const demoDisk = {
440440
441441
**roomId** (*string*) - The unique identifier for the room.`
442442
},
443+
{
444+
option: `Tell me about **GETITEM**`,
445+
line: `<code>getItem</code> is a function you can use to get a reference to an item in the player's inventory or in the current room. It takes one argument:
446+
447+
**name** (*string*) - The name of the item.`
448+
},
443449
{
444450
option: `Tell me about **GETITEMINROOM**`,
445-
line: `<code>getItemInRoom</code> is a function you can use to get a reference to an item in a particular room. It takes two arguments:
451+
line: `<code>getItemInRoom</code> is a function you can use to get a reference to an item in any room. It takes two arguments:
446452
447453
**itemName** (*string*) - The name of the item.
448454
@@ -461,7 +467,7 @@ const demoDisk = {
461467
],
462468
},
463469
],
464-
};
470+
});
465471

466472
// custom functions used by this disk
467473
// change the CSS stylesheet to the one with the passed name

game-disks/new-disk-template.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This simple game disk can be used as a starting point to create a new adventure.
22
// Change anything you want, add new rooms, etc.
3-
const newDiskTemplate = {
3+
const newDiskTemplate = () => ({
44
roomId: 'start', // Set this to the ID of the room you want the player to start in.
55
rooms: [
66
{
@@ -21,14 +21,17 @@ const newDiskTemplate = {
2121
name: 'axe',
2222
desc: `You could probably USE it to cut the VINES, unblocking the door.`,
2323
isTakeable: true, // Allows the player to take the item.
24-
onUse: () => {
24+
onUse() {
2525
// Remove the block on the room's only exit.
2626
const room = getRoom('start');
2727
const exit = getExit('north', room.exits);
2828

2929
if (exit.block) {
3030
delete exit.block;
3131
println(`You cut through the vines, unblocking the door to the NORTH.`);
32+
33+
// Update the axe's description.
34+
getItem('axe').desc = `You USED it to cut the VINES, unblocking the door.`;
3235
} else {
3336
println(`There is nothing to use the axe on.`);
3437
}
@@ -55,4 +58,4 @@ const newDiskTemplate = {
5558
],
5659
}
5760
],
58-
};
61+
});

game-disks/screen-creatures.js

Lines changed: 0 additions & 79 deletions
This file was deleted.

game-disks/unlimited-adventure.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ commands[0].help = help;
1515
// switch to the retro style
1616
document.getElementById('styles').setAttribute('href', 'styles/retro.css');
1717

18-
const unlimitedAdventure = {
18+
const unlimitedAdventure = () => ({
1919
roomId: 'gameOver', // The room the player is currently in. Set this to the room you want the player to start in.
2020
inventory: [], // You can add any items you want the player to start with here.
2121
rooms: [
@@ -75,11 +75,11 @@ WWWWW/\\| / \\|'/\\|/"\\
7575
`,
7676
// This is just here as an example of how you can use the onEnter property.
7777
// This gets called when the player enters the room.
78-
onEnter: ({disk, println, getRoom}) => {
78+
onEnter({disk, println, getRoom}) {
7979
console.log('Entered', disk.roomId); // Logs "Entered endOfTheWorld"
8080
},
8181
items: [
82-
{ name: 'key', desc: 'It looks like a key.', isTakeable: true, use: ({disk, println, getRoom}) => {
82+
{ name: 'key', desc: 'It looks like a key.', isTakeable: true, onUse({disk, println, getRoom}) {
8383
// This method gets run when the user types "use key".
8484
const room = getRoom(disk.roomId);
8585
const door = room.items.find(item => item.name === 'door');
@@ -91,7 +91,7 @@ WWWWW/\\| / \\|'/\\|/"\\
9191
println('There\'s nothing to use the key on.');
9292
}
9393
}},
94-
{ name: 'book', desc: 'It appears to contain some sort of encantation, or perhaps... code.', isTakeable: true, use: ({disk, println, getRoom}) => {
94+
{ name: 'book', desc: 'It appears to contain some sort of encantation, or perhaps... code.', isTakeable: true, onUse({disk, println, getRoom}) {
9595
const room = getRoom(disk.roomId);
9696
const door = room.items.find(item => item.name === 'door');
9797

@@ -101,7 +101,7 @@ WWWWW/\\| / \\|'/\\|/"\\
101101
}
102102

103103
println('A door has appeared from nothing! It seems to go nowhere...');
104-
room.items.push({ name: 'door', desc: 'It seems to go nowhere...', isOpen: false, use: ({disk, println, enterRoom}) => {
104+
room.items.push({ name: 'door', desc: 'It seems to go nowhere...', isOpen: false, onUse({disk, println, enterRoom}) {
105105
const door = room.items.find(item => item.name === 'door');
106106
if (door.isOpen) {
107107
enterRoom('gameReallyOver');
@@ -122,4 +122,4 @@ WWWWW/\\| / \\|'/\\|/"\\
122122
`,
123123
},
124124
],
125-
};
125+
});

0 commit comments

Comments
 (0)