Skip to content

Instantly share code, notes, and snippets.

@sunlee-newyork
Created January 23, 2013 18:47
Show Gist options
  • Save sunlee-newyork/4611489 to your computer and use it in GitHub Desktop.
Save sunlee-newyork/4611489 to your computer and use it in GitHub Desktop.
class Cyoza
def initialize
start_game
end
def type(string)
sleep 0.5
string.each_char {|x| print x ; sleep 0.05 ; $stdout.flush}
end
def start_game
type("Welcome to Choose Your Own Zombie Adventure!\n")
type("The game will start in... ")
sleep 0.5
3.downto(1).each { |x| print x ; sleep 1 }
type("\nBefore we begin, what is your name?\n")
@player_name = gets.capitalize.chomp
type("Hello, #{@player_name}.\n")
type("You are the only human survivor.\n")
type("GET READY TO UNLEASH YOUR FURY.\n")
type("First of all, do you have your zombie kit? \n")
type("Press [y/n]\n")
inv_prep
end
def ask_to_startover
type("Do you want to start over?\n")
type("Press [y/n]\n")
while player_input = gets.downcase.chomp
if player_input == "y"
restart_game
elsif player_input == "n"
abort("GAME OVER.")
else
type("Sorry, please answer with 'y' or 'n'.")
end
end
end
def restart_game
type("Restarting...")
sleep 0.5
puts "NOW."
sleep 1
start_game
end
def look_for_item0
type("That's no good, #{@player_name}!\n")
type("Let's head over to the local department store and get ourselves a nice shotgun.\n")
type("Ah, we have two options: Walmart or deli.\n")
type("Which do you enter?\n")
STDOUT.flush
while w_search = gets.downcase.chomp
if w_search == "walmart"
player_gets_attacked
elsif w_search == "deli"
type("You make a run for the deli.\n")
type("You pass the front door...\n")
type("...and the owner starts making out with your BRAIIIN.\n")
ask_to_startover
else
type("Walmart or the deli are the two only uncharred buildlings around.\n")
type("Which one will it be?\n")
end
end
end
def inv_prep
while player_input = gets.chomp
if player_input == "y"
ask_item0
elsif player_input == "n"
look_for_item0
else
type("Sorry, please answer with 'y' or 'n'.\n")
end
end
end
def stage_two
type("This marks the end of Chapter 1 in Choose Your Own Zombie Adventure.\n")
type("Congratulations! You have made it this far.\n")
type("Let's see how you'll do in the next chapter, coming soon!\n")
ask_to_startover
end
def display_inv
type("Alright! You now have your battle weapons ready!\n")
type("Here is what you'll be using to kick zombie ass:\n")
sleep 0.5
@inv.push @sec_items
@inv.each do |x|
puts x
end
stage_two
end
def item1_notfound
type("Sorry, please choose one of the following:\n")
@sec_items.each do |x|
puts x
end
end
def ask_item2_fromgrenade
@sec_items.delete_at(0)
type("Awesome, the perfect zombie apocolypse defense!\n")
type("Let's see what you've got in your left pocket.\n")
type("Which one of these did you pull out?\n")
sleep 0.5
@sec_items.each do |x|
puts x
end
STDOUT.flush
while @item2 = gets.downcase.chomp
if @item2 == "medkit"
type("You'll want to keep that head on your shoulder, it seems to be in working condition.\n")
display_inv
elsif @item2 == "banana"
type("Why do you have a banana in your pocket? Maybe it'll come into use... MAYBE.\n")
display_inv
else
item1_notfound
end
end
end
def ask_item2_frommedkit
@sec_items.delete_at(1)
type("You'll want to keep that head on your shoulder, it seems to be in working condition.\n")
type("Let's see what you've got in your left pocket.\n")
type("Which one of these did you pull out?\n")
sleep 0.5
@sec_items.each do |x|
puts x
end
STDOUT.flush
while @item2 = gets.downcase.chomp
if @item2 == "grenade"
type("Awesome, the perfect zombie apocolypse defense!\n")
display_inv
elsif @item2 == "banana"
type("Why do you have a banana in your pocket? Maybe it'll come into use... MAYBE.\n")
display_inv
else
item1_notfound
end
end
end
def ask_item2_frombanana
@sec_items.delete_at(2)
type("Why do you have a banana in your pocket? Maybe it'll come into use... MAYBE.\n")
type("Let's see what you've got in your left pocket.\n")
type("Which one of these did you pull out?\n")
sleep 0.5
@sec_items.each do |x|
puts x
end
STDOUT.flush
while @item2 = gets.downcase.chomp
if @item2 == "grenade"
type("Awesome, the perfect zombie apocolypse defense!\n")
display_inv
elsif @item2 == "medkit"
type("You'll want to keep that head on your shoulder, it seems to be in working condition.\n")
display_inv
else
item1_notfound
end
end
end
def ask_item1
@sec_items = %w[grenade medkit banana]
type("Of the following, which one is in your right pocket?\n")
sleep 0.5
@sec_items.each do |x|
puts x
end
STDOUT.flush
while @item1 = gets.downcase.chomp
if @item1 == "grenade"
ask_item2_fromgrenade
elsif @item1 == "medkit"
ask_item2_frommedkit
elsif @item1 == "banana"
ask_item2_frombanana
else item1_notfound
end
end
end
def ask_item0
@inv = []
type("Great! We need to create an inventory before we kick some zombie ass.\n")
type("Type the weapon currently strapped to your back.\n")
STDOUT.flush
@item0 = gets.downcase.chomp
@inv.push @item0
type("You have saved the #{@item0} in your inventory!\n")
ask_item1
end
def player_gets_attacked
type("Well whaddaya know, Walmart FTW.\n")
type("As you reach for the closest rifle...\n")
type("...zombies start flooding through the back door!!!\n")
type("You run away with the rifle and run into the wall.\n")
type("Do you make a left or right?\n")
STDOUT.flush
while turn = gets.downcase.chomp
if turn == "left"
type("Too bad you chose to make a left...\n")
type("...because that grandma zombie is now feasting on your neck!\n")
ask_to_startover
elsif turn == "right"
type("You swerve around...\n")
type("...and run straight into a loving zombie embrace.\n")
ask_to_startover
else
type("Zombies are right behind you! Is it a left or right?\n")
end
end
end
end
Cyoza.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment