Class: RouteObject
- Inherits:
-
Object
- Object
- RouteObject
- Includes:
- Colorful
- Defined in:
- lib/ttr/objects/route.rb
Overview
Copyright © 2011 Jesse Sielaff
Instance Attribute Summary collapse
-
#city_objs ⇒ Object
readonly
Returns the value of attribute city_objs.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#player_obj ⇒ Object
Returns the value of attribute player_obj.
-
#points ⇒ Object
readonly
Returns the value of attribute points.
Attributes included from Colorful
Instance Method Summary collapse
-
#connects?(*city_objs) ⇒ Boolean
Returns true if the Route connects the given Cities, false otherwise.
-
#initialize(city_objs, length, color) ⇒ RouteObject
constructor
A new instance of RouteObject.
-
#into?(city_obj) ⇒ Boolean
Returns true if the Route connects to the given City, false otherwise.
-
#twin ⇒ Object
If there are two Routes connecting the two Cities at the end of this Route, returns the other Route.
Methods included from Colorful
Constructor Details
#initialize(city_objs, length, color) ⇒ RouteObject
Returns a new instance of RouteObject.
7 8 9 10 11 12 13 14 15 |
# File 'lib/ttr/objects/route.rb', line 7 def initialize (city_objs, length, color) @city_objs = city_objs @color = color @length = length @player_obj = nil x = length.to_f @points = (Math.sin(4*x/3)*x*x*x/250 + 23*x*x/78 + 7*x/13).round end |
Instance Attribute Details
#city_objs ⇒ Object (readonly)
Returns the value of attribute city_objs.
20 21 22 |
# File 'lib/ttr/objects/route.rb', line 20 def city_objs @city_objs end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
20 21 22 |
# File 'lib/ttr/objects/route.rb', line 20 def length @length end |
#player_obj ⇒ Object
Returns the value of attribute player_obj.
19 20 21 |
# File 'lib/ttr/objects/route.rb', line 19 def player_obj @player_obj end |
#points ⇒ Object (readonly)
Returns the value of attribute points.
20 21 22 |
# File 'lib/ttr/objects/route.rb', line 20 def points @points end |
Instance Method Details
#connects?(*city_objs) ⇒ Boolean
Returns true if the Route connects the given Cities, false otherwise.
24 25 26 |
# File 'lib/ttr/objects/route.rb', line 24 def connects? (*city_objs) (@city_objs & city_objs).length == 2 end |
#into?(city_obj) ⇒ Boolean
Returns true if the Route connects to the given City, false otherwise.
30 31 32 |
# File 'lib/ttr/objects/route.rb', line 30 def into? (city_obj) @city_objs.include?(city_obj) end |
#twin ⇒ Object
If there are two Routes connecting the two Cities at the end of this Route, returns the other Route. Otherwise, returns nil.
37 38 39 |
# File 'lib/ttr/objects/route.rb', line 37 def twin (@city_objs[0].routes_to(@city_objs[1]) - [self])[0] end |