From 562a496175d8e8d0482850bd27e7ed5d7430d328 Mon Sep 17 00:00:00 2001 From: "J. Michael Kasiewicz" Date: Wed, 12 Dec 2012 12:36:42 -0500 Subject: [PATCH 1/3] Panda --- adventure.rb | 16 +++++++--------- db/migrate/001_creates_page.rb | 1 + 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/adventure.rb b/adventure.rb index d65f616..4931582 100644 --- a/adventure.rb +++ b/adventure.rb @@ -6,21 +6,24 @@ 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") +Page.create(conclusion: true, parent_id: page.id, preview: "Go into the forest", content: "You find that the forest is endless maze of confusing paths. You spend the rest of your days trying to find a way out. RIP") +Page.create(conclusion: true, parent_id: page.id, preview: "Walk 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!!!") 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.options.first.preview}]" + puts "B - [#{book.current_page.options.last.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..c18b503 100644 --- a/db/migrate/001_creates_page.rb +++ b/db/migrate/001_creates_page.rb @@ -1,6 +1,7 @@ class CreatesPage < ActiveRecord::Migration def change create_table :pages do |t| + t.text :preview t.text :content t.integer :parent_id t.boolean :starting_point, default: false From 22e74b44d7b924990703e5eaa485606635df3799 Mon Sep 17 00:00:00 2001 From: "J. Michael Kasiewicz" Date: Wed, 12 Dec 2012 14:38:32 -0500 Subject: [PATCH 2/3] Tiger --- Gemfile.lock | 2 +- adventure.rb | 6 +++--- db/seed.rb | 7 +++++++ 3 files changed, 11 insertions(+), 4 deletions(-) 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 4931582..e515045 100644 --- a/adventure.rb +++ b/adventure.rb @@ -1,14 +1,14 @@ 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, preview: "Go into the forest", content: "You find that the forest is endless maze of confusing paths. You spend the rest of your days trying to find a way out. RIP") -Page.create(conclusion: true, parent_id: page.id, preview: "Walk 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!!!") +require './db/seed' +page = Page.starting_point book = Book.new(page) until book.complete_game? do diff --git a/db/seed.rb b/db/seed.rb index 1abe902..3287654 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1 +1,8 @@ # Cleaning Out +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?") +page2 = Page.create(parent_id: page.id, preview: "Go into the forest", content: "You find that the forest is a maze of confusing paths.") +Page.create(conclusion: true, parent_id: page2.id, 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") +Page.create(conclusion: true, parent_id: page2.id, 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") +page3 = Page.create(parent_id: page.id, preview: "Walk down the road", content: "This road doesn't seem to be going anywhere.") +Page.create(conclusion: true, parent_id: page3.id, 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") +Page.create(conclusion: true, parent_id: page3.id, 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!!!") From 65caa56417fbea2f71701670c1a56eda77d0da93 Mon Sep 17 00:00:00 2001 From: "J. Michael Kasiewicz" Date: Wed, 12 Dec 2012 20:22:46 -0500 Subject: [PATCH 3/3] Eagle --- adventure.rb | 4 ++-- db/migrate/001_creates_page.rb | 3 ++- db/seed.rb | 19 ++++++++++++------- models/book.rb | 4 ++-- models/page.rb | 8 ++++++-- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/adventure.rb b/adventure.rb index e515045..2419206 100644 --- a/adventure.rb +++ b/adventure.rb @@ -14,8 +14,8 @@ until book.complete_game? do puts book.current_page.content puts "your options: " - puts "A - [#{book.current_page.options.first.preview}]" - puts "B - [#{book.current_page.options.last.preview}]" + 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 ) diff --git a/db/migrate/001_creates_page.rb b/db/migrate/001_creates_page.rb index c18b503..0204743 100644 --- a/db/migrate/001_creates_page.rb +++ b/db/migrate/001_creates_page.rb @@ -3,7 +3,8 @@ 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 3287654..22f9cf2 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1,8 +1,13 @@ # Cleaning Out -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?") -page2 = Page.create(parent_id: page.id, preview: "Go into the forest", content: "You find that the forest is a maze of confusing paths.") -Page.create(conclusion: true, parent_id: page2.id, 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") -Page.create(conclusion: true, parent_id: page2.id, 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") -page3 = Page.create(parent_id: page.id, preview: "Walk down the road", content: "This road doesn't seem to be going anywhere.") -Page.create(conclusion: true, parent_id: page3.id, 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") -Page.create(conclusion: true, parent_id: page3.id, 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!!!") +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