Class: TTT::GameInteractor

Inherits:
Object
  • Object
show all
Defined in:
lib/ttt/game_interactor.rb

Instance Method Summary collapse

Constructor Details

#initialize(db) ⇒ GameInteractor

Returns a new instance of GameInteractor.



3
4
5
# File 'lib/ttt/game_interactor.rb', line 3

def initialize(db)
  self.db = db
end

Instance Method Details

#add_game(game) ⇒ Object



7
8
9
# File 'lib/ttt/game_interactor.rb', line 7

def add_game(game)
  db.add_game(game)
end

#adjust_move_index(game, value) ⇒ Object



115
116
117
# File 'lib/ttt/game_interactor.rb', line 115

def adjust_move_index(game, value)
  game.history.move_traverser.adjust_move_index(value)
end

#ai_move(id, game) ⇒ Object



31
32
33
34
# File 'lib/ttt/game_interactor.rb', line 31

def ai_move(id, game)
  game.next_move
  save_game(id, game)
end

#ai_move?(game) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/ttt/game_interactor.rb', line 27

def ai_move?(game)
  game.ai_move?
end

#board(game) ⇒ Object



97
98
99
# File 'lib/ttt/game_interactor.rb', line 97

def board(game)
  game.board[]
end

#delete_game(id) ⇒ Object



23
24
25
# File 'lib/ttt/game_interactor.rb', line 23

def delete_game(id)
  db.delete_game(id)
end

#draw?(game) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/ttt/game_interactor.rb', line 52

def draw?(game)
  game.draw?
end

#finished?(game) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/ttt/game_interactor.rb', line 36

def finished?(game)
  game.finished?
end

#game_listObject



15
16
17
# File 'lib/ttt/game_interactor.rb', line 15

def game_list
  db.game_list
end

#get_game(id) ⇒ Object



11
12
13
# File 'lib/ttt/game_interactor.rb', line 11

def get_game(id)
  db.get_game(id)
end

#get_history(game) ⇒ Object



64
65
66
# File 'lib/ttt/game_interactor.rb', line 64

def get_history(game)
  game.show_history
end

#get_history_board(game) ⇒ Object



77
78
79
# File 'lib/ttt/game_interactor.rb', line 77

def get_history_board(game)
  game.get_history_board
end

#get_history_length(game) ⇒ Object



85
86
87
# File 'lib/ttt/game_interactor.rb', line 85

def get_history_length(game)
  game.show_history.length
end

#get_move_index(game) ⇒ Object



119
120
121
# File 'lib/ttt/game_interactor.rb', line 119

def get_move_index(game)
  game.history.move_traverser.move_index
end

#get_move_traverser(game) ⇒ Object



68
69
70
# File 'lib/ttt/game_interactor.rb', line 68

def get_move_traverser(game)
  game.history.move_traverser
end

#initialize_history(game) ⇒ Object



81
82
83
# File 'lib/ttt/game_interactor.rb', line 81

def initialize_history(game)
  game.initialize_history
end

#mark_move(game, cell, side) ⇒ Object



107
108
109
# File 'lib/ttt/game_interactor.rb', line 107

def mark_move(game, cell, side)
  game.mark_move(cell, side)
end

#not_finished?(game) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/ttt/game_interactor.rb', line 40

def not_finished?(game)
  !game.finished?
end

#record_move(game, cell, side) ⇒ Object



111
112
113
# File 'lib/ttt/game_interactor.rb', line 111

def record_move(game, cell, side)
  game.record_move(cell, side)
end

#save_game(id, game) ⇒ Object



19
20
21
# File 'lib/ttt/game_interactor.rb', line 19

def save_game(id, game)
  db.save_game(id, game)
end

#save_move_traverser(id, game, move_traverser) ⇒ Object



72
73
74
75
# File 'lib/ttt/game_interactor.rb', line 72

def save_move_traverser(id, game, move_traverser)
  game.history.move_traverser = move_traverser
  save_game(id, game)
end

#switch_player(game) ⇒ Object



89
90
91
# File 'lib/ttt/game_interactor.rb', line 89

def switch_player(game)
  game.switch_player
end

#update_game(game, cell, side) ⇒ Object



101
102
103
104
105
# File 'lib/ttt/game_interactor.rb', line 101

def update_game(game, cell, side)
  mark_move(game, cell, side)
  record_move(game, cell, side)
  switch_player(game)
end

#valid_move?(game, move) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/ttt/game_interactor.rb', line 60

def valid_move?(game, move)
  game.valid_move?(move)
end

#which_board(game) ⇒ Object



56
57
58
# File 'lib/ttt/game_interactor.rb', line 56

def which_board(game)
  game.which_board
end

#which_current_player?(game) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/ttt/game_interactor.rb', line 93

def which_current_player?(game)
  game.which_current_player?
end

#winner(game) ⇒ Object



48
49
50
# File 'lib/ttt/game_interactor.rb', line 48

def winner(game)
  game.last_player
end

#winner?(game) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/ttt/game_interactor.rb', line 44

def winner?(game)
  game.winner?
end