Class: Game

Inherits:
Object
  • Object
show all
Defined in:
lib/ttt_malisa/game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(display, rules, player_one, player_two) ⇒ Game

Returns a new instance of Game.



8
9
10
11
12
13
14
# File 'lib/ttt_malisa/game.rb', line 8

def initialize(display, rules, player_one, player_two)
  @rules = rules
  @display = display
  @player_one = player_one
  @player_two = player_two
  @current_player = @player_one
end

Instance Attribute Details

#player_oneObject (readonly)

Returns the value of attribute player_one.



6
7
8
# File 'lib/ttt_malisa/game.rb', line 6

def player_one
  @player_one
end

#player_twoObject (readonly)

Returns the value of attribute player_two.



6
7
8
# File 'lib/ttt_malisa/game.rb', line 6

def player_two
  @player_two
end

#rulesObject (readonly)

Returns the value of attribute rules.



6
7
8
# File 'lib/ttt_malisa/game.rb', line 6

def rules
  @rules
end

Instance Method Details

#game_over_messageObject



34
35
36
# File 'lib/ttt_malisa/game.rb', line 34

def game_over_message
  winner ? @display.winner_message(@current_player.mark) : @display.draw_message
end

#playObject



28
29
30
31
32
# File 'lib/ttt_malisa/game.rb', line 28

def play
  @display.board
  turn until rules.game_over?
  game_over_message
end

#startObject



16
17
18
19
# File 'lib/ttt_malisa/game.rb', line 16

def start
  @display.welcome
  play
end

#turnObject



21
22
23
24
25
26
# File 'lib/ttt_malisa/game.rb', line 21

def turn
  @display.alert_current_player(@current_player)
  @current_player.move
  @display.board
  switch_players
end