Class: MapObject

Inherits:
Object
  • Object
show all
Defined in:
lib/ttr/objects/map.rb

Overview

Copyright © 2011 Jesse Sielaff

Direct Known Subclasses

UsaMap

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMapObject

Returns a new instance of MapObject.



13
14
15
16
17
18
19
# File 'lib/ttr/objects/map.rb', line 13

def initialize
  @city_objs = []
  @route_objs = []
  @ticket_objs = []
  
  build
end

Class Method Details

.inherited(subclass) ⇒ Object



7
8
9
10
11
# File 'lib/ttr/objects/map.rb', line 7

def MapObject.inherited (subclass)
  subclass.define_singleton_method(:play_game) do |*script_names|
    subclass.new.new_game(*script_names).play
  end
end

Instance Method Details

#city(name) ⇒ Object

Creates and returns a new City on the Map.



23
24
25
# File 'lib/ttr/objects/map.rb', line 23

def city (name)
  @city_objs[0...0] = CityObject.new(name.to_sym)
end

#new_game(*script_names) ⇒ Object

Returns a new Game played using the Map, using Players running the named Scripts.



30
31
32
# File 'lib/ttr/objects/map.rb', line 30

def new_game (*script_names)
  GameObject.new(script_names, @city_objs, @route_objs.each {|r| r.player_obj = nil }, @ticket_objs.shuffle)
end

#route(*city_objs, length, color) ⇒ Object

Creates and returns a new Route between the given Cities, with the given length and color.



37
38
39
40
41
# File 'lib/ttr/objects/map.rb', line 37

def route (*city_objs, length, color)
  route_obj = RouteObject.new(city_objs, length, color)
  city_objs.each {|obj| obj.add_route_obj(route_obj) }
  @route_objs[0...0] = route_obj
end

#ticket(points, *city_objs) ⇒ Object

Creates and returns a new Ticket for the given Cities, with the given point value.



46
47
48
# File 'lib/ttr/objects/map.rb', line 46

def ticket (points, *city_objs)
  @ticket_objs[0...0] = TicketObject.new(points, city_objs)
end