Class: Petli::Stages::Guess
- Inherits:
-
Base
show all
- Defined in:
- lib/petli/stages/guess.rb
Constant Summary
Constants inherited
from Base
Base::GAME_HEIGHT, Base::GAME_WIDTH
Instance Attribute Summary
Attributes inherited from Tatty::Stage
#framerate
Instance Method Summary
collapse
Methods inherited from Base
#action_bar, #action_pages, #keypress, #left, #top
#goto, #keypress, #move_to, #render, #render_at, #render_box, #screen_height, #screen_size, #screen_width, #step
Constructor Details
#initialize(pet:) ⇒ Guess
Returns a new instance of Guess.
4
5
6
7
8
|
# File 'lib/petli/stages/guess.rb', line 4
def initialize(pet:)
super(pet: pet)
@left = true
@countdown = -1
end
|
Instance Method Details
#actions ⇒ Object
10
11
12
|
# File 'lib/petli/stages/guess.rb', line 10
def actions
%w(left right)
end
|
#draw ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/petli/stages/guess.rb', line 30
def draw
super
if @countdown == -1
render_at(left+4, top+5, "☟") if @left
render_at(left+23, top+5, "☟") unless @left
render_at(left+4, top+6, "▒") if @left
render_at(left+23, top+6, "▒") unless @left
@left = !@left
elsif @countdown == 0
(@petpickedleft == @pickedleft) ? @pet.win : @pet.lose
goto(Main, pet: @pet)
else
render_at(left+4, top+5, "☟") if @pickedleft
render_at(left+23, top+5, "☟") unless @pickedleft
render_at(left+4, top+6, "▒") if @petpickedleft
render_at(left+23, top+6, "▒") unless @petpickedleft
@countdown -= 1
end
end
|
#enter ⇒ Object
14
15
16
|
# File 'lib/petli/stages/guess.rb', line 14
def enter
pet.play(game: :guess)
end
|
#leave ⇒ Object
18
19
20
|
# File 'lib/petli/stages/guess.rb', line 18
def leave
@pet.reset
end
|
#onkey(event) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/petli/stages/guess.rb', line 22
def onkey(event)
return if event.value != "l" and event.value != "r"
@petpickedleft = rand(1..2) == 1
@pickedleft = event.value == "l"
(@petpickedleft == @pickedleft) ? @pet.celebrate : @pet.embarass
@countdown = 10
end
|