Class: Demos::TicTacToe::Square

Inherits:
Hokusai::Block show all
Defined in:
ui/examples/tic_tac_toe.rb

Instance Attribute Summary

Attributes inherited from Hokusai::Block

#node, #provides, #publisher

Instance Method Summary collapse

Methods inherited from Hokusai::Block

#children, #children?, compile, computed, computed!, #draw, #draw_with, #dump, #emit, #initialize, inject, inject!, #method_missing, mount, #on_resize, provide, provides, #render, style, styles_get, template, template_from_file, template_get, #update, use, uses

Constructor Details

This class inherits a constructor from Hokusai::Block

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hokusai::Block

Instance Method Details

#compute_backgroundObject



44
45
46
47
48
49
50
51
52
53
# File 'ui/examples/tic_tac_toe.rb', line 44

def compute_background
  case player
  when Player::X
    [52,168,77]
  when Player::O
    [219,176,57]
  when Player::None
    @hover ? [55, 110, 155] : [47,98,140]
  end
end

#emit_position(click) ⇒ Object



67
68
69
# File 'ui/examples/tic_tac_toe.rb', line 67

def emit_position(click)
  emit("position", position)
end

#has_playerObject



71
72
73
# File 'ui/examples/tic_tac_toe.rb', line 71

def has_player
  player != Player::None
end

#read_positionObject



63
64
65
# File 'ui/examples/tic_tac_toe.rb', line 63

def read_position
  position.inspect
end

#set_hover(event) ⇒ Object



55
56
57
# File 'ui/examples/tic_tac_toe.rb', line 55

def set_hover(event)
  @hover = true
end

#set_mouseout(event) ⇒ Object



59
60
61
# File 'ui/examples/tic_tac_toe.rb', line 59

def set_mouseout(event)
  @hover = false
end

#square_imageObject



75
76
77
78
79
80
81
82
# File 'ui/examples/tic_tac_toe.rb', line 75

def square_image
  case player
  when Player::X
    return "#{__dir__}/assets/science-troll.png"
  when Player::O
    return "#{__dir__}/assets/football-troll.png"
  end
end