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 Level: add a preview and an outcome to the page #12

Open
wants to merge 7 commits 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
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- color --format progress
22 changes: 22 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2014 jason perez

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,33 @@ License
-------

Copyright Jesse Wolgamott 2012, MIT License. See LICENSE

# Adventure Game

TODO: Write a gem description

## Installation

Add this line to your application's Gemfile:

gem 'adventure_game'

And then execute:

$ bundle

Or install it yourself as:

$ gem install adventure_game

## Usage

TODO: Write usage instructions here

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
24 changes: 24 additions & 0 deletions adventure_game.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'adventure_game/version'

Gem::Specification.new do |spec|
spec.name = "adventure_game"
spec.version = AdventureGame::VERSION
spec.authors = ["jason perez"]
spec.email = ["[email protected]"]
spec.description = "A sample gem as one exercise from Ruby Off Rails."
spec.summary = "Sample gem for Adventure Game."
spec.homepage = ""
spec.license = "MIT"

spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
end
1 change: 0 additions & 1 deletion db/seed.rb

This file was deleted.

6 changes: 6 additions & 0 deletions lib/adventure_game.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require_relative "adventure_game/version"
require_relative "adventure_game/adventure"

module AdventureGame
# Your code goes here...
end
23 changes: 10 additions & 13 deletions adventure.rb → lib/adventure_game/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_relative '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!"
6 changes: 6 additions & 0 deletions lib/adventure_game/config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
host: 'localhost'
adapter: 'postgresql'
database: 'episode5'
username: 'jason'
encoding: 'utf8'
pool: 5
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
29 changes: 29 additions & 0 deletions lib/adventure_game/db/seed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +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.")
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?")
4 changes: 2 additions & 2 deletions db/setup.rb → lib/adventure_game/db/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'active_record'
require 'yaml'

connection_details = YAML::load(File.open('config/database.yml'))
connection_details = YAML::load(File.open('lib/adventure_game/config/database.yml'))

# Setup out connection details
ActiveRecord::Base.establish_connection(connection_details.merge({'database'=> 'postgres', 'schema_search_path'=> 'public'}))
Expand All @@ -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("lib/adventure_game/db/migrate/")
2 changes: 1 addition & 1 deletion models/book.rb → lib/adventure_game/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 → lib/adventure_game/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)
end

end
3 changes: 3 additions & 0 deletions lib/adventure_game/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module AdventureGame
VERSION = "0.0.1"
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.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.outcome.should eq("You be dead!")
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
6 changes: 3 additions & 3 deletions 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 "../models/page"
require_relative "../models/book"
require_relative '../lib/adventure_game/db/setup'
require_relative "../lib/adventure_game/models/page"
require_relative "../lib/adventure_game/models/book"