diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/.DS_Store differ diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..9c21dc5 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +-- color --format progress \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..364e56d --- /dev/null +++ b/LICENSE.txt @@ -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. diff --git a/README.md b/README.md index 04a69b3..684981a 100644 --- a/README.md +++ b/README.md @@ -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 \ No newline at end of file diff --git a/adventure_game.gemspec b/adventure_game.gemspec new file mode 100644 index 0000000..18327f6 --- /dev/null +++ b/adventure_game.gemspec @@ -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 = ["jperezish@gmail.com"] + 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 diff --git a/db/seed.rb b/db/seed.rb deleted file mode 100644 index 1abe902..0000000 --- a/db/seed.rb +++ /dev/null @@ -1 +0,0 @@ -# Cleaning Out diff --git a/lib/adventure_game.rb b/lib/adventure_game.rb new file mode 100644 index 0000000..5e8114f --- /dev/null +++ b/lib/adventure_game.rb @@ -0,0 +1,6 @@ +require_relative "adventure_game/version" +require_relative "adventure_game/adventure" + +module AdventureGame + # Your code goes here... +end \ No newline at end of file diff --git a/adventure.rb b/lib/adventure_game/adventure.rb similarity index 56% rename from adventure.rb rename to lib/adventure_game/adventure.rb index d65f616..6a0bfac 100644 --- a/adventure.rb +++ b/lib/adventure_game/adventure.rb @@ -4,23 +4,25 @@ 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 "| |" @@ -28,8 +30,3 @@ puts "| |" puts "| |" puts "------------------------------------------" - - -puts book.current_page.content - -puts "hope you won!" diff --git a/lib/adventure_game/config/database.yml b/lib/adventure_game/config/database.yml new file mode 100644 index 0000000..df913ce --- /dev/null +++ b/lib/adventure_game/config/database.yml @@ -0,0 +1,6 @@ +host: 'localhost' +adapter: 'postgresql' +database: 'episode5' +username: 'jason' +encoding: 'utf8' +pool: 5 diff --git a/config/database.yml.sample b/lib/adventure_game/config/database.yml.sample similarity index 100% rename from config/database.yml.sample rename to lib/adventure_game/config/database.yml.sample diff --git a/db/migrate/001_creates_page.rb b/lib/adventure_game/db/migrate/001_creates_page.rb similarity index 65% rename from db/migrate/001_creates_page.rb rename to lib/adventure_game/db/migrate/001_creates_page.rb index 8a293c0..325cba3 100644 --- a/db/migrate/001_creates_page.rb +++ b/lib/adventure_game/db/migrate/001_creates_page.rb @@ -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 diff --git a/lib/adventure_game/db/seed.rb b/lib/adventure_game/db/seed.rb new file mode 100644 index 0000000..89a99a2 --- /dev/null +++ b/lib/adventure_game/db/seed.rb @@ -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?") diff --git a/db/setup.rb b/lib/adventure_game/db/setup.rb similarity index 77% rename from db/setup.rb rename to lib/adventure_game/db/setup.rb index 0e80690..5876342 100644 --- a/db/setup.rb +++ b/lib/adventure_game/db/setup.rb @@ -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'})) @@ -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/") diff --git a/models/book.rb b/lib/adventure_game/models/book.rb similarity index 91% rename from models/book.rb rename to lib/adventure_game/models/book.rb index 5eb6f53..3c14935 100644 --- a/models/book.rb +++ b/lib/adventure_game/models/book.rb @@ -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 diff --git a/models/page.rb b/lib/adventure_game/models/page.rb similarity index 76% rename from models/page.rb rename to lib/adventure_game/models/page.rb index 2b88343..6ce2772 100644 --- a/models/page.rb +++ b/lib/adventure_game/models/page.rb @@ -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 diff --git a/lib/adventure_game/version.rb b/lib/adventure_game/version.rb new file mode 100644 index 0000000..89a95bd --- /dev/null +++ b/lib/adventure_game/version.rb @@ -0,0 +1,3 @@ +module AdventureGame + VERSION = "0.0.1" +end \ No newline at end of file diff --git a/spec/book_spec.rb b/spec/book_spec.rb index b429112..ad0a4b7 100644 --- a/spec/book_spec.rb +++ b/spec/book_spec.rb @@ -1,7 +1,11 @@ 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 @@ -9,9 +13,6 @@ 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) diff --git a/spec/page_spec.rb b/spec/page_spec.rb index 5951cdd..6af65f5 100644 --- a/spec/page_spec.rb +++ b/spec/page_spec.rb @@ -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]) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bdb95b8..8c2905c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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"