Game can be completed

main
Ashelyn Dawn 4 years ago
parent cdc82511a3
commit 76916590f2

@ -18,6 +18,7 @@ export default class Renderer {
private target : HTMLElement | null = null
private promptVisible : boolean = true
private videoSettingsSet : boolean = !!window.localStorage.getItem('video')
private gameEnded : boolean = false
constructor(parser : Parser, game : Game, rules : RulesEngine) {
this.parser = parser
@ -25,6 +26,12 @@ export default class Renderer {
this.rules = rules
}
endGame() {
this.gameEnded = true
this.promptVisible = false
this.render()
}
start(target : HTMLElement | null) {
this.target = target
this.rules.gameStart()
@ -37,7 +44,8 @@ export default class Renderer {
}
public showPrompt() {
this.promptVisible = true;
if(!this.gameEnded)
this.promptVisible = true;
this.render()
}

@ -1,7 +1,8 @@
import {game} from '../engine'
game.addRoom('cabin', 'Crew Cabin', `
A dark and dingy room with a single bunk bed along the starboard side.
A dark and dingy room with a single bunk bed along the starboard side, and a few
piles of discarded clothes strewn about the room.
The washroom is to the aft, with the comms room to port.
`)
@ -38,6 +39,13 @@ The bridge is to the fore, the medbay to port, and the crew cabin to starboard.
There is a large storage locker on the aft wall of the room.
`)
game.addItem('locker', `
Recessed into the aft wall, you use this locker to store various odds and
ends. Spare parts, cleaning supplies, etc.
It is locked.
`, 'comms')
game.addRoom('bridge', 'Bridge', `
A lone chair sits in the center of the room, surrounded with computer
consoles and flight instruments. Nowadays most aspects of spaceflight are

@ -22,7 +22,6 @@ export enum Phase {
unlockedLocker
}
// TODO: Replace [thing]
export const hints : Map<Phase, string> = new Map()
hints.set(Phase.wakeUp, 'You may be able to assess your situation better if you find a light.')
hints.set(Phase.hasFlashlight, 'With the security door shut and power cut off, you\'ll have to find another way into the rest of the ship.')
@ -32,16 +31,16 @@ hints.set(Phase.openedSinkPanel, 'You can get to the lower deck through the pane
hints.set(Phase.droppedBelow, 'You need to re-start the CO<sub>2</sub> scrubber before you run out of clean air.')
hints.set(Phase.fixedLifeSupport, 'While the immediate threat to your life has been solved, you need to bring the engine back on so you can restore power to your ship.')
hints.set(Phase.examinedEngine, 'The engine itself seems to be in good repair, time to go to the mainframe and start up its control systems.')
hints.set(Phase.examinedMainframe, 'The engine control systems are missing [thing]. There\'s a spare in the comm room locker, but you\'ll have to find a way to get there.')
hints.set(Phase.examinedDoor, 'You need to find a way into the comms room to retrieve [thing] - the door looks like it could be pried open with enough leverage.')
hints.set(Phase.examinedMainframe, 'The engine control systems are missing a capacitor. There\'s a spare in the comm room locker, but you\'ll have to find a way to get there.')
hints.set(Phase.examinedDoor, 'You need to find a way into the comms room to retrieve the capacitor for your engine controls - the door looks like it could be pried open with enough leverage.')
hints.set(Phase.examinedChair, 'The chair looks sturdy enough to work as a lever to get in the door, but it will have to be disassembled first.')
hints.set(Phase.destroyedChair, 'You have a bar that should be strong enough to open the door to the comms room - go retrieve the [thing] so you can start the engine again!')
hints.set(Phase.openedDoor, 'You found a way into the comms room - retrieve the [thing] from the comms room locker so you can restart the engine.')
hints.set(Phase.destroyedChair, 'You have a bar that should be strong enough to open the door to the comms room - go retrieve the the capacitor so you can start the engine again!')
hints.set(Phase.openedDoor, 'You found a way into the comms room - retrieve the capacitor from the comms room locker so you can restart the engine.')
hints.set(Phase.examinedLocker, 'Someone locked the comms room locker. There\'s a spare key in your overalls - they\'re back in your cabin.')
hints.set(Phase.examinedHoleCannotGetUp, 'You can\'t reach up into the bathroom any more - you\'ll have to find something else to use to climb up')
hints.set(Phase.hasNewChair, 'You found another chair you can use to reach the bathroom - go get the spare locker key from your cabin.')
hints.set(Phase.returnedUpToBathroom, 'Someone locked the comms room locker. There\'s a spare key in your overalls - they\'re back in your cabin.')
hints.set(Phase.hasKey, `You've retrieved the spare key to the comms locker, and can finally get the [thing] to repair the mainframe.`)
hints.set(Phase.hasKey, `You've retrieved the spare key to the comms locker, and can finally get the capacitor to repair the mainframe.`)
hints.set(Phase.unlockedLocker, 'Locker is empty - whoever was in your ship made sure you wouldn\'t be able to repair it.')
setImmediate(() => {

@ -1,4 +1,4 @@
import {game, rules, parser} from '../engine'
import {game, rules, parser, renderer} from '../engine'
import { ObjectType, Item } from '../engine/types/GameState'
import { Draft } from 'immer'
import { Phase } from './2-phases-and-hints'
@ -26,6 +26,17 @@ rules.onBeforeCommand(command => {
throw new Error(`The security doors have sealed - you're either going to need to restart the mainframe or find a way to force these open before you can access the comms room.`)
})
/**
* Do not allow going east from comms
*/
rules.onBeforeCommand(command => {
const playerLocation = game.getCurrentRoom()?.name
if(command.verb.name !== 'go' || playerLocation !== 'comms' || command.subject?.name !== 'starboard')
return;
throw new Error(`The security doors have sealed - you're either going to need to restart the mainframe or find a way to force these open before you can access the comms room.`)
})
/**
* Do not allow going east from medbay until opened
*/
@ -372,3 +383,30 @@ rules.onBeforeCommand(command => {
throw new Error()
})
/**
* Prevent locker from opening
*/
rules.onBeforeCommand(command => {
if(command.verb.name !== 'openItem' || command.subject?.name !== 'locker')
return
if(game.getProperty('gamePhase') === Phase.hasKey) {
renderer.endGame()
setImmediate(() => rules.emit('gameEnd'))
throw new Error()
}
game.say(`
The locker door rattles but will not open.
"That's odd," you say, "I don't remember locking this..." but luckily you have
a spare key. You think for a moment and remember the key is in your other
pants - those should be back in your cabin.
`)
if(game.getProperty('gamePhase') < Phase.examinedLocker)
game.setProperty('gamePhase', Phase.examinedLocker)
throw new Error()
})

@ -96,6 +96,8 @@ rules.onAfterCommand(command => {
game.say(`As you lower yourself down into the cargo bay you're struck by how empty it looks. Normally this storage bay would have a lot more general-purpose supplies, but you had to clear it out to make room for this delivery. Since you've dropped the cargo and were on your way to get paid, they're no longer here to fill that space.`)
game.pause()
game.clear()
game.say(`You weren't permitted to know what was in the boxes you delivered. "Wares to be sold in the outer markets," Rosalyn said when you asked. "The less you know the less you have to worry." `)
game.say(`You weren't even sure how heavy or light the boxes were - she arranged crews for loading and unloading ahead of time, and the time requirements for delivery were just close enough you hadn't dared stop to investigate along the way. It really was as easy as Wren had said it would be...`)
@ -177,3 +179,64 @@ rules.onAfterCommand(command => {
game.clear()
rules.printArea()
})
rules.onBeforeCommand(command => {
if(command.verb.name !== 'go' || command.subject?.name !== 'fore' || game.getCurrentRoom()?.name !== 'mainframe')
return;
if(game.getProperty('gamePhase') < Phase.examinedLocker)
return;
game.say(`As you work your way back to your cabin you start to get a growing sense of unease.`)
game.say(`You don't want to believe it, but something is definitely suspicious about this engine failure - the part was brand new, and now a locker you've never locked in your life is shut tight.`)
game.pause()
game.clear()
game.say(`You don't think about it. Rosalyn and the rest of her synth trade clients would definitely be willing to sabotage your ship, but they wouldn't have known enough to pull it off that quickly they had Wren's help.`)
game.say(`"Come on, Wren," you say to yourself, "don't let me down. The spare will be where I left it, and everything will be all right."`)
game.pause()
game.clear()
})
/**
* Give player key after entering cabin with the proper game phase
*/
rules.onAfterCommand(command => {
if(command.verb.name !== 'go' || command.subject?.name !== 'fore' || game.getCurrentRoom()?.name !== 'cabin')
return;
if(game.getProperty('gamePhase') < Phase.examinedLocker)
return;
game.say(`Upon entering your cabin you quickly find your pants and retrieve the key.`)
const key = game.addItem('key', 'A small steel locker key - cheap, but easier than picking the lock every time.', 'inventory')
key.seen = true
game.say(`(You place the key in your inventory)`)
game.setProperty('gamePhase', Phase.hasKey)
})
/**
* Triggers on opening the locker
*/
rules.on('gameEnd', () => {
game.clear()
game.say(`The key turns in the lock with a sharp ***click***. As you swing open the locker your heart drops.`)
game.say(`"No Wren," you mutter, "you didn't!" But the empty locker before you is evidence that he did.`)
game.pause()
game.clear()
game.say(`It figures that the easy job was too good to be true.`)
game.pause()
game.clear()
game.say(`<div style="margin-top: 122px; text-align: center">[GAME OVER]</div>`)
game.say(`<div style="text-align:center; opacity: .6">(Reload the page to play again)</div>`)
})
Loading…
Cancel
Save