Class: TTT::Game

Inherits:
Shared::Game show all
Defined in:
lib/games/tictactoe/game.rb

Instance Attribute Summary collapse

Attributes inherited from Shared::Game

#board, #board_builder, #board_presenter, #config, #game_module, #game_resetter, #game_state_changer, #input_helper, #io, #move_generator, #number_of_turns_taken, #players, #players_factory

Instance Method Summary collapse

Methods inherited from Shared::Game

#change_game_state, #current_player, #current_player_computer?, #current_player_human?, #current_player_name, #display_values, #every_time_setup, #generate_empty_board, #initialize, #move_forward_one_turn, #one_time_setup, #play, #winner

Constructor Details

This class inherits a constructor from Shared::Game

Instance Attribute Details

#won_flagObject

Returns the value of attribute won_flag.



5
6
7
# File 'lib/games/tictactoe/game.rb', line 5

def won_flag
  @won_flag
end

Instance Method Details

#available_choicesObject



32
33
34
# File 'lib/games/tictactoe/game.rb', line 32

def available_choices
  board.available_choices
end

#change_square(display_value, current_player_value) ⇒ Object



56
57
58
# File 'lib/games/tictactoe/game.rb', line 56

def change_square(display_value, current_player_value)
  board.change_square(display_value, current_player_value)
end

#current_player_difficult_computer?Boolean



48
49
50
# File 'lib/games/tictactoe/game.rb', line 48

def current_player_difficult_computer?
  current_player_computer? && current_player.difficulty_level == :difficult
end

#current_player_easy_computer?Boolean



52
53
54
# File 'lib/games/tictactoe/game.rb', line 52

def current_player_easy_computer?
  current_player_computer? && current_player.difficulty_level == :easy
end

#current_player_valueObject



44
45
46
# File 'lib/games/tictactoe/game.rb', line 44

def current_player_value
  current_player.value
end

#local_setupObject



7
8
9
# File 'lib/games/tictactoe/game.rb', line 7

def local_setup
  self.won_flag = false
end

#over?Boolean



12
13
14
# File 'lib/games/tictactoe/game.rb', line 12

def over?
  won_flag || over_with_no_winner?
end

#over_with_no_winner?Boolean



16
17
18
# File 'lib/games/tictactoe/game.rb', line 16

def over_with_no_winner?
  board.full?
end

#player_1_valueObject



36
37
38
# File 'lib/games/tictactoe/game.rb', line 36

def player_1_value
  players[0].value
end

#player_2_valueObject



40
41
42
# File 'lib/games/tictactoe/game.rb', line 40

def player_2_value
  players[1].value
end

#won?Boolean



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/games/tictactoe/game.rb', line 20

def won?
  if won_flag
    return true
  end

  if board.won?
    self.won_flag = true
  else
    false
  end
end