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
62 changes: 35 additions & 27 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
GEM
remote: http://rubygems.org/
specs:
activemodel (3.2.3)
activesupport (= 3.2.3)
builder (~> 3.0.0)
activerecord (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activesupport (3.2.3)
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
builder (3.0.0)
diff-lcs (1.1.3)
i18n (0.6.0)
multi_json (1.3.4)
pg (0.13.2)
rake (0.9.2.2)
rspec (2.10.0)
rspec-core (~> 2.10.0)
rspec-expectations (~> 2.10.0)
rspec-mocks (~> 2.10.0)
rspec-core (2.10.0)
rspec-expectations (2.10.0)
diff-lcs (~> 1.1.3)
rspec-mocks (2.10.1)
tzinfo (0.3.33)
activemodel (4.0.2)
activesupport (= 4.0.2)
builder (~> 3.1.0)
activerecord (4.0.2)
activemodel (= 4.0.2)
activerecord-deprecated_finders (~> 1.0.2)
activesupport (= 4.0.2)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.2)
i18n (~> 0.6, >= 0.6.4)
minitest (~> 4.2)
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
arel (4.0.1)
atomic (1.1.14)
builder (3.1.4)
diff-lcs (1.2.5)
i18n (0.6.9)
minitest (4.7.5)
multi_json (1.8.4)
pg (0.17.1)
rake (10.1.1)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.7)
rspec-expectations (2.14.4)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.4)
thread_safe (0.1.3)
atomic
tzinfo (0.3.38)

PLATFORMS
ruby
Expand Down
21 changes: 11 additions & 10 deletions adventure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@
require_relative 'db/setup'
require_relative 'models/page'
require_relative 'models/book'
require_relative 'db/seed'

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")

book = Book.new(page)
book = Book.new(Page.where(starting_point: true).first)

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 "\n" + book.current_page.content
puts "\nyour options: "
puts " - [#{Page.find(book.current_page.option_ids.first).preview}]"
puts " - [#{Page.find(book.current_page.option_ids.last).preview}]"
puts "What do you want to do? Enter A or B"

book.input( gets )


end

puts "\n" + book.current_page.content


puts "------------------------------------------"
puts "| |"
puts "| |"
Expand All @@ -30,6 +32,5 @@
puts "------------------------------------------"


puts book.current_page.content

puts "hope you won!"
2 changes: 1 addition & 1 deletion config/database.yml.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
host: 'localhost'
adapter: 'postgresql'
database: 'episode5'
username: XXXXXXX
username: albinosquirrelclimb
encoding: 'utf8'
pool: 5
3 changes: 2 additions & 1 deletion db/migrate/001_creates_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ class CreatesPage < ActiveRecord::Migration
def change
create_table :pages do |t|
t.text :content
t.integer :parent_id
t.text :preview
t.integer :option_ids, array: true, default: []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most excellent use of postgres arrays!

t.boolean :starting_point, default: false
t.boolean :conclusion, default: false
end
Expand Down
35 changes: 34 additions & 1 deletion db/seed.rb
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
# Cleaning Out
#options
#fourth tier
fourthTier_option1 = Page.create(conclusion: true, content: "You have tea with the monkey. Mmmm Earl Grey. You win!", preview: "Sir")

fourthTier_option2 = Page.create(conclusion: true, content: "The monkey does not appreciate you calling him that. He throws his poo at you. You sulk home in disgrace.", preview: "Ma'am")

#third tier
thirdTier_option1 = Page.create(option_ids: [fourthTier_option1.id, fourthTier_option2.id], content: "How should you address the monkey?", preview: "Really? A monkey?" )
#second tier
#path1
secondTier_option1 = Page.create(conclusion: true, content: "The duck gets mad and eats you. That was a terrible Quack", preview: "You quack at the duck.")

secondTier_option2 = Page.create(option_ids: [thirdTier_option1.id], content: "Surprise! A monkey jumps in front of you!", preview: "You pat the duck.")

#path2
secondTier_option3 = Page.create(conclusion: true, content: "Why would you pass up loot? You fall in the water. Eaten by sharks!? bummer!", preview: "Keep walking down the road toward the dock, ignoring the chest.")

secondTier_option4 = Page.create(option_ids: [thirdTier_option1.id], content: "Surprise! A monkey jumps in front of you!", preview: "Bang open the chest with the hammer.")

#firstTier
#path1
firstTier_option1 = Page.create(option_ids: [secondTier_option1.id, secondTier_option2.id], content: "You see a duck", preview: "Walk into the forest")

#path2
firstTier_option2 = Page.create(option_ids: [secondTier_option3.id, secondTier_option4.id], content: "You see a giant chest with a hammer beside it.", preview: "Walk down the road to the dock")

#starting_page
Page.create(starting_point: true, option_ids: [firstTier_option1.id, firstTier_option2.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?")






1 change: 1 addition & 0 deletions db/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
ActiveRecord::Base.establish_connection(connection_details)
# Migrate all the things
ActiveRecord::Migrator.migrate("db/migrate/")

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 = Page.find(current_page.option_ids.first)
elsif input_string.chomp == "B"
@current_page = current_page.options.last
@current_page = Page.find(current_page.option_ids.last)
end
end

Expand Down
5 changes: 0 additions & 5 deletions models/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,4 @@ class Page < ActiveRecord::Base
def self.starting_point
Page.where(starting_point: true).first
end

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

end
7 changes: 3 additions & 4 deletions spec/book_spec.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
require_relative "spec_helper"

describe Book do
let!(:page) {Page.create(starting_point: true)}
let!(:option_a) { Page.create }
let!(:option_b) { Page.create }
let!(:page) {Page.create(starting_point: true, option_ids: [option_a,option_b])}
subject { Book.new(page) }

it "should have a page" do
subject.current_page.should eq(page)
end

describe "#input" do
let!(:option_a) { Page.create(parent_id: page.id)}
let!(:option_b) { Page.create(parent_id: page.id)}

it "should receive input and opens page" do
subject.input("A")
subject.current_page.should eq(option_a)
Expand Down
17 changes: 11 additions & 6 deletions spec/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@
Page.find(page.id).content.should eq("The fox and hound get along")
end

context "#options" do
subject {Page.create}
let(:option_a) {Page.create(parent_id: subject.id) }
let(:option_b) {Page.create(parent_id: subject.id) }
let(:option_c) {Page.create(parent_id: subject.id) }
it "should have a preview" do
page = Page.create(preview: "Step into the forest")
expect(Page.find(page.id).preview).to eq("Step into the forest")
end

context "#options" do
let(:option_a) {Page.create }
let(:option_b) {Page.create }
let(:option_c) {Page.create }
subject {Page.create(option_ids: [option_a, option_b])}

it "should have options for the next pages" do
subject.options.should eq([option_a, option_b])
subject.option_ids.should eq([option_a, option_b])
end
end

Expand Down
22 changes: 18 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
require "rspec"
require 'rspec'
require 'bundler/setup'
require_relative '../db/setup'
require_relative "../models/page"
require_relative "../models/book"
require_relative '../db/setup'


require_relative '../models/page'
require_relative '../models/book'

RSpec.configure do |config|
# Use color in STDOUT
config.color_enabled = true

# Use color not only in STDOUT but also in pagers and files
config.tty = true

# Use the specified formatter
config.formatter = :documentation # :progress, :html, :textmate
end