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.



3
4
5
6
7
# File 'lib/mastermind_cli/mastermind.rb', line 3

def initialize
	@turn = 0
	@board = Board.new
	@player = Player.new(@board)
end

Instance Method Details

#game_over?Boolean

Returns:

  • (Boolean)


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

def game_over?
	victory || lose
end

#greetingsObject



9
10
11
12
13
14
15
16
17
# File 'lib/mastermind_cli/mastermind.rb', line 9

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



43
44
45
46
47
48
49
50
51
# File 'lib/mastermind_cli/mastermind.rb', line 43

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



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

def play
	greetings
	until game_over?
		@board.render
		@player.make_move(@turn)
		@turn +=1
	end
end

#victoryObject



33
34
35
36
37
38
39
40
41
# File 'lib/mastermind_cli/mastermind.rb', line 33

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