Skip to content

Instantly share code, notes, and snippets.

@missingno15
Last active December 23, 2015 19:09
Show Gist options
  • Save missingno15/6680426 to your computer and use it in GitHub Desktop.
Save missingno15/6680426 to your computer and use it in GitHub Desktop.
Recreating the famous Professor Oak Intro from the Pokémon games http://www.youtube.com/watch?v=6jqUMlyvhcU
# Recreating the famous Professor Oak Intro from Pokemon
# http://www.youtube.com/watch?v=6jqUMlyvhcU
# Asks the user for input based on their gender. Must reply with either
# "boy" or "girl" in lower case.
def gender
puts
puts "Now tell me. Are you a boy?\nOr are you a girl?"
print "> "; sex = gets.chomp.upcase!
puts
gender unless sex == "BOY" || sex == "GIRL"
end
# Asks and confirms the player for their name. Name is first stored in a
# certain position in the @game_text array and unless the user input receives
# anything but "yes", then the initial input is deleted and this section runs itself again
# until the correct player_name is given.
def p_check
puts "Let's begin with your name.\nWhat is it?\n\nYour name?"
print "> "; player_name = gets.chomp
@game_text.insert(12, "#{player_name}!")
puts
puts "Right...\nSo your name is #{player_name}.\n\n{YES / NO}"
print "> "; confirm = gets.chomp.upcase!
puts
unless confirm == "YES" || confirm == "NO"
@game_text.delete_at(12)
p_check
end
if confirm == "NO"
@game_text.delete_at(12)
p_check
end
end
# Asks and confirms the rival's name from the player. Anything other than "yes" or "no"
# activates the confirm print "> " again. And if the input for confirm is "no", block restarts itself
# until correct rival name is given.
def rival
puts "\n...Erm, what was his name now?\n\nRIVAL's NAME?"
print "> "; rival_name = gets.chomp
puts
puts "...Er, was it #{rival_name}?\n\n{YES / NO}"
print "> "; confirm = gets.chomp.upcase!
puts
until confirm == "YES" || confirm == "NO"
puts "...Er, was it #{rival_name}?\n\n{YES / NO}"
print "> "; confirm = gets.chomp.upcase!
puts
end
if confirm == "NO"
rival
else
puts "That's right! I remember now!\nHis name is #{rival_name}!"
end
end
# Text taken from Pokemon FireRed/LeafGreen dialouge when Prof. Oak gives you an intro
@game_text = [
"Hello there!\nGlad to meet you!",
"Welcome to the world of POKéMON!",
"My name is OAK", "People affectionately refer to me as the POKéMON PROFESSOR",
"This world...","...is inhabited far and wide by creatures called POKéMON.",
"For some people, POKéMON are pets.\nOthers use them for battling.", "As for myself...",
"I study PokéMON as a profession.", "But first, tell me a bit about yourself",
"This is my grandson", "He's been your rival since you both were babies.",
"", "Your very own POKéMON legend is about to unfold!",
"A world of dreams and adventures with POKéMON awaits! Let's go!",
"\n\nInspired by the Professor Oak Intro and coded by missingno15 / Kenneth Uy."
]
###########################################################################
# To make the text seem like the real game as much as possible, the player must
# press the ENTER key to advance the game just like one would if playing
# the game on an Nintendo handheld console pressing the A or B button.
# Directory to background music for this part of the game
# For some reason, the program won't run unless I put the following snippet first
file_to_open = "/Users/kenny/Desktop/rubyshit/route24&25.mp3"
puts system %{open "#{file_to_open}"}
puts "Press ENTER to begin"
@game_text[0..9].each {|text| puts "#{text}" if gets == "\n"}
gender
p_check
@game_text[10..11].each { |text| puts "#{text}" if gets == "\n" }
rival
@game_text[12..16].each { |text| puts "#{text}" if gets == "\n" }
################################################################################################
#
# Some helpful links that I found and used to help me build this script
#
# http://stackoverflow.com/questions/10355477/is-there-an-opposite-of-include-for-ruby-arrays
# http://stackoverflow.com/questions/4130280/ruby-gets-enter-key
# http://stackoverflow.com/questions/4010039/equivalent-of-continue-in-ruby
# http://www.ruby-doc.org/core-2.0.0/Array.html#label-Accessing+Elements
# Using until loops - http://www.tutorialspoint.com/ruby/ruby_loops.htm
# http://stackoverflow.com/questions/9476291/how-to-open-file-in-default-application-ruby
#
################################################################################################
@drewbaumann
Copy link

If I were you I would make @game_text a hash for readability if nothing else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment