From fc8126d618c20f587c71f44b669703875c5d37bd Mon Sep 17 00:00:00 2001 From: jason perez Date: Fri, 24 Jan 2014 13:47:53 -0800 Subject: [PATCH 1/7] add a preview and an outcome to the page --- .rspec | 1 + adventure.rb | 27 +++++++++++++++++---------- db/migrate/001_creates_page.rb | 2 ++ models/book.rb | 2 +- spec/page_spec.rb | 10 ++++++++++ 5 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 .rspec 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/adventure.rb b/adventure.rb index d65f616..c931927 100644 --- a/adventure.rb +++ b/adventure.rb @@ -5,19 +5,28 @@ require_relative 'models/page' 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: "Walk down the road") +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, + 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.create(conclusion: true, + parent_id: page.id, + 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.") 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 "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 ) end @@ -29,7 +38,5 @@ puts "| |" puts "------------------------------------------" - -puts book.current_page.content - -puts "hope you won!" +puts book.current_page.outcome +puts book.current_page.content diff --git a/db/migrate/001_creates_page.rb b/db/migrate/001_creates_page.rb index 8a293c0..2536910 100644 --- a/db/migrate/001_creates_page.rb +++ b/db/migrate/001_creates_page.rb @@ -2,6 +2,8 @@ class CreatesPage < ActiveRecord::Migration def change create_table :pages do |t| t.text :content + t.string :preview + t.string :outcome t.integer :parent_id t.boolean :starting_point, default: false t.boolean :conclusion, default: false diff --git a/models/book.rb b/models/book.rb index 5eb6f53..3c14935 100644 --- a/models/book.rb +++ b/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/spec/page_spec.rb b/spec/page_spec.rb index 5951cdd..d48dfd5 100644 --- a/spec/page_spec.rb +++ b/spec/page_spec.rb @@ -16,6 +16,16 @@ 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.find(page.id).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.find(page.id).outcome.should eq("You be dead!") + end + context "#options" do subject {Page.create} let(:option_a) {Page.create(parent_id: subject.id) } From ef1b1fc5ff91d051c274d0aa21fa4977c5a02ff9 Mon Sep 17 00:00:00 2001 From: jason perez Date: Sat, 25 Jan 2014 09:00:13 -0800 Subject: [PATCH 2/7] extract all Page.creates to the seed file --- adventure.rb | 15 ++------------- db/seed.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/adventure.rb b/adventure.rb index c931927..f5fcd6e 100644 --- a/adventure.rb +++ b/adventure.rb @@ -4,20 +4,9 @@ require_relative 'db/setup' require_relative 'models/page' require_relative 'models/book' +require "./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, - 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.create(conclusion: true, - parent_id: page.id, - 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 = Page.starting_point book = Book.new(page) until book.complete_game? do diff --git a/db/seed.rb b/db/seed.rb index 1abe902..995d71c 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1 +1,16 @@ # Cleaning Out +Page.delete_all + +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, + 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.create(conclusion: true, + parent_id: page.id, + 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.") + From 7fde057183a5e7af5d81cd36653eb1e5f5173c21 Mon Sep 17 00:00:00 2001 From: jason perez Date: Tue, 28 Jan 2014 07:09:28 -0800 Subject: [PATCH 3/7] update page to store 2 option ids --- db/migrate/001_creates_page.rb | 3 ++- db/seed.rb | 13 ++++++------- models/page.rb | 2 +- spec/book_spec.rb | 9 +++++---- spec/page_spec.rb | 7 +++---- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/db/migrate/001_creates_page.rb b/db/migrate/001_creates_page.rb index 2536910..325cba3 100644 --- a/db/migrate/001_creates_page.rb +++ b/db/migrate/001_creates_page.rb @@ -4,7 +4,8 @@ def change t.text :content t.string :preview t.string :outcome - 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 diff --git a/db/seed.rb b/db/seed.rb index 995d71c..de2ace5 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1,16 +1,15 @@ # Cleaning Out Page.delete_all -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, +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.create(conclusion: true, - parent_id: page.id, +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 = Page.create(starting_point: true, + option_a_id: page_two.id, + option_b_id: page_three.id, + 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?") \ No newline at end of file diff --git a/models/page.rb b/models/page.rb index 2b88343..6ce2772 100644 --- a/models/page.rb +++ b/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/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 d48dfd5..c10fa76 100644 --- a/spec/page_spec.rb +++ b/spec/page_spec.rb @@ -27,10 +27,9 @@ 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]) From a7249448c798b69a0073674e94a23031fcae6409 Mon Sep 17 00:00:00 2001 From: jason perez Date: Tue, 28 Jan 2014 09:24:04 -0800 Subject: [PATCH 4/7] update to have a common page --- adventure.rb | 9 +++++---- db/seed.rb | 34 ++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/adventure.rb b/adventure.rb index f5fcd6e..4209f7c 100644 --- a/adventure.rb +++ b/adventure.rb @@ -10,6 +10,7 @@ book = Book.new(page) until book.complete_game? do + puts "------------------------------------------" puts book.current_page.content puts "your options: " puts "A - [#{book.current_page.options.first.preview}]" @@ -17,8 +18,11 @@ puts "What do you want to do? Enter A or B" book.input( gets ) - + puts "------------------------------------------" + puts book.current_page.outcome + puts "------------------------------------------" end +puts book.current_page.content puts "------------------------------------------" puts "| |" puts "| |" @@ -26,6 +30,3 @@ puts "| |" puts "| |" puts "------------------------------------------" - -puts book.current_page.outcome -puts book.current_page.content diff --git a/db/seed.rb b/db/seed.rb index de2ace5..89a99a2 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1,15 +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.") + 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.") + 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_two.id, - option_b_id: page_three.id, - 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?") \ No newline at end of file + 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?") From abb45b3379b06a963d874bc08ce4c371e1b11640 Mon Sep 17 00:00:00 2001 From: jason perez Date: Tue, 28 Jan 2014 13:52:39 -0800 Subject: [PATCH 5/7] update tests to remove db query and just send a message to the object --- spec/page_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/page_spec.rb b/spec/page_spec.rb index c10fa76..6af65f5 100644 --- a/spec/page_spec.rb +++ b/spec/page_spec.rb @@ -18,12 +18,12 @@ it "should have a preview" do page = Page.create(preview: "Walk down the road") - Page.find(page.id).preview.should eq("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.find(page.id).outcome.should eq("You be dead!") + page.outcome.should eq("You be dead!") end context "#options" do From 85a8007b64e038e03f3c70f4a3a555d6e1b695f7 Mon Sep 17 00:00:00 2001 From: jason perez Date: Fri, 21 Feb 2014 13:04:30 -0800 Subject: [PATCH 6/7] move and update files to be packaged as a gem --- .DS_Store | Bin 0 -> 6148 bytes lib/adventure_game.rb | 6 ++++++ adventure.rb => lib/adventure_game/adventure.rb | 2 +- lib/adventure_game/config/database.yml | 6 ++++++ .../adventure_game/config}/database.yml.sample | 0 .../db}/migrate/001_creates_page.rb | 0 {db => lib/adventure_game/db}/seed.rb | 0 {db => lib/adventure_game/db}/setup.rb | 4 ++-- {models => lib/adventure_game/models}/book.rb | 0 {models => lib/adventure_game/models}/page.rb | 0 lib/adventure_game/version.rb | 3 +++ spec/spec_helper.rb | 6 +++--- 12 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 .DS_Store create mode 100644 lib/adventure_game.rb rename adventure.rb => lib/adventure_game/adventure.rb (97%) create mode 100644 lib/adventure_game/config/database.yml rename {config => lib/adventure_game/config}/database.yml.sample (100%) rename {db => lib/adventure_game/db}/migrate/001_creates_page.rb (100%) rename {db => lib/adventure_game/db}/seed.rb (100%) rename {db => lib/adventure_game/db}/setup.rb (77%) rename {models => lib/adventure_game/models}/book.rb (100%) rename {models => lib/adventure_game/models}/page.rb (100%) create mode 100644 lib/adventure_game/version.rb diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 '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 100% rename from models/book.rb rename to lib/adventure_game/models/book.rb diff --git a/models/page.rb b/lib/adventure_game/models/page.rb similarity index 100% rename from models/page.rb rename to lib/adventure_game/models/page.rb 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/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" From b7574492d3b5d502c622d78bb7bfecdaa5391de9 Mon Sep 17 00:00:00 2001 From: jason perez Date: Fri, 21 Feb 2014 13:11:28 -0800 Subject: [PATCH 7/7] add gem spec, update readme, add license --- LICENSE.txt | 22 ++++++++++++++++++++++ README.md | 30 ++++++++++++++++++++++++++++++ adventure_game.gemspec | 24 ++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 LICENSE.txt create mode 100644 adventure_game.gemspec 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