Class: Game

Inherits:
Object
  • Object
show all
Includes:
Color, Evaluator, InputHandler, Presenter
Defined in:
lib/capim_tictactoe/game.rb

Constant Summary

Constants included from Presenter

Presenter::GREEN_GRASS, Presenter::SILLY_LINE

Instance Method Summary collapse

Methods included from InputHandler

#fetch_human_spot, #parse_args

Methods included from Presenter

#present_game

Methods included from Evaluator

#eval_board, #get_best_move, #winning_move?

Methods included from Color

#line, #o_marker, #pipe, #x_marker

Constructor Details

#initializeGame

Returns a new instance of Game.



16
17
18
19
20
21
# File 'lib/capim_tictactoe/game.rb', line 16

def initialize
  @board = Board.new
  @computer = x_marker
  @human = o_marker
  parse_args
end

Instance Method Details

#start_gameObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/capim_tictactoe/game.rb', line 23

def start_game
  present_game

  until @board.game_over? || @board.tie?
    fetch_human_spot(@board, @human)

    eval_board(@board, @human, @computer, @options[:game_mode]) unless @board.game_over? || @board.tie?
    @board.grid.display
  end

  puts @board.tie? ? "I'ts a tie!" : 'Game over'
end