Skip to content

Instantly share code, notes, and snippets.

@illbzo1
illbzo1 / The Tomb of Unfathomable Horror
Created October 16, 2011 21:50
Text-based Dungeon Adventure
# creates an empty array for the user's inventory
@inventory = []
# this is the command prompt method
def prompt()
print "Enter command > "
end
# shows a list of viable commands when a user enters "help" at the command prompt
def help()
@illbzo1
illbzo1 / Gothon_Game
Created October 27, 2011 00:13
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
@illbzo1
illbzo1 / madlib
Created October 29, 2011 00:32
Simple MadLibs generator
def prompt
print "> "
end
def generate_mad_lib
puts "Bear with me. I'm going to need 18 singular @nouns."
prompt;
@noun1 = gets.chomp()
@noun2 = gets.chomp()
@noun3 = gets.chomp()
@illbzo1
illbzo1 / madlibs
Created October 30, 2011 17:30
Refactored Madlibs generator
def generate_mad_lib
puts "Bear with me. I'm going to need 16 singular nouns."
@nouns = []
16.times { @nouns << gets.chomp }
puts "Awesome, now I'm going to need 6 plural nouns."
@plural_nouns = []
6.times { @plural_nouns << gets.chomp }
puts "Ok, now let's collect some singular verbs. I'm looking for 7 of them."
@illbzo1
illbzo1 / madlibs
Created October 30, 2011 23:08
Madlibs Generator, Second Refactoring
def generate_mad_lib
puts "Bear with me. I'm going to need 16 singular nouns."
@nouns = []
16.times { @nouns << gets.chomp }
@nouns = @nouns.reverse
puts "Awesome, now I'm going to need 6 plural nouns."
@plural_nouns = []
6.times { @plural_nouns << gets.chomp }
@plural_nouns = @plural_nouns.reverse
@illbzo1
illbzo1 / madlib.rb
Created November 8, 2011 03:15
Madlibs Generator, Objectified
@counter = 0
files = Dir.glob("*.madlib")
if files.size > 1
puts "CHOOSE YOUR FILE:"
x = 0
files.each do |file|
x += 1
puts "#{x}. #{file}"
@illbzo1
illbzo1 / aan
Created November 10, 2011 02:37
Random Phrase Generator
files = Dir.glob("*.txt")
adjective_list1 = IO.readlines("adj1.txt")
adjective_list2 = IO.readlines("adj2.txt")
noun_list = IO.readlines("noun.txt")
prefix_list = IO.readlines("prefix.txt")
suffix_list = IO.readlines("suffix.txt")
rand1 = rand(adjective_list1.length)
rand2 = rand(adjective_list2.length)
@illbzo1
illbzo1 / aan.rb
Created November 15, 2011 02:42
Random Phrase Generator, Refactored
require 'yaml'
words = YAML::load(File.open('words.yml'))
loop do
puts "Generate new phrase? (y / n)"
input = gets.chomp()
unless input == "n"
new_phrase = %w[adj2 noun].map { |type| words[type].sample }
addition = rand(7)
@illbzo1
illbzo1 / An example of the form method from a view
Created December 14, 2011 02:33
Working with form methods in Sinatra
<form method="get" action="/input">
<input type="text" name="input" />
<input type="submit" value="Submit" />
</form>
@illbzo1
illbzo1 / Example code
Created December 22, 2011 03:48
Still working on Dungeon Crawler redirection
# trying to set a method so I can use @input in other methods
class Input
def initialize(input)
@input = params[:input]
end
end
# collecting the input with a form here
get '/input' do
@input = params[:input]