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, shuffle = true, debugg = false) ⇒ Game

Returns a new instance of Game.



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/manasimu/game.rb', line 4

def initialize(deck, shuffle = true, debugg = false)
  if shuffle 
    @deck = deck.shuffle(random: Random.new)
  else
    @deck = deck
  end
  @deck.each { |card| card.reset }
  @hands = []
  @plays = []
  @planner = Planner.new
  @debugg = debugg
  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



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

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

#planObject



47
48
49
# File 'lib/manasimu/game.rb', line 47

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

#play(card, turn) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/manasimu/game.rb', line 51

def play(card, turn)
  if @debugg
    puts "play #{card}"
  end

  card.resolve(nil, @hands, @plays, @deck)
  card.played(turn, nil)
  @plays << card
  @hands.delete card
end

#step(turn) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/manasimu/game.rb', line 18

def step(turn)
  if @debugg
    puts "---------------------------------"
    puts "turn #{turn} basic_lands #{@deck.select {|c| c.instance_of? BasicLandCard}.length}"
    puts "played"
    @plays.each do |card| puts " #{card}" end
    puts "hands"
    @hands.each do |card| puts " #{card}" end
  end

  draw(turn)
  play_cards, deck = plan;
  @hands.each { |card| card.step_in_hands(turn) }
  play_cards.each do |card| 
    play(card, turn)
  end
  deck = deck if deck
  @plays.each { |card| card.step_in_plays(turn) }
end