dwemthy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) why the lucky stiff
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ = dwemthy
2
+
3
+ In this game, you are a rabbit who is going to die. A dragon is going to do it. Deep in Dwemthy's Array.
4
+
5
+ Please, never ask who Dwemthy is. Obviously he is a mastermind and would never disclose his location or true identity. He has sired dynasties. He has set living ogres aflame. Horses everywhere smell him at all times. Most of all, he knows carnal pleasures. And to think that this...
6
+
7
+ This is his Array.
8
+
9
+ A scalding SEETHING LAVA infiltrates the cacauphonous ENGORGED MINESHAFTS deep within the ageless canopy of the DWEMTHY FOREST... chalky and nocturnal screams from the belly of the RAVENOUS WILD STORKUPINE... who eats wet goslings RIGHT AFTER they've had a few graham crackers and a midday nap... amidst starved hippos TECHNICALLY ORPHANED but truthfully sheltered by umbrellas owned jointly by car dealership conglomerates... beneath uncapped vials of mildly pulpy BLUE ELIXIR... which shall remain... heretofore... UNDISTURBED... DWEMTHY!!!
10
+
11
+ Contrary to the ill-guided notions of certain introductory comics, DWEMTHY'S ARRAY is not a mind puzzle. It is a short 60 line role-playing game that is played with Ruby metaprogramming. The game comes from chapter six of Why's (Poignant) Guide to Ruby.
12
+
13
+ To play, you must have Ruby (the beloved programming language) on your computer. If you don't, you must leave Dwemthy's Array immediately and never speak of it, except with your legal guardian to whom your life is entrusted.
14
+
15
+ More info: http://mislav.uniqpath.com/poignant-guide/dwemthy/
16
+
17
+ == To play
18
+
19
+ * gem install dwemthy; dwemthy
20
+
21
+
22
+ == Note on Patches/Pull Requests
23
+
24
+ * Fork the project.
25
+ * Make your feature addition or bug fix.
26
+ * Commit, do not mess with rakefile, version, or history.
27
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
28
+ * Send me a pull request. Bonus points for topic branches.
29
+
30
+ == Copyright
31
+
32
+ See LICENSE for details.
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "dwemthy"
8
+ gem.summary = "$$$ DWEMTHY_S ARRAY ^!^ A RUBY MINI_DUNGEON ^!^ ONLY 60 LINES OF CODE ^!^ DWEMTY IS WATCHING ^!^ A STALE BREATH IS ON YOUR NAPE, IS IT NOT ?? ^!^ DWEMTHY COMETH $$$"
9
+ gem.description = "DWEMTHY'S ARRAY is not a mind puzzle. It is a short 60 line role-playing game that is played with Ruby metaprogramming. The game comes from chapter six of Why's (Poignant) Guide to Ruby."
10
+ gem.email = "caffeine@gmail.com"
11
+ gem.homepage = "http://github.com/caffo/dwemthy"
12
+ gem.authors = ["rodrigo franco (caffo)"]
13
+ # gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "dwemthy #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
3
+
4
+ require 'irb'
5
+ module IRB # :nodoc:
6
+ def self.start_session(binding)
7
+ unless @__initialized
8
+ args = ARGV
9
+ ARGV.replace(ARGV.dup)
10
+ IRB.setup(nil)
11
+ ARGV.replace(args)
12
+ @__initialized = true
13
+ end
14
+
15
+ workspace = WorkSpace.new(binding)
16
+
17
+ irb = Irb.new(workspace)
18
+
19
+ @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
20
+ @CONF[:MAIN_CONTEXT] = irb.context
21
+
22
+ catch(:IRB_EXIT) do
23
+ irb.eval_input
24
+ end
25
+ end
26
+ end
27
+
28
+
29
+ require 'dwemthy'
30
+ dwarr = DwemthysArray[IndustrialRaverMonkey.new,
31
+ DwarvenAngel.new,
32
+ AssistantViceTentacleAndOmbudsman.new,
33
+ TeethDeer.new,
34
+ IntrepidDecomposedCyclist.new,
35
+ Dragon.new]
36
+
37
+ IRB.start_session(Kernel.binding)
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{dwemthy}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["rodrigo franco (caffo)"]
12
+ s.date = %q{2010-08-19}
13
+ s.default_executable = %q{dwemthy}
14
+ s.description = %q{DWEMTHY'S ARRAY is not a mind puzzle. It is a short 60 line role-playing game that is played with Ruby metaprogramming. The game comes from chapter six of Why's (Poignant) Guide to Ruby.}
15
+ s.email = %q{caffeine@gmail.com}
16
+ s.executables = ["dwemthy"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/dwemthy",
29
+ "dwemthy.gemspec",
30
+ "lib/creature.rb",
31
+ "lib/dwemthy.rb",
32
+ "lib/foes.rb",
33
+ "lib/rabbit.rb",
34
+ "test/helper.rb",
35
+ "test/test_dwemthy.rb"
36
+ ]
37
+ s.homepage = %q{http://github.com/caffo/dwemthy}
38
+ s.rdoc_options = ["--charset=UTF-8"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.3.7}
41
+ s.summary = %q{$$$ DWEMTHY_S ARRAY ^!^ A RUBY MINI_DUNGEON ^!^ ONLY 60 LINES OF CODE ^!^ DWEMTY IS WATCHING ^!^ A STALE BREATH IS ON YOUR NAPE, IS IT NOT ?? ^!^ DWEMTHY COMETH $$$}
42
+ s.test_files = [
43
+ "test/helper.rb",
44
+ "test/test_dwemthy.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
+ else
53
+ end
54
+ else
55
+ end
56
+ end
57
+
@@ -0,0 +1,71 @@
1
+ # The guts of life force within Dwemthy's Array
2
+ class Creature
3
+
4
+ # Get a metaclass for this class
5
+ def self.metaclass; class << self; self; end; end
6
+
7
+ # Advanced metaprogramming code for nice, clean traits
8
+ def self.traits( *arr )
9
+ return @traits if arr.empty?
10
+
11
+ # 1. Set up accessors for each variable
12
+ attr_accessor *arr
13
+
14
+ # 2. Add a new class method to for each trait.
15
+ arr.each do |a|
16
+ metaclass.instance_eval do
17
+ define_method( a ) do |val|
18
+ @traits ||= {}
19
+ @traits[a] = val
20
+ end
21
+ end
22
+ end
23
+
24
+ # 3. For each monster, the `initialize' method
25
+ # should use the default number for each trait.
26
+ class_eval do
27
+ define_method( :initialize ) do
28
+ self.class.traits.each do |k,v|
29
+ instance_variable_set("@#{k}", v)
30
+ end
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ # Creature attributes are read-only
37
+ traits :life, :strength, :charisma, :weapon
38
+
39
+ # This method applies a hit taken during a fight.
40
+ def hit( damage )
41
+ p_up = rand( charisma )
42
+ if p_up % 9 == 7
43
+ @life += p_up / 4
44
+ puts "[#{ self.class } magick powers up #{ p_up }!]"
45
+ end
46
+ @life -= damage
47
+ puts "[#{ self.class } has died.]" if @life <= 0
48
+ end
49
+
50
+ # This method takes one turn in a fight.
51
+ def fight( enemy, weapon )
52
+ if life <= 0
53
+ puts "[#{ self.class } is too dead to fight!]"
54
+ return
55
+ end
56
+
57
+ # Attack the opponent
58
+ your_hit = rand( strength + weapon )
59
+ puts "[You hit with #{ your_hit } points of damage!]"
60
+ enemy.hit( your_hit )
61
+
62
+ # Retaliation
63
+ p enemy
64
+ if enemy.life > 0
65
+ enemy_hit = rand( enemy.strength + enemy.weapon )
66
+ puts "[Your enemy hit with #{ enemy_hit } points of damage!]"
67
+ self.hit( enemy_hit )
68
+ end
69
+ end
70
+
71
+ end
@@ -0,0 +1,89 @@
1
+ require 'creature'
2
+ require 'rabbit'
3
+ require 'foes'
4
+
5
+ class DwemthysArray < Array
6
+ alias _inspect inspect
7
+ def inspect; "#<#{ self.class }#{ _inspect }>"; end
8
+ def method_missing( meth, *args )
9
+ answer = first.send( meth, *args )
10
+ if first.life <= 0
11
+ shift
12
+ if empty?
13
+ puts "[Whoa. You decimated Dwemthy's Array!]"
14
+ else
15
+ puts "[Get ready. #{ first.class } has emerged.]"
16
+ end
17
+ end
18
+ answer || 0
19
+ end
20
+ end
21
+
22
+ dwarr = DwemthysArray[IndustrialRaverMonkey.new,
23
+ DwarvenAngel.new,
24
+ AssistantViceTentacleAndOmbudsman.new,
25
+ TeethDeer.new,
26
+ IntrepidDecomposedCyclist.new,
27
+ Dragon.new]
28
+
29
+ @ohai = <<-END
30
+
31
+ _
32
+ ____ _ _ _ _____ _____ _____ _____ __ __| |_____ _____ _____ _____ _____ __ __
33
+ | \| | | | __| |_ _| | | | |_| __| | _ | __ | __ | _ | | |
34
+ | | | | | | __| | | | | | | |_ _| |__ | | | -| -| |_ _|
35
+ |____/|_____|_____|_|_|_| |_| |__|__| |_| |_____| |__|__|__|__|__|__|__|__| |_|
36
+
37
+
38
+ DWEMTHY'S ARRAY is not a mind puzzle. It is a short 60 line role-playing game that is played with Ruby metaprogramming. The game comes from chapter six of Why's (Poignant) Guide to Ruby - http://mislav.uniqpath.com/poignant-guide/.
39
+
40
+ You Are A Rabbit, UNTIL!
41
+ ------------------------
42
+
43
+ In this game, you are a rabbit who is going to die. A dragon is going to do it. Deep in Dwemthy's Array.
44
+
45
+ Please, never ask who Dwemthy is. Obviously he is a mastermind and would never disclose his location or true identity. He has sired dynasties. He has set living ogres aflame. Horses everywhere smell him at all times. Most of all, he knows carnal pleasures. And to think that this...
46
+
47
+ This is his Array.
48
+
49
+ #{dwarr.inspect}
50
+
51
+ If you don't understand Dwemthy's Array, it is Dwemthy's fault. He designed the game to complicate our lives and were it simpler, it would not be the awe-inspiring quest we've come to cherish in our arms this very hour.
52
+
53
+ Introducing: You.
54
+ -----------------
55
+
56
+ You have four weapons. I shan't describe them further. Ok, I will:
57
+
58
+ ^ - little boomerang
59
+ / - the hero's sword is unlimited!!
60
+ % - lettuce will build your strength and extra ruffage will fly in the face of your opponent!!
61
+ * - bombs, but you only have three!!
62
+
63
+ How to Play
64
+ -----------
65
+
66
+ To get the fight started, make sure you've created one of you:
67
+
68
+ r = Rabbit.new
69
+
70
+ Now use the little boomerang to kill monsters who dell in the fetid array!
71
+
72
+ > r * dwarr
73
+ [You hit with 4 points of damage!]
74
+ #<DwemthysArray[#<IndustrialRaverMonkey:0x1005279d8 @charisma=91, @strength=35, @life=42, @weapon=2>, #<DwarvenAngel:0x100527758 @charisma=144, @strength=6, @life=540, @weapon=50>, #<AssistantViceTentacleAndOmbudsman:0x1005274d8 @charisma=144, @strength=6, @life=320, @weapon=50>, #<TeethDeer:0x100527258 @charisma=19, @strength=192, @life=655, @weapon=109>, #<IntrepidDecomposedCyclist:0x100526fd8 @charisma=422, @strength=560, @life=901, @weapon=105>, #<Dragon:0x100526b78 @charisma=1020, @strength=451, @life=1340, @weapon=939>]>
75
+ [Your enemy hit with 16 points of damage!]
76
+ [Rabbit magick powers up 25!]
77
+ [Rabbit has died.]
78
+
79
+ For crying out loud!! Our sample rabbit died!!
80
+
81
+ Grim prospects. I can't ask you to return to the rabbit kingdom, though. Just pretend like you didn't die and make a whole new rabbit. Iterate until perfection.
82
+
83
+ Fight the Array and the monsters will appear as you go. Godspeed and may you return with harrowing tales and nary an angel talon piercing through your shoulder.
84
+
85
+ Oh, and none of this "I'm too young to die" business. I'm sick of that crap. I'm not going to have you insulting our undead young people. They are our future. After our future is over, that is.
86
+
87
+ END
88
+
89
+ puts @ohai
@@ -0,0 +1,41 @@
1
+ class IndustrialRaverMonkey < Creature
2
+ life 46
3
+ strength 35
4
+ charisma 91
5
+ weapon 2
6
+ end
7
+
8
+ class DwarvenAngel < Creature
9
+ life 540
10
+ strength 6
11
+ charisma 144
12
+ weapon 50
13
+ end
14
+
15
+ class AssistantViceTentacleAndOmbudsman < Creature
16
+ life 320
17
+ strength 6
18
+ charisma 144
19
+ weapon 50
20
+ end
21
+
22
+ class TeethDeer < Creature
23
+ life 655
24
+ strength 192
25
+ charisma 19
26
+ weapon 109
27
+ end
28
+
29
+ class IntrepidDecomposedCyclist < Creature
30
+ life 901
31
+ strength 560
32
+ charisma 422
33
+ weapon 105
34
+ end
35
+
36
+ class Dragon < Creature
37
+ life 1340 # tough scales
38
+ strength 451 # bristling veins
39
+ charisma 1020 # toothy smile
40
+ weapon 939 # fire breath
41
+ end
@@ -0,0 +1,35 @@
1
+ class Rabbit < Creature
2
+ traits :bombs
3
+
4
+ life 10
5
+ strength 2
6
+ charisma 44
7
+ weapon 4
8
+ bombs 3
9
+
10
+ # little boomerang
11
+ def ^( enemy )
12
+ fight( enemy, 13 )
13
+ end
14
+ # the hero's sword is unlimited!!
15
+ def /( enemy )
16
+ fight( enemy, rand( 4 + ( ( enemy.life % 10 ) ** 2 ) ) )
17
+ end
18
+ # lettuce will build your strength and extra ruffage
19
+ # will fly in the face of your opponent!!
20
+ def %( enemy )
21
+ lettuce = rand( charisma )
22
+ puts "[Healthy lettuce gives you #{ lettuce } life points!!]"
23
+ @life += lettuce
24
+ fight( enemy, 0 )
25
+ end
26
+ # bombs, but you only have three!!
27
+ def *( enemy )
28
+ if @bombs.zero?
29
+ puts "[UHN!! You're out of bombs!!]"
30
+ return
31
+ end
32
+ @bombs -= 1
33
+ fight( enemy, 86 )
34
+ end
35
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'dwemthy'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestDwemthy < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dwemthy
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - rodrigo franco (caffo)
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-19 00:00:00 -03:00
19
+ default_executable: dwemthy
20
+ dependencies: []
21
+
22
+ description: DWEMTHY'S ARRAY is not a mind puzzle. It is a short 60 line role-playing game that is played with Ruby metaprogramming. The game comes from chapter six of Why's (Poignant) Guide to Ruby.
23
+ email: caffeine@gmail.com
24
+ executables:
25
+ - dwemthy
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - LICENSE
30
+ - README.rdoc
31
+ files:
32
+ - .document
33
+ - .gitignore
34
+ - LICENSE
35
+ - README.rdoc
36
+ - Rakefile
37
+ - VERSION
38
+ - bin/dwemthy
39
+ - dwemthy.gemspec
40
+ - lib/creature.rb
41
+ - lib/dwemthy.rb
42
+ - lib/foes.rb
43
+ - lib/rabbit.rb
44
+ - test/helper.rb
45
+ - test/test_dwemthy.rb
46
+ has_rdoc: true
47
+ homepage: http://github.com/caffo/dwemthy
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options:
52
+ - --charset=UTF-8
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.7
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: $$$ DWEMTHY_S ARRAY ^!^ A RUBY MINI_DUNGEON ^!^ ONLY 60 LINES OF CODE ^!^ DWEMTY IS WATCHING ^!^ A STALE BREATH IS ON YOUR NAPE, IS IT NOT ?? ^!^ DWEMTHY COMETH $$$
80
+ test_files:
81
+ - test/helper.rb
82
+ - test/test_dwemthy.rb