Skip to content

Instantly share code, notes, and snippets.

@illbzo1
Created October 27, 2011 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save illbzo1/1318412 to your computer and use it in GitHub Desktop.
Save illbzo1/1318412 to your computer and use it in GitHub Desktop.
Another text-based dungeon game
class Game
def initialize(start)
@quips = [
"You died. You kind of suck at this.",
"Nice job! You died again!",
"What a loser!",
"I have a small puppy that's better at this."
]
@start = start
puts "in init @start = " + @start.inspect
end
def prompt
print '> '
end
def play()
puts "@start =>" + @start.inspect
next_room = @start
while true
puts "\n--------"
room = method(next_room)
next_room = room.call()
end
end
def death()
puts @quips[rand(@quips.length())]
Process.exit(1)
end
def central_corridor()
puts <<-CENTRAL_DESCRIPTION
The Gothons of Planet Percal #25 have invaded your ship and destroyed
your entire crew. You are the last surviving member and your last
mission is to get the neutron destruct bomb from the Weapons Armory,
put it in the bridge, and blow the ship up after getting into an
escape pod.
You're running down the central corridor to the Weapons Armory when
a Gothon jumps out, red scaly skin, dark grimy teeth, and evil clown costume
flowing around his hate filled body. He's blocking the door to the
Armory and about to pull a weapon to blast you.
CENTRAL_DESCRIPTION
prompt()
action = gets.chomp()
if action == "shoot"
puts <<-SHOT_DOWN
Quick on the draw you yank out your blaster and fire it at the Gothon.
His clown costume is flowing and moving around his body, which throws
off your aim. Your laser hits his costume but misses him entirely. This
completely ruins his brand new costume his mother bought him, which
makes him fly into an insane rage and blast you repeatedly in the face until
you are dead. Then he eats you.
SHOT_DOWN
return :death
elsif action == "dodge"
puts <<-STOMPED
Like a world class boxer you dodge, weave, slip and slide right
as the Gothon's blaster cranks a laser past your head.
In the middle of your artful dodge your foot slips and you
bang your head on the metal wall and pass out.
You wake up shortly after only to die as the Gothon stomps on
your head and eats you.
STOMPED
return :death
elsif action == "tell a joke"
puts <<-JOKEY
Lucky for you they made you learn Gothon insults in the academy.
You tell the one Gothon joke you know:
Lbhe zbgure vf fb sng, jura fur fvgf nebhaq gur ubhfr, fur fvgf nebhaq gur ubhfr.
The Gothon stops, tries not to laugh, then busts out laughing and can't move.
While he's laughing you run up and shoot him square in the head
putting him down, then jump through the Weapon Armory door.
JOKEY
return :laser_armory
else
puts "DOES NOT COMPUTE!"
return :central_corridor
end
end
def laser_armory()
puts <<-LASER_DESCRIPTION
You do a dive roll into the Weapon Armory, crouch and scan the room
for more Gothons that might be hiding. It's dead quiet, too quiet.
You stand up and run to the far side of the room and find the
neutron bomb in its container. There's a keypad lock on the box
and you need the code to get the bomb out. If you get the code
wrong 10 times then the lock closes forever and you can't
get the bomb. The code is 3 digits.
LASER_DESCRIPTION
code = "%s%s%s" % [rand(9)+1, rand(9)+1, rand(9)+1]
print "[keypad]> "
guess = gets.chomp()
guesses = 0
if guess == "reset"
puts <<-RESET_DESCRIPTION
You hear a soft click as the neutron bomb's container
opens, revealing the bomb inside. You're not quite sure
how you did it, but you just hacked the Gibson.
RESET_DESCRIPTION
return :bridge_access
elsif
while guess != code and guesses < 10
puts "BZZZZZZEDDDD!"
guesses += 1
print "[keypad]> "
guess = gets.chomp()
end
end
if guess == code
puts <<-CODE_DESCRIPTION
The container clicks open and the seal breaks, releasing a cloud of gas.
You grab the neutron bomb and run as fast as you can to the
bridge where you must place the bomb in the right spot.
CODE_DESCRIPTION
return :bridge_access
else
puts <<-FAILURE_DESCRIPTION
The lock buzzes one last time and then you hear a sickening
melting sound as the mechanism is fused together.
You decide to sit there, and finally the Gothons blow up the
ship from their ship and you die.
FAILURE_DESCRIPTION
return :death
end
end
def bridge_access()
puts <<-BRIDGE_ACCESS
You round the corner, ready to make your way to the bridge and to the escape
pods that lie beyond. Unfortunately, you see a huge pile of debris blocking
your way. Luckily, you can see a panel that covers a maintenance tunnel is
slightly askew. The tunnel appears to be unoccupied, but you can never tell
with Gothons. You could also try to make your way over the pile of debris.
Or you could wait here for the cleaning service to come and clear the trash
out of your way.
BRIDGE_ACCESS
prompt()
action = gets.chomp()
if action == "enter tunnel"
puts <<-TUNNEL_DESCRIPTION
The access tunnel is dark, but you manage to make your way through.
Luckily, it seems those unsettling noises were just the ship coming
apart, and not a hungry alien in a hideous clown costume ready to
leap out and tear you to shreds.
TUNNEL_DESCRIPTION
return :the_bridge
elsif action == "climb debris"
puts <<-DEBRIS_DESCRIPTION
You bravely begin to climb the mountain of rubble, but about halfway
up, you slip and fall. You narrowly miss impaling yourself on a bit of
rebar. Breathing a sigh of relief, you realize you've got bigger problems.
The rubble shifts beneath you, effectively crushing your lower body.
You've got no choice but to wait for the sweet release of death.
DEBRIS_DESCRIPTION
return :death
elsif action == "wait here"
puts <<-WAIT_DESCRIPTION
You realize I was kidding, right?
Leaning up against the wall, you wait for the cleaning crew to arrive.
Fortunately, you don't have to wait long as a team of Gothons are along
momentarily and blast you into vapor.
WAIT_DESCRIPTION
return :death
else
puts "DOES NOT COMPUTE!"
return :bridge_access
end
end
def the_bridge()
puts <<-BRIDGE_DESCRIPTION
You burst onto the Bridge with the neutron destruction bomb
under your arm and surprise 5 Gothons who are trying to
take control of the ship. Each of them has an even uglier
clown costume than the last. They haven't pulled their
weapons out yet, as they see the active bomb under your
arm and don't want to set it off.
BRIDGE_DESCRIPTION
prompt()
action = gets.chomp()
if action == "throw the bomb"
puts <<-THROW_DESCRIPTION
In a panic, you throw the bomb at the group of Gothons
and make a leap for the door. Right as you drop it, a
Gothon shoots you right in the back, killing you.
As you die you see another Gothon frantically try to disarm
the bomb. You die knowing they will probably blow up when
it goes off.
THROW_DESCRIPTION
return :death
elsif action == "slowly place the bomb"
puts <<-PLACE_DESCRIPTION
You point your blaster at the bomb under your arm
and the Gothons put their hands up and start to sweat.
You inch backward to the door, open and then carefully
place the bomb on the floor, pointing your blaster at it.
You then jump back through the door, punch the close button
and blast the lock so the Gothons can't get out.
Now that the bomb is placed, you run to the escape pod to
get off this tin can.
PLACE_DESCRIPTION
return :escape_pod
else
puts "DOES NOT COMPUTE!"
return :the_bridge
end
end
def escape_pod()
puts <<-ESCAPE_POD_DESCRIPTION
You rush through the ship desperately trying to make it to
the escape pod before the whole ship explodes. It seems like
hardly any Gothons are on the ship, so your run is clear of
interference. You get to the chamber with the escape pods, and
now need to pick one to take. Some of them could be damaged
but you don't have time to look. There are 5 pods, which one
do you take?
ESCAPE_POD_DESCRIPTION
good_pod = rand(5)+1
print "[pod# #]>"
guess = gets.chomp()
if guess == "the correct pod"
puts <<-CORRECT_DESCRIPTION
Trusting to instinct, you hop into the pod directly across
the room. Slamming the eject button as soon as the hatch closes,
you quickly leave the ship behind. In the distance, you watch
as it explodes into a fiery supernova. Thankfully, the blast
is too far away to affect your escape pod.
Congratulations! You won!
CORRECT_DESCRIPTION
Process.exit()
elsif guess.to_i != good_pod
puts
puts <<-BAD_POD
"You jump into escape pod #{guess.to_i} and hit the eject button.
The pod escapes out into the void of space, then
implodes as the hull ruptures, crushing your body
into a jelly."
BAD_POD
return :death
else
puts <<-GOOD_POD
You jump into pod #{guess.to_i} and hit the eject button.
The pod easily slides out into space, heading to
the planet below. As it flies to the planet, you look
back and see your ship implode, then explode like a
bright star, taking out the Gothon ship at the same time.
You won!"
GOOD_POD
Process.exit()
end
end
end
a_game = Game.new(:central_corridor)
a_game.play()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment