diff --git a/Gemfile.lock b/Gemfile.lock index 0facad0..e885584 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/adventure.rb b/adventure.rb index d65f616..d88a365 100644 --- a/adventure.rb +++ b/adventure.rb @@ -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 "| |" @@ -30,6 +32,5 @@ puts "------------------------------------------" -puts book.current_page.content puts "hope you won!" diff --git a/config/database.yml.sample b/config/database.yml.sample index 2e5c2a9..0646f88 100644 --- a/config/database.yml.sample +++ b/config/database.yml.sample @@ -1,6 +1,6 @@ host: 'localhost' adapter: 'postgresql' database: 'episode5' -username: XXXXXXX +username: albinosquirrelclimb encoding: 'utf8' pool: 5 diff --git a/db/migrate/001_creates_page.rb b/db/migrate/001_creates_page.rb index 8a293c0..f6fff97 100644 --- a/db/migrate/001_creates_page.rb +++ b/db/migrate/001_creates_page.rb @@ -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: [] t.boolean :starting_point, default: false t.boolean :conclusion, default: false end diff --git a/db/seed.rb b/db/seed.rb index 1abe902..77c2ac4 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -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?") + + + + + + diff --git a/db/setup.rb b/db/setup.rb index 0e80690..44fc53e 100644 --- a/db/setup.rb +++ b/db/setup.rb @@ -13,3 +13,4 @@ ActiveRecord::Base.establish_connection(connection_details) # Migrate all the things ActiveRecord::Migrator.migrate("db/migrate/") + diff --git a/models/book.rb b/models/book.rb index 5eb6f53..d9beca8 100644 --- a/models/book.rb +++ b/models/book.rb @@ -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 diff --git a/models/page.rb b/models/page.rb index 2b88343..f80d2f4 100644 --- a/models/page.rb +++ b/models/page.rb @@ -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 diff --git a/spec/book_spec.rb b/spec/book_spec.rb index b429112..1d54c60 100644 --- a/spec/book_spec.rb +++ b/spec/book_spec.rb @@ -1,7 +1,9 @@ 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 @@ -9,9 +11,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") subject.current_page.should eq(option_a) diff --git a/spec/page_spec.rb b/spec/page_spec.rb index 5951cdd..8716068 100644 --- a/spec/page_spec.rb +++ b/spec/page_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bdb95b8..0e05571 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 +