diff --git a/Gemfile.lock b/Gemfile.lock index 0facad0..a0e9251 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/adventure.rb b/adventure.rb index d65f616..2419206 100644 --- a/adventure.rb +++ b/adventure.rb @@ -1,26 +1,29 @@ 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 "| |" @@ -28,8 +31,3 @@ puts "| |" puts "| |" puts "------------------------------------------" - - -puts book.current_page.content - -puts "hope you won!" diff --git a/db/migrate/001_creates_page.rb b/db/migrate/001_creates_page.rb index 8a293c0..0204743 100644 --- a/db/migrate/001_creates_page.rb +++ b/db/migrate/001_creates_page.rb @@ -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 diff --git a/db/seed.rb b/db/seed.rb index 1abe902..22f9cf2 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -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.") diff --git a/models/book.rb b/models/book.rb index 5eb6f53..49bc03c 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 = current_page.option_a elsif input_string.chomp == "B" - @current_page = current_page.options.last + @current_page = current_page.option_b end end diff --git a/models/page.rb b/models/page.rb index 2b88343..4e409ed 100644 --- a/models/page.rb +++ b/models/page.rb @@ -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