"Space Exploration" (in Harlowe 2.0)
This //Space Exploration// example borrows heavily from games like //FTL// (2012) where randomly generated obstacles prevent the player from her goal.
###Narrative Premise
Your ship has taken damage while in a hazardous area of space. With the navigation system broken, you know that it will take 15 hyperspace jumps to make it out of the area and back into safety.
###Game Rules
Each hyperspace jump takes 1 unit of fuel.
Because the navigation system is broken, each jump will land you in a random system of 1-4 planets. Those marked in RED are high-risk, high-reward. Those marked in GREEN are low-risk, low-reward. (The chance of RED or GREEN is 50%.)
Starting with 20 health and 2 units of fuel for your ship, explore space, planets you find, and try to make your way across the hazardous area of space.
[[Programming the rules]]
(set: $health to 20)
(set: $fuel to 2)
(set: $system to (array:) )
(set: $numberOfJumpsLeft to 15)
[[Explore Space 1]]{
<!-- Save a range from 0 to a max of 3 (total of max 4) -->
(set: _planets to (range: 0, (random: 1, 3) ) )
<!-- Reset system -->
(set: $system to (array:) )
<!-- Create a new system based on the previous random range -->
(for: each _i, ..._planets )[
<!-- Add to the new system, setting either RED or GREEN planets -->
(set: $system to it + (a: (either: "RED", "GREEN") ) )
]
}Health: $health
Fuel: $fuel
Number of Jumps Left: $numberOfJumpsLeft
(display: "Check Status"){
(for: each _planet, ...$system)[
(if: _planet is "RED")[
(link: _planet)[
(display: "Show Outcome - Red")
]
]
(if: _planet is "GREEN")[
(link: _planet)[
(display: "Show Outcome - Green")
]
]
<br>
]
}(link: "Hyperjump")[
(set: $fuel to it - 1)
(set: $numberOfJumpsLeft to it - 1)
(goto: "Explore Space 2")
]
[(display: "HUD")]<HUD|
(display: "Generate System")
(display: "Display System"){
(set: _percentage to (random: 1, 10) )
(if: _percentage is 1)[
(set: _foundFuel to (random: 1, 2) )
Fuel was found in some wreckage. (+_foundFuel to fuel)
(set: $fuel to it + _foundFuel)
] (else-if: _percentage is >= 6)[
(set: _foundHealth to (random: 1, 3) )
During a brief pause, the ship was able to be repaired. (+_foundHealth to health)
(set: $health to it + _foundHealth )
] (else:) [
Nothing happened.
]
(replace: ?HUD)[(display: "HUD")]
}{
(set: _percentage to (random: 1, 10) )
(if: _percentage is >= 6)[
(set: _foundHealth to (random: 1, 5) )
(set: _foundFuel to (random: 1, 3) )
The hostile environment damaged the ship, but extra fuel was found. (-_foundHealth to health and +_foundFuel to fuel)
(set: $health to it - _foundHealth )
(set: $fuel to it + _foundFuel )
] (else-if: _percentage <= 3)[
(set: _foundHealth to (random: 2, 7) )
A hostile ship attacked. (-_foundHealth to health)
(set: $health to it - _foundHealth )
] (else:)[
Nothing happened.
]
(replace: ?HUD)[(display: "HUD")]
}(link: "Hyperjump")[
(set: $fuel to it - 1)
(set: $numberOfJumpsLeft to it - 1)
(goto: "Explore Space 1")
]
[(display: "HUD")]<HUD|
(display: "Generate System")
(display: "Display System"){
(if: $health <= 0)[
(goto: "Destroyed")
]
(if: $fuel <= 0)[
(goto: "Lost in space")
]
(if: $numberOfJumpsLeft <= 0)[
(goto: "Safe")
]
}The ship exploded in flight.
###Game Over.Without fuel, the ship tumbled and spun in the endless black.
###Game OverAfter 15 hyperjumps, the ship left the hazardous area and called for help.
###Success!