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
28 changes: 28 additions & 0 deletions adv.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'rubygems'
require 'bundler/setup'

require_relative 'db/setup'
Dir.glob('./models/*').each { |r| require r}
require "./db/seed"
#require_relative 'models/page'
#require_relative 'models/book'



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.preview}]"
puts " - [#{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 book.current_page.conclusion
35 changes: 0 additions & 35 deletions adventure.rb

This file was deleted.

6 changes: 0 additions & 6 deletions config/database.yml.sample

This file was deleted.

18 changes: 10 additions & 8 deletions db/migrate/001_creates_page.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
class CreatesPage < ActiveRecord::Migration
def change
create_table :pages do |t|
t.text :content
t.integer :parent_id
t.boolean :starting_point, default: false
t.boolean :conclusion, default: false
end
end
def change
create_table :pages do |t|
t.text :preview
t.text :content
t.integer :parent_id
t.boolean :starting_point, default: false
t.boolean :conclusion, default: false
end
end
end

15 changes: 14 additions & 1 deletion db/seed.rb
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
# Cleaning Out

Page.delete_all
page = Page.create(starting_point: true, preview: 'Adventure road', content: "you wake up on a road.
It's foggy and dampy. In your bag is 30 gold pieces and bacon sandwich. Which do you choose?")
Page.create(conclusion: true, parent_id: page.id, preview: "Go into the Forest", content: "Omg...you just won 30 bags of gold: WINNER")
Page.create(conclusion: true, parent_id: page.id, preview: "Sail across the River", content: "Shat...you just got ripped to pieces by a clan of hungry paranas. LOSER")
Copy link
Member

Choose a reason for hiding this comment

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

👍 for 'shat'

LOL


#forrest = Page.create(conclusion: true, id: forrest.id, preview: '', content '')





#id: forrest.id
2 changes: 1 addition & 1 deletion db/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
26 changes: 13 additions & 13 deletions models/book.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
class Book

attr_reader :current_page
attr_reader :current_page

def initialize(starting_page)
@current_page = starting_page
end
end

def input(input_string)
if input_string.chomp == "A"
@current_page = current_page.options.first
elsif input_string.chomp == "B"
@current_page = current_page.options.last
end
end
def input(input_string)
if input_string.chomp == "A"
@current_page = current_page.options.first
elsif input_string.chomp == "B"
@current_page = current_page.options.last
end
end

def complete_game?
current_page.conclusion?
end
def complete_game?
current_page.conclusion?

end
end
end
15 changes: 9 additions & 6 deletions models/page.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
class Page < ActiveRecord::Base

def self.starting_point
Page.where(starting_point: true).first
end

def self.starting_point
Page.where(starting_point: true).first
end

def options
Page.where(:parent_id => id).limit(2)
end

def options
Page.where(:parent_id => id).limit(2)
end
# limit(5)
# index the pages. instead of doing first/last
end
51 changes: 26 additions & 25 deletions spec/book_spec.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
require_relative "spec_helper"

describe Book do
let!(:page) {Page.create(starting_point: true)}
subject { Book.new(page) }
let!(:page) {Page.create(starting_point: true)}
subject { Book.new(page) }

it "should have a page" do
subject.current_page.should eq(page)
end
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)}
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)
end
it "should receive input and opens page" do
subject.input("B")
subject.current_page.should eq(option_b)
end
it "should receive input and opens page" do
subject.input("A")
subject.current_page.should eq(option_a)
end
it "should receive input and opens page" do
subject.input("B")
subject.current_page.should eq(option_b)
end

end

describe "#complete_game?" do

it "should know when it's done" do
subject.stub(:current_page) { stub(:conclusion? => true)}
subject.complete_game?.should be_true
end
end
end

describe "#complete_game?" do
let!(:page) {Page.create(starting_point: true)}
subject { Book.new(page) }
it "should know when it's done" do
subject.stub(:current_page) { stub(:conclusion? => true)}
subject.complete_game?.should be_true
end
end
end
45 changes: 25 additions & 20 deletions spec/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,43 @@
Page.delete_all
end

it "should know if it's at the end of the road" do
it "should know it's at the end of the road" do
page = Page.create(conclusion: true)
page.conclusion?.should be_true

end

it "should have awesome content" do
page = Page.create(content: "The fox and hound get along")
Page.find(page.id).content.should eq("The fox and hound get along")
end
end

context "#options" do
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(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 options for the next pages" do
subject.options.should eq([option_a, option_b])
end
end
it "should have options for the next pages" do
subject.options.should eq([option_a, option_b])
end
end

it "should not be a starting point by default" do
Page.create.starting_point.should eq(false)
end
it "should not be a conclusion by default" do
Page.create.conclusion.should eq(false)
end
it "should have a starting point by default" do
Page.create.starting_point.should eq(false)
end

it "should not be a conclusion by default" do
Page.create.conclusion.should eq(false)
end

it "should have a starting point" do
the_page = Page.create(starting_point: true)
Page.starting_point.should eq(the_page)
end
it "should have a starting point" do
the_page = Page.create(starting_point: true)
Page.starting_point.should eq(the_page)

end
end




2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "rspec"
require 'bundler/setup'
require_relative '../db/setup'
require_relative '../db/setup'
require_relative "../models/page"
require_relative "../models/book"