Class: MM::MoveGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/games/mastermind/move_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#gameObject

Returns the value of attribute game.



4
5
6
# File 'lib/games/mastermind/move_generator.rb', line 4

def game
  @game
end

Instance Method Details

#computer?Boolean



41
42
43
# File 'lib/games/mastermind/move_generator.rb', line 41

def computer?
  game.current_player_computer?
end

#computer_moveObject



20
21
22
23
24
25
26
# File 'lib/games/mastermind/move_generator.rb', line 20

def computer_move
  secret_code = []
  4.times do
    secret_code.push((1..6).to_a.sample)
  end
  secret_code
end

#current_playerObject



29
30
31
# File 'lib/games/mastermind/move_generator.rb', line 29

def current_player
  game.current_player
end

#get_moveObject



11
12
13
14
15
16
17
18
# File 'lib/games/mastermind/move_generator.rb', line 11

def get_move
  if human?
    input_helper.get_player_choice(game)
  elsif computer?
    input_helper.computer_choosing_graphic
    computer_move
  end
end

#get_player_choice(game) ⇒ Object



6
7
8
9
# File 'lib/games/mastermind/move_generator.rb', line 6

def get_player_choice(game)
  @game = game
  get_move
end

#human?Boolean



37
38
39
# File 'lib/games/mastermind/move_generator.rb', line 37

def human?
  game.current_player_human?
end

#input_helperObject



33
34
35
# File 'lib/games/mastermind/move_generator.rb', line 33

def input_helper
  game.input_helper
end