Skip to content

Commit

Permalink
Merge pull request #20 from okaybenji/replay-save-system
Browse files Browse the repository at this point in the history
Replay save system
  • Loading branch information
okaybenji authored Jul 13, 2022
2 parents cd8d0ac + b853fa5 commit 87728fe
Show file tree
Hide file tree
Showing 8 changed files with 383 additions and 377 deletions.
36 changes: 21 additions & 15 deletions game-disks/demo-disk.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const demoDisk = {
const demoDisk = () => ({
roomId: 'foyer', // the ID of the room the player starts in
rooms: [
{
Expand All @@ -14,7 +14,7 @@ const demoDisk = {
const room = getRoom('foyer');
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.
***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**.
***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**.
Each room you create should have a description. (That's what you're reading now!)
Expand All @@ -38,7 +38,7 @@ const demoDisk = {
block: `It's far too large for you to carry.`, // optional reason player cannot pick up this item
// when player looks at the plant, they discover a shiny object which turns out to be a key
onLook: () => {
if (getItemInRoom('shiny', 'foyer') || getItemInInventory('shiny')) {
if (getItem('shiny')) {
// the key is already in the pot or the player's inventory
return;
}
Expand All @@ -48,7 +48,7 @@ const demoDisk = {
// put the silver key in the pot
foyer.items.push({
name: ['shiny thing', 'something shiny', 'pot'],
onUse: () => {
onUse() {
const room = getRoom(disk.roomId);
if (room.id === 'foyer') {
println(`There's nothing to unlock in the foyer.`);
Expand All @@ -58,15 +58,15 @@ const demoDisk = {
const exit = getExit('east', room.exits);
delete exit.block;
// this item can only be used once
const key = getItemInInventory('shiny');
const key = getItem('shiny');
key.onUse = () => println(`The lab has already been unlocked.`);
} else {
println(`There's nothing to unlock here.`);
}
},
desc: `It's a silver **KEY**!`,
onLook: () => {
const key = getItemInInventory('shiny') || getItemInRoom('shiny', 'foyer');
onLook() {
const key = getItem('shiny');

// now that we know it's a key, place that name first so the engine calls it by that name
key.name.unshift('silver key');
Expand All @@ -78,10 +78,10 @@ const demoDisk = {
delete key.onLook;
},
isTakeable: true,
onTake: () => {
onTake() {
println(`You took it.`);
// update the monstera's description, removing everything starting at the line break
const plant = getItemInRoom('plant', 'foyer');
const plant = getItem('plant');
plant.desc = plant.desc.slice(0, plant.desc.indexOf('\n'));
},
});
Expand All @@ -97,7 +97,7 @@ const demoDisk = {
Type **INV** to see a list of items in your inventory.*`),
// using the dime randomly prints HEADS or TAILS
onUse: () => {
onUse() {
const side = Math.random() > 0.5 ? 'HEADS' : 'TAILS';
println(`You flip the dime. It lands on ${side}.`);
},
Expand Down Expand Up @@ -128,7 +128,7 @@ const demoDisk = {
{
name: 'door',
desc: `There are 4" metal letters nailed to the door. They spell out: "RESEARCH LAB".`,
onUse: () => {
onUse() {
const reception = getRoom('reception');
const exit = getExit('east', reception.exits);
if (exit.block) {
Expand Down Expand Up @@ -195,7 +195,7 @@ const demoDisk = {

// add a special item to the player's inventory
disk.inventory.push({
name: 'style-changer',
name: ['style-changer', 'stylechanger'],
desc: `This is a magical item. Type **USE STYLE-CHANGER** to try it out!`,
onUse: () => {
const currentStylesheet = document.getElementById('styles').getAttribute('href');
Expand Down Expand Up @@ -275,7 +275,7 @@ const demoDisk = {
},
{
option: `What is a **DISK**?`,
line: `A disk is a JavaScript object which describes your game. At minimum, it must have these two top-level properties:
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:
**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.
Expand Down Expand Up @@ -440,9 +440,15 @@ const demoDisk = {
**roomId** (*string*) - The unique identifier for the room.`
},
{
option: `Tell me about **GETITEM**`,
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:
**name** (*string*) - The name of the item.`
},
{
option: `Tell me about **GETITEMINROOM**`,
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:
line: `<code>getItemInRoom</code> is a function you can use to get a reference to an item in any room. It takes two arguments:
**itemName** (*string*) - The name of the item.
Expand All @@ -461,7 +467,7 @@ const demoDisk = {
],
},
],
};
});

// custom functions used by this disk
// change the CSS stylesheet to the one with the passed name
Expand Down
9 changes: 6 additions & 3 deletions game-disks/new-disk-template.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This simple game disk can be used as a starting point to create a new adventure.
// Change anything you want, add new rooms, etc.
const newDiskTemplate = {
const newDiskTemplate = () => ({
roomId: 'start', // Set this to the ID of the room you want the player to start in.
rooms: [
{
Expand All @@ -21,14 +21,17 @@ const newDiskTemplate = {
name: 'axe',
desc: `You could probably USE it to cut the VINES, unblocking the door.`,
isTakeable: true, // Allows the player to take the item.
onUse: () => {
onUse() {
// Remove the block on the room's only exit.
const room = getRoom('start');
const exit = getExit('north', room.exits);

if (exit.block) {
delete exit.block;
println(`You cut through the vines, unblocking the door to the NORTH.`);

// Update the axe's description.
getItem('axe').desc = `You USED it to cut the VINES, unblocking the door.`;
} else {
println(`There is nothing to use the axe on.`);
}
Expand All @@ -55,4 +58,4 @@ const newDiskTemplate = {
],
}
],
};
});
79 changes: 0 additions & 79 deletions game-disks/screen-creatures.js

This file was deleted.

12 changes: 6 additions & 6 deletions game-disks/unlimited-adventure.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ commands[0].help = help;
// switch to the retro style
document.getElementById('styles').setAttribute('href', 'styles/retro.css');

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

Expand All @@ -101,7 +101,7 @@ WWWWW/\\| / \\|'/\\|/"\\
}

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

0 comments on commit 87728fe

Please sign in to comment.