Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ GEM
i18n (0.6.0)
multi_json (1.3.4)
pg (0.13.2)
rake (0.9.2.2)
rake (10.0.2)
rspec (2.10.0)
rspec-core (~> 2.10.0)
rspec-expectations (~> 2.10.0)
Expand Down
18 changes: 8 additions & 10 deletions adventure.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
require 'rubygems'
require 'bundler/setup'


require_relative 'db/setup'
require_relative 'models/page'
require_relative 'models/book'

page = Page.create(starting_point: true, content: "You wake up on a road. It's foggy and dampy. In your bag is 30 gold pieces and a bacon sandwich. Which do you choose?")
Page.create(conclusion: true, parent_id: page.id, content: "Go into the forest")
Page.create(conclusion: true, parent_id: page.id, content: "Walk down the road")
require './db/seed'

page = Page.starting_point
book = Book.new(page)

until book.complete_game? do
puts book.current_page.content
puts "your options: "
puts " - [#{book.current_page.options.first.content}]"
puts " - [#{book.current_page.options.last.content}]"
puts "A - [#{book.current_page.option_a.preview}]"
puts "B - [#{book.current_page.option_b.preview}]"
puts "What do you want to do? Enter A or B"

book.input( gets )

end

puts book.current_page.content

puts "------------------------------------------"
puts "| |"
puts "| |"
puts "| ADVENTURE COMPLETE |"
puts "| |"
puts "| |"
puts "------------------------------------------"


puts book.current_page.content

puts "hope you won!"
4 changes: 3 additions & 1 deletion db/migrate/001_creates_page.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
class CreatesPage < ActiveRecord::Migration
def change
create_table :pages do |t|
t.text :preview
t.text :content
t.integer :parent_id
t.integer :option_a_id
t.integer :option_b_id
t.boolean :starting_point, default: false
t.boolean :conclusion, default: false
end
Expand Down
12 changes: 12 additions & 0 deletions db/seed.rb
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
# Cleaning Out
page2_option_a = Page.create(conclusion: true, preview: "Go futher into the forest", content: "The forest endlessly unfolds into an illogical maze of overgrown paths. You spend the rest of your days trying to find a way out. RIP")
page2_option_b = Page.create(conclusion: true, preview: "Turn around and head back to the road", content: "The forest endlessly unfolds into an illogical maze of overgrown paths. You spend the rest of your days trying to find a way out. RIP")
page2 = Page.create(option_a_id: page2_option_a.id, option_b_id: page2_option_b.id, preview: "Go into the forest", content: "You find that the forest is a maze of confusing paths.")


page3_option_a = Page.create(conclusion: true, preview: "Head into the woods and find a shortcut", content: "The forest endlessly unfolds into an illogical maze of overgrown paths. You spend the rest of your days trying to find that shortcut, smartypants. RIP")
page3_option_b = Page.create(conclusion: true, preview: "Continue down the road", content: "As you walk, you notice something glimmer on the horizon. You approach and find a pile of gold pieces the size of your parent's house. You can finally move out. YOU WIN!!!")
page3 = Page.create(option_a_id: page3_option_a.id, option_b_id: page3_option_b.id, preview: "Walk down the road", content: "This road doesn't seem to be going anywhere.")

page = Page.create(starting_point: true, option_a_id: page2.id, option_b_id: page3.id, content: "You wake up on a road. It's foggy and dampy. In your bag is 30 gold pieces and a bacon sandwich. Which do you choose?")

Page.update(page2_option_a.id, conclusion: false, option_a_id: page3.id, option_b_id: page2.id, preview: "Go futher into the forest", content: "It seems you've reached the other side of the forest and are back on the road.")
4 changes: 2 additions & 2 deletions models/book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def initialize(starting_page)

def input(input_string)
if input_string.chomp == "A"
@current_page = current_page.options.first
@current_page = current_page.option_a
elsif input_string.chomp == "B"
@current_page = current_page.options.last
@current_page = current_page.option_b
end
end

Expand Down
8 changes: 6 additions & 2 deletions models/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ def self.starting_point
Page.where(starting_point: true).first
end

def options
Page.where(:parent_id => id).limit(2)
def option_a
Page.where(id: option_a_id).first
end

def option_b
Page.where(id: option_b_id).first
end

end