Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- color --format progress
23 changes: 10 additions & 13 deletions adventure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,29 @@
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")

page = Page.starting_point
book = Book.new(page)

until book.complete_game? do
puts "------------------------------------------"
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 )

book.input( gets )
puts "------------------------------------------"
puts book.current_page.outcome
puts "------------------------------------------"
end
puts book.current_page.content
puts "------------------------------------------"
puts "| |"
puts "| |"
puts "| ADVENTURE COMPLETE |"
puts "| |"
puts "| |"
puts "------------------------------------------"


puts book.current_page.content

puts "hope you won!"
5 changes: 4 additions & 1 deletion 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.integer :parent_id
t.string :preview
t.string :outcome
t.integer :option_a_id
t.integer :option_b_id
t.boolean :starting_point, default: false
t.boolean :conclusion, default: false
end
Expand Down
28 changes: 28 additions & 0 deletions db/seed.rb
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
# Cleaning Out
Page.delete_all
page_two = Page.create(conclusion: true,
preview: "Go into the forest",
outcome: "You were methodically consumed by ZOMBIE DEER!!!",
content: "As soon as you stepped off the road, darkness consumed you. You tripped, fell to the ground, and a hoard of zombie deer proceeded to gobble you up.")
page_three = Page.create(conclusion: true,
preview: "Walk down the road",
outcome: "You found the circle of life (can be traded at Trapper's Den for 2 gold pieces)!",
content: "Apparently, after receiving it from his father, Simba dropped the circle of life while chasing a zombie deer.")
page_six = Page.create(option_a_id: page_two.id,
option_b_id: page_three.id,
preview: "Take a moment and taste the bacon fat in your mouth",
outcome: "Your spirits are lifted and you are ready to take on the world!",
content: "Armed with the power to take on the known world, you set forth.")
page_four = Page.create(option_a_id: page_six.id,
option_b_id: page_two.id,
preview: "Admire the 30 gold pieces",
outcome: "You were ransacked and robbed by a hoard of geriatric orcs!",
content: "They came at you slow, but because you were sucked into the glow of the gold you didn't notice 3 old orcs guided by walkers(with the little tennis balls on the fronts). You eat the bacon sandwich.")
page_five = Page.create(option_a_id: page_two.id,
option_b_id: page_six.id,
preview: "Eat the bacon sandwich",
outcome: "Your belly is happy and your mind is clear.",
content: "Obviously the only choice. Now that you've chosen wiser than Indiana Jones and the Quest For the Holy Grail, you are left with only the best decisions.")
Copy link
Member

Choose a reason for hiding this comment

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

page_five RULES 🤘

page = Page.create(starting_point: true,
option_a_id: page_four.id,
option_b_id: page_five.id,
content: "You wake up on a road. It's foggy and damp. In your bag is 30 gold pieces and a bacon sandwich. Which do you choose?")
2 changes: 1 addition & 1 deletion models/book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(starting_page)
end

def input(input_string)
if input_string.chomp == "A"
if input_string.chomp == "A"
@current_page = current_page.options.first
elsif input_string.chomp == "B"
@current_page = current_page.options.last
Expand Down
2 changes: 1 addition & 1 deletion models/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def self.starting_point
end

def options
Page.where(:parent_id => id).limit(2)
Page.find(option_a_id, option_b_id)
Copy link
Member

Choose a reason for hiding this comment

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

Good use of find with an array :)

end

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

it "should have a preview" do
page = Page.create(preview: "Walk down the road")
Page.find(page.id).preview.should eq("Walk down the road")
end

it "should be clear about being a winner or a loser" do
page = Page.create(outcome: "You be dead!")
Page.find(page.id).outcome.should eq("You be dead!")
Copy link
Member

Choose a reason for hiding this comment

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

hmm, I would think this might read a little easier

page = Page.create(outcome: "You be dead!")
page.outcome.should eq("You be dead!")

Any reason to explicitly get a new object from the db?

Copy link
Author

Choose a reason for hiding this comment

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

Nope... I suppose that would be bringing in details not needed.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, while there's no great harm in doing it, it might show future-you a false positive 6 months down the road. You could read, and think there was a REASON that you reloaded from the DB, when in fact it was just a thing.

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 }
let(:option_b) { Page.create }
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