the-swarm 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.yardopts +8 -0
  4. data/Gemfile +24 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +35 -0
  7. data/Rakefile +26 -0
  8. data/bin/swarm +11 -0
  9. data/docs/Swarm.html +296 -0
  10. data/docs/Swarm/Catalog.html +819 -0
  11. data/docs/Swarm/Console.html +1050 -0
  12. data/docs/Swarm/Console/Color.html +160 -0
  13. data/docs/Swarm/Console/NormalKey.html +410 -0
  14. data/docs/Swarm/Console/PopUp.html +236 -0
  15. data/docs/Swarm/Console/VIKey.html +410 -0
  16. data/docs/Swarm/Five.html +421 -0
  17. data/docs/Swarm/Four.html +389 -0
  18. data/docs/Swarm/Game.html +1197 -0
  19. data/docs/Swarm/Intro.html +419 -0
  20. data/docs/Swarm/Level.html +700 -0
  21. data/docs/Swarm/Map.html +2336 -0
  22. data/docs/Swarm/One.html +353 -0
  23. data/docs/Swarm/Three.html +383 -0
  24. data/docs/Swarm/Tile.html +3823 -0
  25. data/docs/Swarm/Two.html +355 -0
  26. data/docs/_index.html +313 -0
  27. data/docs/class_list.html +51 -0
  28. data/docs/css/common.css +1 -0
  29. data/docs/css/full_list.css +58 -0
  30. data/docs/css/style.css +492 -0
  31. data/docs/file.LICENSE.html +70 -0
  32. data/docs/file.README.html +101 -0
  33. data/docs/file_list.html +61 -0
  34. data/docs/frames.html +17 -0
  35. data/docs/index.html +101 -0
  36. data/docs/js/app.js +248 -0
  37. data/docs/js/full_list.js +216 -0
  38. data/docs/js/jquery.js +4 -0
  39. data/docs/method_list.html +1195 -0
  40. data/docs/top-level-namespace.html +110 -0
  41. data/lib/swarm.rb +60 -0
  42. data/lib/swarm/catalog.rb +71 -0
  43. data/lib/swarm/console.rb +165 -0
  44. data/lib/swarm/game.rb +173 -0
  45. data/lib/swarm/level.rb +58 -0
  46. data/lib/swarm/levels/five.rb +71 -0
  47. data/lib/swarm/levels/four.rb +55 -0
  48. data/lib/swarm/levels/intro.rb +36 -0
  49. data/lib/swarm/levels/one.rb +35 -0
  50. data/lib/swarm/levels/three.rb +51 -0
  51. data/lib/swarm/levels/two.rb +38 -0
  52. data/lib/swarm/map.rb +254 -0
  53. data/lib/swarm/tile.rb +149 -0
  54. data/lib/swarm/version.rb +5 -0
  55. data/swarm.gemspec +24 -0
  56. metadata +112 -0
data/lib/swarm/tile.rb ADDED
@@ -0,0 +1,149 @@
1
+ module Swarm
2
+ class Tile
3
+
4
+ class << self
5
+
6
+ # Create methods for setting and testing the +type+ value, change status
7
+ # and console color of every +Tile+.
8
+ #
9
+ # @macro [attach] swarm.tile.attr_type
10
+ # @method $1
11
+ # set the +type+ to :$1, the +icon+ to +$2+, the +color+ to $3, the +age+
12
+ # to $7 and flags the tile to be updated by the +Console+
13
+ # $0, $1, $2, $3, $4, $5, $6, $7
14
+ #
15
+ # @param age [Integer]
16
+ # @return [true]
17
+ #
18
+ # @method $1!
19
+ # set the +type+ to :$1, the +icon+ to '$2', the +color+ to $3, the +age+
20
+ # to 0, and flags the tile to be updated by the +Console+
21
+ #
22
+ # @param age [Integer]
23
+ # @return [true]
24
+ #
25
+ # @method $1?
26
+ # test the value of +type+
27
+ # @return [Boolean] +true+ if +type+ is $1, +false+ if it is not
28
+ def attr_type(type, icon: String.new, color: 0)
29
+ define_method(type) do |age|
30
+ change do
31
+ @type = type
32
+ @icon = icon
33
+ @color = color
34
+ @age = age
35
+ end
36
+
37
+ self
38
+ end
39
+
40
+ define_method("#{type}!") { send type, 0 }
41
+
42
+ define_method("#{type}?") { @type == type }
43
+ end
44
+ end
45
+
46
+ include Console::Color
47
+
48
+ attr_type :empty, icon: ' '.freeze, color: BLACK
49
+ attr_type :dirt, icon: '██'.freeze, color: SILVER
50
+ attr_type :rock, icon: '██'.freeze, color: WHITE
51
+ attr_type :worker, icon: '├┤'.freeze, color: BLUE
52
+ attr_type :soldier, icon: '╟╢'.freeze, color: RED
53
+ attr_type :queen, icon: '╬╬'.freeze, color: PURPLE
54
+ attr_type :egg, icon: 'oo'.freeze, color: YELLOW
55
+ attr_type :player, icon: '◄▶'.freeze, color: GREEN
56
+
57
+ # @macro swarm.tile.position
58
+ # @return [Integer] the position of the +tile+ on the $1 axis.
59
+
60
+ # @macro swarm.tile.position
61
+ attr_reader :x
62
+
63
+ # @macro swarm.tile.position
64
+ attr_reader :y
65
+
66
+ # @return [Symbol]
67
+ attr_reader :type
68
+
69
+ # @return [String]
70
+ attr_reader :icon
71
+
72
+ # @return [Integer]
73
+ attr_reader :color
74
+
75
+ attr_reader :location
76
+
77
+ # @return [Integer]
78
+ attr_reader :age
79
+
80
+ # Initialize a +Tile+ with the +x+ and both +y+ positions (+Console+ and +Map+)
81
+ # on the +Console+. Since tiles are 2 characters wide, two sets coordinates
82
+ # are stored: the position in the console (+@location+) and the position
83
+ # on the map (+@x+ and +@y+). All tiles start off as +:empty+.
84
+ #
85
+ # @param map_x [Integer]
86
+ # @param map_y [Integer]
87
+ # @param console_x [Integer] default +x+
88
+ # @param console_y [Integer] default +y+
89
+ def initialize(map_x, map_y, location)
90
+ @location = location
91
+ @x = map_x
92
+ @y = map_y
93
+ @age = 0
94
+ end
95
+
96
+ def inspect
97
+ '#<%s:0x%014x @x=%p, @y=%p, @type=%p>' % [self.class, object_id << 1, @x, @y, @type]
98
+ end
99
+
100
+ # @return [Boolean]
101
+ def ===(other)
102
+ type == other.type
103
+ end
104
+
105
+ # @return [Integer]
106
+ def born!
107
+ @age = 0
108
+ end
109
+
110
+ # @return [Integer]
111
+ def age!
112
+ @age += 1
113
+ end
114
+
115
+ # @return [Boolean]
116
+ def enemy?
117
+ worker? || soldier? || queen?
118
+ end
119
+
120
+ # @return [Boolean]
121
+ def mover?
122
+ player? || queen?
123
+ end
124
+
125
+ # @return [Void]
126
+ def change
127
+ Catalog.delete type, self
128
+
129
+ yield
130
+
131
+ Catalog.store type, self
132
+ Catalog.store :changed, self
133
+ end
134
+
135
+ def changed?
136
+ Catalog.fetch :changed, self, false
137
+ end
138
+
139
+ def change!
140
+ Catalog.store :changed, self
141
+ end
142
+
143
+ def destroy!
144
+ Catalog.increment :destroyed, type
145
+
146
+ empty!
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,5 @@
1
+ module Swarm
2
+
3
+ VERSION = '1.0.3'
4
+
5
+ end
data/swarm.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ require File.join(__dir__, 'lib/swarm/version')
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'the-swarm'
5
+ gem.version = Swarm::VERSION
6
+
7
+ gem.author = 'Gino Lucero'
8
+ gem.email = 'glucero@gmail.com'
9
+
10
+ gem.description = 'Squish or be squished!'
11
+ gem.summary = gem.description
12
+
13
+ gem.homepage = 'https://github.com/glucero/swarm'
14
+ gem.license = 'MIT'
15
+
16
+ gem.files = `git ls-files`.split(?\n)
17
+ gem.executables = ['swarm']
18
+
19
+ gem.add_dependency 'curses'
20
+
21
+ gem.post_install_message = "Usage: 'swarm' or 'SWARM=easy swarm'"
22
+
23
+ gem.required_ruby_version = '>= 2.0.0'
24
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: the-swarm
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Gino Lucero
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: curses
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Squish or be squished!
28
+ email: glucero@gmail.com
29
+ executables:
30
+ - swarm
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".yardopts"
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - bin/swarm
41
+ - docs/Swarm.html
42
+ - docs/Swarm/Catalog.html
43
+ - docs/Swarm/Console.html
44
+ - docs/Swarm/Console/Color.html
45
+ - docs/Swarm/Console/NormalKey.html
46
+ - docs/Swarm/Console/PopUp.html
47
+ - docs/Swarm/Console/VIKey.html
48
+ - docs/Swarm/Five.html
49
+ - docs/Swarm/Four.html
50
+ - docs/Swarm/Game.html
51
+ - docs/Swarm/Intro.html
52
+ - docs/Swarm/Level.html
53
+ - docs/Swarm/Map.html
54
+ - docs/Swarm/One.html
55
+ - docs/Swarm/Three.html
56
+ - docs/Swarm/Tile.html
57
+ - docs/Swarm/Two.html
58
+ - docs/_index.html
59
+ - docs/class_list.html
60
+ - docs/css/common.css
61
+ - docs/css/full_list.css
62
+ - docs/css/style.css
63
+ - docs/file.LICENSE.html
64
+ - docs/file.README.html
65
+ - docs/file_list.html
66
+ - docs/frames.html
67
+ - docs/index.html
68
+ - docs/js/app.js
69
+ - docs/js/full_list.js
70
+ - docs/js/jquery.js
71
+ - docs/method_list.html
72
+ - docs/top-level-namespace.html
73
+ - lib/swarm.rb
74
+ - lib/swarm/catalog.rb
75
+ - lib/swarm/console.rb
76
+ - lib/swarm/game.rb
77
+ - lib/swarm/level.rb
78
+ - lib/swarm/levels/five.rb
79
+ - lib/swarm/levels/four.rb
80
+ - lib/swarm/levels/intro.rb
81
+ - lib/swarm/levels/one.rb
82
+ - lib/swarm/levels/three.rb
83
+ - lib/swarm/levels/two.rb
84
+ - lib/swarm/map.rb
85
+ - lib/swarm/tile.rb
86
+ - lib/swarm/version.rb
87
+ - swarm.gemspec
88
+ homepage: https://github.com/glucero/swarm
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message: 'Usage: ''swarm'' or ''SWARM=easy swarm'''
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 2.0.0
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.6.11
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Squish or be squished!
112
+ test_files: []