Class: Swarm::Tile
Constant Summary
Constants included from Console::Color
Console::Color::BLACK, Console::Color::BLUE, Console::Color::GREEN, Console::Color::GREY, Console::Color::PURPLE, Console::Color::RED, Console::Color::SILVER, Console::Color::WHITE, Console::Color::YELLOW
Instance Attribute Summary collapse
- #age ⇒ Integer readonly
- #color ⇒ Integer readonly
- #icon ⇒ String readonly
-
#location ⇒ Object
readonly
Returns the value of attribute location.
- #type ⇒ Symbol readonly
-
#x ⇒ Integer
readonly
The position of the
tileon the x axis. -
#y ⇒ Integer
readonly
The position of the
tileon the y axis.
Class Method Summary collapse
-
.attr_type(type, icon: String.new, color: 0) ⇒ Object
Create methods for setting and testing the
typevalue, change status and console color of everyTile.
Instance Method Summary collapse
- #===(other) ⇒ Boolean
- #age! ⇒ Integer
- #born! ⇒ Integer
- #change ⇒ Void
- #change! ⇒ Object
- #changed? ⇒ Boolean
- #destroy! ⇒ Object
-
#dirt ⇒ true
set the
typeto :dirt, theiconto ██, thecolorto color: SILVER, theageto and flags the tile to be updated by theConsoleattr_type, dirt, ██, color: SILVER, , , ,. -
#dirt! ⇒ true
set the
typeto :dirt, theiconto '██', thecolorto color: SILVER, theageto 0, and flags the tile to be updated by theConsole. -
#dirt? ⇒ Boolean
test the value of
type. -
#egg ⇒ true
set the
typeto :egg, theicontooo, thecolorto color: YELLOW, theageto and flags the tile to be updated by theConsoleattr_type, egg, oo, color: YELLOW, , , ,. -
#egg! ⇒ true
set the
typeto :egg, theiconto 'oo', thecolorto color: YELLOW, theageto 0, and flags the tile to be updated by theConsole. -
#egg? ⇒ Boolean
test the value of
type. -
#empty ⇒ true
set the
typeto :empty, theiconto + +, thecolorto color: BLACK, theageto and flags the tile to be updated by theConsoleattr_type, empty, , color: BLACK, , , ,. -
#empty! ⇒ true
set the
typeto :empty, theiconto ' ', thecolorto color: BLACK, theageto 0, and flags the tile to be updated by theConsole. -
#empty? ⇒ Boolean
test the value of
type. - #enemy? ⇒ Boolean
-
#initialize(map_x, map_y, location) ⇒ Tile
constructor
Initialize a
Tilewith thexand bothypositions (ConsoleandMap) on theConsole. - #inspect ⇒ Object
- #mover? ⇒ Boolean
-
#player ⇒ true
set the
typeto :player, theiconto ◄▶, thecolorto color: GREEN, theageto and flags the tile to be updated by theConsoleattr_type, player, ◄▶, color: GREEN, , , ,. -
#player! ⇒ true
set the
typeto :player, theiconto '◄▶', thecolorto color: GREEN, theageto 0, and flags the tile to be updated by theConsole. -
#player? ⇒ Boolean
test the value of
type. -
#queen ⇒ true
set the
typeto :queen, theiconto ╬╬, thecolorto color: PURPLE, theageto and flags the tile to be updated by theConsoleattr_type, queen, ╬╬, color: PURPLE, , , ,. -
#queen! ⇒ true
set the
typeto :queen, theiconto '╬╬', thecolorto color: PURPLE, theageto 0, and flags the tile to be updated by theConsole. -
#queen? ⇒ Boolean
test the value of
type. -
#rock ⇒ true
set the
typeto :rock, theiconto ██, thecolorto color: WHITE, theageto and flags the tile to be updated by theConsoleattr_type, rock, ██, color: WHITE, , , ,. -
#rock! ⇒ true
set the
typeto :rock, theiconto '██', thecolorto color: WHITE, theageto 0, and flags the tile to be updated by theConsole. -
#rock? ⇒ Boolean
test the value of
type. -
#soldier ⇒ true
set the
typeto :soldier, theiconto ╟╢, thecolorto color: RED, theageto and flags the tile to be updated by theConsoleattr_type, soldier, ╟╢, color: RED, , , ,. -
#soldier! ⇒ true
set the
typeto :soldier, theiconto '╟╢', thecolorto color: RED, theageto 0, and flags the tile to be updated by theConsole. -
#soldier? ⇒ Boolean
test the value of
type. -
#worker ⇒ true
set the
typeto :worker, theiconto ├┤, thecolorto color: BLUE, theageto and flags the tile to be updated by theConsoleattr_type, worker, ├┤, color: BLUE, , , ,. -
#worker! ⇒ true
set the
typeto :worker, theiconto '├┤', thecolorto color: BLUE, theageto 0, and flags the tile to be updated by theConsole. -
#worker? ⇒ Boolean
test the value of
type.
Constructor Details
#initialize(map_x, map_y, location) ⇒ Tile
Initialize a Tile with the x and both
y positions (Console and Map) on the
Console. Since tiles are 2 characters wide, two sets
coordinates are stored: the position in the console (+@location+) and the
position on the map (+@x+ and @y). All tiles start off as
:empty.
89 90 91 92 93 94 |
# File 'lib/swarm/tile.rb', line 89 def initialize(map_x, map_y, location) @location = location @x = map_x @y = map_y @age = 0 end |
Instance Attribute Details
#age ⇒ Integer (readonly)
78 79 80 |
# File 'lib/swarm/tile.rb', line 78 def age @age end |
#color ⇒ Integer (readonly)
73 74 75 |
# File 'lib/swarm/tile.rb', line 73 def color @color end |
#icon ⇒ String (readonly)
70 71 72 |
# File 'lib/swarm/tile.rb', line 70 def icon @icon end |
#location ⇒ Object (readonly)
Returns the value of attribute location
75 76 77 |
# File 'lib/swarm/tile.rb', line 75 def location @location end |
#type ⇒ Symbol (readonly)
67 68 69 |
# File 'lib/swarm/tile.rb', line 67 def type @type end |
#x ⇒ Integer (readonly)
Returns the position of the tile on the x axis.
61 62 63 |
# File 'lib/swarm/tile.rb', line 61 def x @x end |
#y ⇒ Integer (readonly)
Returns the position of the tile on the y axis.
64 65 66 |
# File 'lib/swarm/tile.rb', line 64 def y @y end |
Class Method Details
.attr_type(type, icon: String.new, color: 0) ⇒ Object
Create methods for setting and testing the type value, change
status and console color of every Tile.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/swarm/tile.rb', line 28 def attr_type(type, icon: String.new, color: 0) define_method(type) do |age| change do @type = type @icon = icon @color = color @age = age end self end define_method("#{type}!") { send type, 0 } define_method("#{type}?") { @type == type } end |
Instance Method Details
#===(other) ⇒ Boolean
101 102 103 |
# File 'lib/swarm/tile.rb', line 101 def ===(other) type == other.type end |
#age! ⇒ Integer
111 112 113 |
# File 'lib/swarm/tile.rb', line 111 def age! @age += 1 end |
#born! ⇒ Integer
106 107 108 |
# File 'lib/swarm/tile.rb', line 106 def born! @age = 0 end |
#change ⇒ Void
126 127 128 129 130 131 132 133 |
# File 'lib/swarm/tile.rb', line 126 def change Catalog.delete type, self yield Catalog.store type, self Catalog.store :changed, self end |
#change! ⇒ Object
139 140 141 |
# File 'lib/swarm/tile.rb', line 139 def change! Catalog.store :changed, self end |
#changed? ⇒ Boolean
135 136 137 |
# File 'lib/swarm/tile.rb', line 135 def changed? Catalog.fetch :changed, self, false end |
#destroy! ⇒ Object
143 144 145 146 147 |
# File 'lib/swarm/tile.rb', line 143 def destroy! Catalog.increment :destroyed, type empty! end |
#dirt ⇒ true
set the type to :dirt, the icon to ██, the
color to color: SILVER, the age to and flags the
tile to be updated by the Console attr_type, dirt, ██, color:
SILVER, , , ,
49 |
# File 'lib/swarm/tile.rb', line 49 attr_type :dirt, icon: '██'.freeze, color: SILVER |
#dirt! ⇒ true
set the type to :dirt, the icon to '██',
the color to color: SILVER, the age to 0, and
flags the tile to be updated by the Console
49 |
# File 'lib/swarm/tile.rb', line 49 attr_type :dirt, icon: '██'.freeze, color: SILVER |
#dirt? ⇒ Boolean
test the value of type
49 |
# File 'lib/swarm/tile.rb', line 49 attr_type :dirt, icon: '██'.freeze, color: SILVER |
#egg ⇒ true
set the type to :egg, the icon to
oo, the color to color: YELLOW, the
age to and flags the tile to be updated by the
Console attr_type, egg, oo, color: YELLOW, , , ,
54 |
# File 'lib/swarm/tile.rb', line 54 attr_type :egg, icon: 'oo'.freeze, color: YELLOW |
#egg! ⇒ true
set the type to :egg, the icon to 'oo',
the color to color: YELLOW, the age to 0, and
flags the tile to be updated by the Console
54 |
# File 'lib/swarm/tile.rb', line 54 attr_type :egg, icon: 'oo'.freeze, color: YELLOW |
#egg? ⇒ Boolean
test the value of type
54 |
# File 'lib/swarm/tile.rb', line 54 attr_type :egg, icon: 'oo'.freeze, color: YELLOW |
#empty ⇒ true
set the type to :empty, the icon to + +, the
color to color: BLACK, the age to and flags the
tile to be updated by the Console attr_type, empty, , color:
BLACK, , , ,
48 |
# File 'lib/swarm/tile.rb', line 48 attr_type :empty, icon: ' '.freeze, color: BLACK |
#empty! ⇒ true
set the type to :empty, the icon to ' ',
the color to color: BLACK, the age to 0, and
flags the tile to be updated by the Console
48 |
# File 'lib/swarm/tile.rb', line 48 attr_type :empty, icon: ' '.freeze, color: BLACK |
#empty? ⇒ Boolean
test the value of type
48 |
# File 'lib/swarm/tile.rb', line 48 attr_type :empty, icon: ' '.freeze, color: BLACK |
#enemy? ⇒ Boolean
116 117 118 |
# File 'lib/swarm/tile.rb', line 116 def enemy? worker? || soldier? || queen? end |
#inspect ⇒ Object
96 97 98 |
# File 'lib/swarm/tile.rb', line 96 def inspect '#<%s:0x%014x @x=%p, @y=%p, @type=%p>' % [self.class, object_id << 1, @x, @y, @type] end |
#mover? ⇒ Boolean
121 122 123 |
# File 'lib/swarm/tile.rb', line 121 def mover? player? || queen? end |
#player ⇒ true
set the type to :player, the icon to ◄▶, the
color to color: GREEN, the age to and flags the
tile to be updated by the Console attr_type, player, ◄▶,
color: GREEN, , , ,
55 |
# File 'lib/swarm/tile.rb', line 55 attr_type :player, icon: '◄▶'.freeze, color: GREEN |
#player! ⇒ true
set the type to :player, the icon to
'◄▶', the color to color: GREEN, the age
to 0, and flags the tile to be updated by the Console
55 |
# File 'lib/swarm/tile.rb', line 55 attr_type :player, icon: '◄▶'.freeze, color: GREEN |
#player? ⇒ Boolean
test the value of type
55 |
# File 'lib/swarm/tile.rb', line 55 attr_type :player, icon: '◄▶'.freeze, color: GREEN |
#queen ⇒ true
set the type to :queen, the icon to ╬╬, the
color to color: PURPLE, the age to and flags the
tile to be updated by the Console attr_type, queen, ╬╬, color:
PURPLE, , , ,
53 |
# File 'lib/swarm/tile.rb', line 53 attr_type :queen, icon: '╬╬'.freeze, color: PURPLE |
#queen! ⇒ true
set the type to :queen, the icon to '╬╬',
the color to color: PURPLE, the age to 0, and
flags the tile to be updated by the Console
53 |
# File 'lib/swarm/tile.rb', line 53 attr_type :queen, icon: '╬╬'.freeze, color: PURPLE |
#queen? ⇒ Boolean
test the value of type
53 |
# File 'lib/swarm/tile.rb', line 53 attr_type :queen, icon: '╬╬'.freeze, color: PURPLE |
#rock ⇒ true
set the type to :rock, the icon to ██, the
color to color: WHITE, the age to and flags the
tile to be updated by the Console attr_type, rock, ██, color:
WHITE, , , ,
50 |
# File 'lib/swarm/tile.rb', line 50 attr_type :rock, icon: '██'.freeze, color: WHITE |
#rock! ⇒ true
set the type to :rock, the icon to '██',
the color to color: WHITE, the age to 0, and
flags the tile to be updated by the Console
50 |
# File 'lib/swarm/tile.rb', line 50 attr_type :rock, icon: '██'.freeze, color: WHITE |
#rock? ⇒ Boolean
test the value of type
50 |
# File 'lib/swarm/tile.rb', line 50 attr_type :rock, icon: '██'.freeze, color: WHITE |
#soldier ⇒ true
set the type to :soldier, the icon to ╟╢, the
color to color: RED, the age to and flags the
tile to be updated by the Console attr_type, soldier, ╟╢,
color: RED, , , ,
52 |
# File 'lib/swarm/tile.rb', line 52 attr_type :soldier, icon: '╟╢'.freeze, color: RED |
#soldier! ⇒ true
set the type to :soldier, the icon to
'╟╢', the color to color: RED, the age to
0, and flags the tile to be updated by the Console
52 |
# File 'lib/swarm/tile.rb', line 52 attr_type :soldier, icon: '╟╢'.freeze, color: RED |
#soldier? ⇒ Boolean
test the value of type
52 |
# File 'lib/swarm/tile.rb', line 52 attr_type :soldier, icon: '╟╢'.freeze, color: RED |
#worker ⇒ true
set the type to :worker, the icon to ├┤, the
color to color: BLUE, the age to and flags the
tile to be updated by the Console attr_type, worker, ├┤,
color: BLUE, , , ,
51 |
# File 'lib/swarm/tile.rb', line 51 attr_type :worker, icon: '├┤'.freeze, color: BLUE |
#worker! ⇒ true
set the type to :worker, the icon to
'├┤', the color to color: BLUE, the age
to 0, and flags the tile to be updated by the Console
51 |
# File 'lib/swarm/tile.rb', line 51 attr_type :worker, icon: '├┤'.freeze, color: BLUE |
#worker? ⇒ Boolean
test the value of type
51 |
# File 'lib/swarm/tile.rb', line 51 attr_type :worker, icon: '├┤'.freeze, color: BLUE |