Class: Mastermind
- Inherits:
-
Object
- Object
- Mastermind
- Defined in:
- lib/mastermind_cli/mastermind.rb
Instance Method Summary collapse
- #game_over? ⇒ Boolean
- #greetings ⇒ Object
-
#initialize ⇒ Mastermind
constructor
A new instance of Mastermind.
- #lose ⇒ Object
- #play ⇒ Object
- #victory ⇒ Object
Constructor Details
#initialize ⇒ Mastermind
Returns a new instance of Mastermind.
6 7 8 9 10 |
# File 'lib/mastermind_cli/mastermind.rb', line 6 def initialize @turn = 0 @board = Board.new @player = Player.new(@board) end |
Instance Method Details
#game_over? ⇒ Boolean
32 33 34 |
# File 'lib/mastermind_cli/mastermind.rb', line 32 def game_over? victory || lose end |
#greetings ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/mastermind_cli/mastermind.rb', line 12 def greetings puts "="*40 puts "Welcome to CLI Mastermind".center(40) puts "Made by FrenchToast".center(40) puts "Available Colors [r b g y p o]".center(40) puts "To make move, enter 4 colors".center(40) puts "For example: rbyg".center(40) puts "="*40 end |
#lose ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/mastermind_cli/mastermind.rb', line 46 def lose if @board.full?(@turn) @board.render puts "I'm Sorry, you lose." puts "Winning combination was: #{@board.win_code}" return true end false end |
#play ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/mastermind_cli/mastermind.rb', line 22 def play greetings until game_over? @board.render @player.make_move(@turn) @turn +=1 end end |
#victory ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/mastermind_cli/mastermind.rb', line 36 def victory if @board.winning_combination?(@turn) @board.render puts "Congratulations, you win!" puts "Your code was: #{@board.win_code}" return true end false end |