Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panda tasks #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ doc/

config/database.yml
TODO

.idea
27 changes: 12 additions & 15 deletions adventure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,27 @@
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: "Go into the forest", win: true)
Page.create(conclusion: true, parent_id: page.id, content: "Walk down the road")

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 " Option A: [#{book.current_page.options.first.content}]"
puts " Option B: [#{book.current_page.options.last.content}]"
puts "What do you want to do? Enter A or B"

book.input( gets )

puts
puts book.current_page.preview
if book.current_page.win
puts 'You Win! You find the Fountain of Youth!'
else
puts 'You Lose! You are robbed and killed by evil ninjas..'
Copy link
Member

Choose a reason for hiding this comment

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

evil ninjas! OH NOES.

end
end
puts "------------------------------------------"
puts "| |"
puts "| |"
puts "| ADVENTURE COMPLETE |"
puts "| |"
puts "| |"
puts "------------------------------------------"


puts book.current_page.content

puts "hope you won!"
puts
puts " The End! "
1 change: 1 addition & 0 deletions db/migrate/001_creates_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def change
t.integer :parent_id
t.boolean :starting_point, default: false
t.boolean :conclusion, default: false
t.boolean :win, default: false
end
end
end
6 changes: 5 additions & 1 deletion models/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ def self.starting_point

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

def preview
'You ' + content + '...'
end

end
38 changes: 24 additions & 14 deletions spec/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,38 @@
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 options for the next pages" do
subject.options.should eq([option_a, option_b])
end
end

describe "instance methods" do
subject {Page.create}
let(:option_a) {Page.create(parent_id: subject.id, content: 'Go to the store', win: true) }
let(:option_b) {Page.create(parent_id: subject.id, content: 'Take a nap') }
let(:option_c) {Page.create(parent_id: subject.id) }

context "#options" do
it "should have options for the next pages" do
subject.options.should eq([option_a, option_b])
end
end

context "#preview" do
it "should show preview" do
option_a.preview.should eq('You Go to the store...')
end
end
end

it "should not be a winning page by default" do
a_page = Page.create
a_page.win?.should_not be_true
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" do
the_page = Page.create(starting_point: true)
Page.starting_point.should eq(the_page)
end
end

end