-
Notifications
You must be signed in to change notification settings - Fork 21
Panda Complete #10
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
Open
var114
wants to merge
5
commits into
RubyoffRails:master
Choose a base branch
from
var114:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Panda Complete #10
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'rubygems' | ||
require 'bundler/setup' | ||
|
||
require_relative 'db/setup' | ||
Dir.glob('./models/*').each { |r| require r} | ||
require "./db/seed" | ||
|
||
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 '' | ||
puts 'Maybe you can come back again if you\'re not too rich or too dead. Hope you had fun.' |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
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.integer :option_a_id | ||
t.integer :option_b_id | ||
t.boolean :starting_point, default: false | ||
t.boolean :conclusion, default: false | ||
end | ||
end | ||
end | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
# Cleaning Out | ||
|
||
Page.delete_all | ||
steady = Page.create(conclusion: true, preview: 'You move forward', | ||
content: 'You crash a secret conference of top teer venture capitalist. They like you so much they give you some pocket change. 30 bags of gold: WINNER') | ||
sleep = Page.create(conclusion: true, preview: 'You lay down for a power nap', | ||
content: 'A clan of dwarfs adopt you and name you sleepy. Unfortunately that very day grumpy\'s new pick-ax arrives from Amazon and you loose your head: LOSER') | ||
forest = Page.create(option_a_id: steady.id, option_b_id: sleep.id, preview: "Go into the Forest", content: "You see smoke in the distance.") | ||
lake = Page.create(option_a_id: steady.id, option_b_id: sleep.id, preview: "Sail across the Lake", content: "You begin to hear music in the distance.") | ||
page = Page.create(starting_point: true, option_a_id: forest.id, option_b_id: lake.id, preview: "Welcome subjects", 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?") | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
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 | ||
|
||
end | ||
def complete_game? | ||
current_page.conclusion? | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
class Page < ActiveRecord::Base | ||
|
||
def self.starting_point | ||
Page.where(starting_point: true).first | ||
end | ||
|
||
def options | ||
Page.where(:parent_id => id).limit(2) | ||
end | ||
def self.starting_point | ||
Page.where(starting_point: true).first | ||
end | ||
|
||
def options | ||
Page.find(option_a_id, option_b_id) | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
require_relative "spec_helper" | ||
|
||
describe Book do | ||
let!(:page) {Page.create(starting_point: true)} | ||
subject { Book.new(page) } | ||
let!(:option_a) {Page.create(preview: 'view option_a')} | ||
let!(:option_b) {Page.create(preview: 'view option_b')} | ||
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 | ||
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 | ||
|
||
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 | ||
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 | ||
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome!