Class: Mastermind

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

Instance Method Summary collapse

Constructor Details

#initializeMastermind

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

Returns:

  • (Boolean)


32
33
34
# File 'lib/mastermind_cli/mastermind.rb', line 32

def game_over?
  victory || lose
end

#greetingsObject



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

#loseObject



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

#playObject



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

#victoryObject



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