Class: TTT::Context

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceObject



6
7
8
# File 'lib/ttt/context.rb', line 6

def instance
  @instance ||= new
end

Instance Method Details

#add_game(game) ⇒ Object



34
35
36
# File 'lib/ttt/context.rb', line 34

def add_game(game)
  game_interactor.add_game(game)
end

#adjust_move_index(id, value) ⇒ Object



127
128
129
130
131
132
133
134
# File 'lib/ttt/context.rb', line 127

def adjust_move_index(id, value)
  if game = game_interactor.get_game(id)
    game_interactor.adjust_move_index(game, value)
    game_interactor.save_game(id, game)
  else
    nil
  end
end

#ai_move(id) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/ttt/context.rb', line 71

def ai_move(id)
  if game = game_interactor.get_game(id)
    game_interactor.ai_move(id, game)
  else
    nil
  end
end

#ai_move?(id) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
69
# File 'lib/ttt/context.rb', line 63

def ai_move?(id)
  if game = db_instance.get_game(id)
    game_interactor.ai_move?(game)
  else
    nil
  end
end

#board(id) ⇒ Object



197
198
199
200
201
202
203
# File 'lib/ttt/context.rb', line 197

def board(id)
  if game = game_interactor.get_game(id)
    game_interactor.board(game)
  else
    nil
  end
end

#boardsObject



25
26
27
# File 'lib/ttt/context.rb', line 25

def boards
  @setup.boards
end

#create_game(player1, player2, board) ⇒ Object



29
30
31
32
# File 'lib/ttt/context.rb', line 29

def create_game(player1, player2, board)
  game = @setup.new_game(:player1 => player1, :player2 => player2, :board => board)
  add_game(game)
end

#delete_game(id) ⇒ Object



50
51
52
# File 'lib/ttt/context.rb', line 50

def delete_game(id)
  game_interactor.delete_game(id)
end

#draw?(id) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
106
107
108
109
# File 'lib/ttt/context.rb', line 103

def draw?(id)
  if game = game_interactor.get_game(id)
    game_interactor.draw?(game)
  else
    nil
  end
end

#finished?(id) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
83
84
85
# File 'lib/ttt/context.rb', line 79

def finished?(id)
  if game = game_interactor.get_game(id)
    game_interactor.finished?(game)
  else
    nil
  end
end

#game_listObject



46
47
48
# File 'lib/ttt/context.rb', line 46

def game_list
  game_interactor.game_list
end

#get_game(id) ⇒ Object



38
39
40
# File 'lib/ttt/context.rb', line 38

def get_game(id)
  game_interactor.get_game(id)
end

#get_history(id) ⇒ Object



181
182
183
184
185
186
187
# File 'lib/ttt/context.rb', line 181

def get_history(id)
  if game = game_interactor.get_game(id)
    game_interactor.get_history(game)
  else
    nil
  end
end

#get_history_board(id) ⇒ Object



136
137
138
139
140
141
142
# File 'lib/ttt/context.rb', line 136

def get_history_board(id)
  if game = game_interactor.get_game(id)
    game_interactor.get_history_board(game)
  else
    nil
  end
end

#get_history_length(id) ⇒ Object



167
168
169
170
171
# File 'lib/ttt/context.rb', line 167

def get_history_length(id)
  if game = game_interactor.get_game(id)
    game_interactor.get_history_length(game)
  end
end

#get_move_index(id) ⇒ Object



173
174
175
176
177
178
179
# File 'lib/ttt/context.rb', line 173

def get_move_index(id)
  if game = game_interactor.get_game(id)
    game_interactor.get_move_index(game)
  else
    nil
  end
end

#get_move_traverser(id) ⇒ Object



144
145
146
147
148
149
150
# File 'lib/ttt/context.rb', line 144

def get_move_traverser(id)
  if game = game_interactor.get_game(id)
    game_interactor.get_move_traverser(game)
  else
    nil
  end
end

#initialize_history(id) ⇒ Object



158
159
160
161
162
163
164
165
# File 'lib/ttt/context.rb', line 158

def initialize_history(id)
  if game = game_interactor.get_game(id)
    game_interactor.initialize_history(game)
    save_game(id, game)
  else
    nil
  end
end

#playersObject



21
22
23
# File 'lib/ttt/context.rb', line 21

def players
  @setup.players
end

#save_game(id, game) ⇒ Object



42
43
44
# File 'lib/ttt/context.rb', line 42

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

#save_move_traverser(id, move_traverser) ⇒ Object



152
153
154
155
156
# File 'lib/ttt/context.rb', line 152

def save_move_traverser(id, move_traverser)
  if game = game_interactor.get_game(id)
    game_interactor.save_move_traverser(id, game, move_traverser)
  end
end

#setupObject



17
18
19
# File 'lib/ttt/context.rb', line 17

def setup
  @setup
end

#setup=(setup_const) ⇒ Object



13
14
15
# File 'lib/ttt/context.rb', line 13

def setup=(setup_const)
  @setup = setup_const.new
end

#update_game(id, move, side) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/ttt/context.rb', line 54

def update_game(id, move, side)
  if game = db_instance.get_game(id)
    game_interactor.update_game(game, move, side)
    game_interactor.save_game(id, game)
  else
    nil
  end
end

#valid_move?(id, move) ⇒ Boolean

Returns:

  • (Boolean)


119
120
121
122
123
124
125
# File 'lib/ttt/context.rb', line 119

def valid_move?(id, move)
  if game = game_interactor.get_game(id)
    game_interactor.valid_move?(game, move)
  else
    nil
  end
end

#which_board(id) ⇒ Object



111
112
113
114
115
116
117
# File 'lib/ttt/context.rb', line 111

def which_board(id)
  if game = game_interactor.get_game(id)
    game_interactor.which_board(game)
  else
    nil
  end
end

#which_current_player?(id) ⇒ Boolean

Returns:

  • (Boolean)


189
190
191
192
193
194
195
# File 'lib/ttt/context.rb', line 189

def which_current_player?(id)
  if game = game_interactor.get_game(id)
    game_interactor.which_current_player?(game)
  else
    nil
  end
end

#winner(id) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/ttt/context.rb', line 87

def winner(id)
  if game = game_interactor.get_game(id)
    game_interactor.winner(game)
  else
    nil
  end
end

#winner?(id) ⇒ Boolean

Returns:

  • (Boolean)


95
96
97
98
99
100
101
# File 'lib/ttt/context.rb', line 95

def winner?(id)
  if game = game_interactor.get_game(id)
    game_interactor.winner?(game)
  else
    nil
  end
end