Class: MastermindSname::Command
- Inherits:
-
Object
- Object
- MastermindSname::Command
- Defined in:
- lib/mastermind_sname/sname/command.rb
Instance Attribute Summary collapse
-
#game_colours ⇒ Object
Returns the value of attribute game_colours.
-
#guesses ⇒ Object
Returns the value of attribute guesses.
Instance Method Summary collapse
- #action(guess, game_colours, guesses) ⇒ Object
- #cheat_mode ⇒ Object
- #get_history ⇒ Object
-
#initialize ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize ⇒ Command
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_colours ⇒ Object
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 |
#guesses ⇒ Object
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_mode ⇒ Object
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_history ⇒ Object
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 |