Class: Game

Inherits:
Object
  • Object
show all
Defined in:
lib/manasimu/game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deck) ⇒ Game

Returns a new instance of Game.



4
5
6
7
8
9
10
# File 'lib/manasimu/game.rb', line 4

def initialize(deck)
  @deck = deck.shuffle(random: Random.new)
  @hands = []
  @plays = []
  @planner = Planner.new
  7.times { draw(0) }
end

Instance Attribute Details

#deckObject

Returns the value of attribute deck.



2
3
4
# File 'lib/manasimu/game.rb', line 2

def deck
  @deck
end

#handsObject

Returns the value of attribute hands.



2
3
4
# File 'lib/manasimu/game.rb', line 2

def hands
  @hands
end

#playsObject

Returns the value of attribute plays.



2
3
4
# File 'lib/manasimu/game.rb', line 2

def plays
  @plays
end

Instance Method Details

#draw(turn) ⇒ Object



30
31
32
33
34
35
# File 'lib/manasimu/game.rb', line 30

def draw(turn)
  card = @deck.pop
  # puts "draw #{card}"
  card.drawed(turn)
  @hands << card
end

#planObject



37
38
39
# File 'lib/manasimu/game.rb', line 37

def plan
  @planner.plan(@hands, @plays)
end

#play(card, turn) ⇒ Object



41
42
43
44
45
46
# File 'lib/manasimu/game.rb', line 41

def play(card, turn)
  # puts "play #{card}"
  card.played(turn)
  @plays << card
  @hands.delete card
end

#step(turn) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/manasimu/game.rb', line 12

def step(turn)
  # puts "turn #{turn}"
  # puts "played"
  # @plays.each do |card| puts " #{card}" end
  # puts "hands"
  # @hands.each do |card| puts " #{card}" end

  upkeep(turn)
  draw(turn)
  plan.each do |card| 
    play(card, turn)
  end
end

#upkeep(turn) ⇒ Object



26
27
28
# File 'lib/manasimu/game.rb', line 26

def upkeep(turn)
  @plays.each { |card| card.step(turn) }
end