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
46 changes: 24 additions & 22 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
GEM
remote: http://rubygems.org/
specs:
activemodel (3.2.3)
activesupport (= 3.2.3)
activemodel (3.2.13)
activesupport (= 3.2.13)
builder (~> 3.0.0)
activerecord (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
activerecord (3.2.13)
activemodel (= 3.2.13)
activesupport (= 3.2.13)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activesupport (3.2.3)
i18n (~> 0.6)
activesupport (3.2.13)
i18n (= 0.6.1)
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)
builder (3.0.4)
diff-lcs (1.2.2)
i18n (0.6.1)
multi_json (1.7.2)
pg (0.15.0)
pg (0.15.0-x86-mingw32)
rake (10.0.4)
rspec (2.13.0)
rspec-core (~> 2.13.0)
rspec-expectations (~> 2.13.0)
rspec-mocks (~> 2.13.0)
rspec-core (2.13.1)
rspec-expectations (2.13.0)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.13.0)
tzinfo (0.3.37)

PLATFORMS
ruby
x86-mingw32

DEPENDENCIES
activerecord
Expand Down
21 changes: 9 additions & 12 deletions adventure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@
require_relative 'db/setup'
require_relative 'models/page'
require_relative 'models/book'
require "./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.starting_point)

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 "Your options: "
puts " - [#{book.current_page.options.first.preview}]"
puts " - [#{book.current_page.options.last.preview}]"
puts "What do you want to do? Enter A or B"

book.input( gets )
book.input(gets.chomp().capitalize)
Copy link
Member

Choose a reason for hiding this comment

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

ohhh I like the capitalize here.


end
puts book.current_page.content

puts "------------------------------------------"
puts "| |"
puts "| |"
Expand All @@ -30,6 +29,4 @@
puts "------------------------------------------"


puts book.current_page.content

puts "hope you won!"
puts "Hope you won!"
6 changes: 0 additions & 6 deletions config/database.yml.sample

This file was deleted.

3 changes: 3 additions & 0 deletions db/migrate/001_creates_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ class CreatesPage < ActiveRecord::Migration
def change
create_table :pages do |t|
t.text :content
t.text :preview
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
22 changes: 21 additions & 1 deletion db/seed.rb
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
# Cleaning Out
Page.delete_all

#woods = Page.create(conclusion: true, preview: "Explore the woods",
# content: "You are attacked by a hungry bear who smells bacon. You lose.")
campfire = Page.create(conclusion: true, preview: "Approach the campfire",
content: "Bandits steal your bag. You lose everything!!")
sit = Page.create(conclusion: true, preview: "Sit down to eat your sandwich",
content: "You are attacked by a hungry bear who smells bacon. You lose.")
walk = Page.create(conclusion: true, preview: "Keep walking",
content: "You made it back to the inn safely. You win 100 gold pieces!!")

forest = Page.create(option_a_id: sit.id, option_b_id: campfire.id,
preview: "Go into the forest",
content: "You see a campfire in the distance.")
road = Page.create(option_a_id: sit.id, option_b_id: walk.id,
preview: "Walk down the road",
content: "You are hungry.")

start = Page.create(starting_point: true, option_a_id: forest.id, option_b_id: road.id,
preview: "Welcome, adventurer.",
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?")
2 changes: 1 addition & 1 deletion db/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# connect to it
ActiveRecord::Base.establish_connection(connection_details)
# Migrate all the things
ActiveRecord::Migrator.migrate("db/migrate/")
ActiveRecord::Migrator.migrate("db/migrate/")
4 changes: 3 additions & 1 deletion models/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ def self.starting_point
end

def options
Page.where(:parent_id => id).limit(2)
#Page.where(:parent_id => id).limit(2)
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather delete commented code than leave it in... you ended up on using the Page.find with an array, that's awesome.

#[ Page.where(:id => option_a_id).limit(1), Page.where(:id => option_b_id).limit(1)]
Page.find(option_a_id, option_b_id)
end

end
7 changes: 4 additions & 3 deletions spec/book_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
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_a_id: option_a.id,
option_b_id: option_b.id)}
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")
Expand Down
13 changes: 9 additions & 4 deletions spec/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@
Page.find(page.id).content.should eq("The fox and hound get along")
end

it "should have a preview" do
page = Page.create(preview: "Awesome preview")
Page.find(page.id).preview.should eq("Awesome preview")
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) }
let(:option_a) {Page.create(preview: "Preview for option_a")}
let(:option_b) {Page.create(preview: "Preview for option_b") }
let(:option_c) {Page.create(preview: "Preview for option_c") }
subject {Page.create(option_a_id: option_a.id, option_b_id: option_b.id)}

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