Class: Game

Inherits:
Object show all
Defined in:
lib/ascension.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.reset!Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/ascension.rb', line 100

def reset!
  Game.collection.remove
  game = Game.new
  side = Side.new(:game => game)
  game.sides << side
  game.sides << Side.new(:game => game)

  game.deck = CenterDeck.starting
  #game.deck << Parse.get("Mephit")
  game.center.fill!
  #side.deck << game.deck.get_one('Temple Librarian')
  #side.deck[-1] = Card::Hero.arha

  #side.deck << Parse.get("Shade ot Black Watch")
  #side.deck << Parse.get("Seer of the Forked Path")
  #side.deck << Parse.get("Demon Slayer")
  game.sides.each do |s|
    s.draw_hand!
  end
  #side.hand << game.deck.get_one('Void Thirster')
  #side.deck << game.deck.get_one('Void Initiate')

  game.mongo.save!
  game
end

Instance Method Details

#addl_json_attributesObject



38
39
40
# File 'lib/ascension.rb', line 38

def addl_json_attributes
  %w(mongo_id engageable_cards constant_cards current_side_index last_update_dt)
end

#after_mongo_loadObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ascension.rb', line 71

def after_mongo_load
  center.game = self
  turn_manager.game = self

  sides.each do |s|
    s.game = self
    %w(discard deck hand played constructs).each do |m|
      s.send(m).side = s
    end
    s.choices.each do |c|
      c.side = s
    end
  end

  card_places.each do |cards|
    cards.hydrate!
  end
end

#card_placesObject



63
64
65
66
67
68
69
# File 'lib/ascension.rb', line 63

def card_places
  places = [deck,center,void]
  sides.each do |side|
    places += [side.hand,side.discard,side.deck,side.played]
  end
  places
end

#constant_cardsObject



53
54
55
# File 'lib/ascension.rb', line 53

def constant_cards
  center_wc.constant_cards
end

#current_side_indexObject



56
57
58
# File 'lib/ascension.rb', line 56

def current_side_index
  turn_manager.current_side_index
end

#engageable_cardsObject



50
51
52
# File 'lib/ascension.rb', line 50

def engageable_cards
  turn_manager.current_side.engageable_cards
end

#find_card(card_id) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/ascension.rb', line 90

def find_card(card_id)
  raise "blank card id" if card_id.blank?
  card_places.each do |cards|
    res = cards.find { |x| x.card_id.to_s == card_id.to_s }
    return res if res
  end
  raise "no card #{card_id}"
end

#last_update_dtObject



59
60
61
# File 'lib/ascension.rb', line 59

def last_update_dt
  Time.now
end