Class: MastermindSname::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/mastermind_sname/sname/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommand

Returns a new instance of Command.



5
6
7
# File 'lib/mastermind_sname/sname/command.rb', line 5

def initialize
  @game_colours = game_colours
end

Instance Attribute Details

#game_coloursObject

Returns the value of attribute game_colours.



4
5
6
# File 'lib/mastermind_sname/sname/command.rb', line 4

def game_colours
  @game_colours
end

#guessesObject

Returns the value of attribute guesses.



4
5
6
# File 'lib/mastermind_sname/sname/command.rb', line 4

def guesses
  @guesses
end

Instance Method Details

#action(guess, game_colours, guesses) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/mastermind_sname/sname/command.rb', line 9

def action(guess, game_colours, guesses)
  @game_colours = game_colours
  @guesses = guesses
  case guess
  when "quit", "q" then exit
  when "cheat", "c" then cheat_mode
  when "h", "history" then get_history
  end
end

#cheat_modeObject



19
20
21
22
# File 'lib/mastermind_sname/sname/command.rb', line 19

def cheat_mode
  puts Message.new.cheat(@game_colours)
  exit
end

#get_historyObject



24
25
26
27
28
29
30
# File 'lib/mastermind_sname/sname/command.rb', line 24

def get_history
  return "No guesses yet" if @guesses.empty?
  @guesses.each_with_index\
   { |val, i| print " #{i + 1} ==> #{val} \n" }
  print "\n"
  puts "Enter guess"
end