diff --git a/Gemfile.lock b/Gemfile.lock index 0facad0..1f2cb79 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/adventure.rb b/adventure.rb index d65f616..cac320b 100644 --- a/adventure.rb +++ b/adventure.rb @@ -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) end +puts book.current_page.content + puts "------------------------------------------" puts "| |" puts "| |" @@ -30,6 +29,4 @@ puts "------------------------------------------" -puts book.current_page.content - -puts "hope you won!" +puts "Hope you won!" diff --git a/config/database.yml.sample b/config/database.yml.sample deleted file mode 100644 index 2e5c2a9..0000000 --- a/config/database.yml.sample +++ /dev/null @@ -1,6 +0,0 @@ -host: 'localhost' -adapter: 'postgresql' -database: 'episode5' -username: XXXXXXX -encoding: 'utf8' -pool: 5 diff --git a/db/migrate/001_creates_page.rb b/db/migrate/001_creates_page.rb index 8a293c0..0f3b6bd 100644 --- a/db/migrate/001_creates_page.rb +++ b/db/migrate/001_creates_page.rb @@ -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 diff --git a/db/seed.rb b/db/seed.rb index 1abe902..39d2708 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -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?") diff --git a/db/setup.rb b/db/setup.rb index 0e80690..1cbf7ce 100644 --- a/db/setup.rb +++ b/db/setup.rb @@ -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/") \ No newline at end of file diff --git a/models/page.rb b/models/page.rb index 2b88343..dccb93a 100644 --- a/models/page.rb +++ b/models/page.rb @@ -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) + #[ 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 diff --git a/spec/book_spec.rb b/spec/book_spec.rb index b429112..2152929 100644 --- a/spec/book_spec.rb +++ b/spec/book_spec.rb @@ -1,7 +1,10 @@ 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 @@ -9,8 +12,6 @@ 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") diff --git a/spec/page_spec.rb b/spec/page_spec.rb index 5951cdd..d89f268 100644 --- a/spec/page_spec.rb +++ b/spec/page_spec.rb @@ -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])