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

Methods inherited from Tatty::Stage

#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

#actionsObject



10
11
12
13
14
15
# File 'lib/petli/stages/guess.rb', line 10

def actions
  {
    left:  -> {pick("l")},
    right: -> {pick("r")},
  }
end

#drawObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/petli/stages/guess.rb', line 32

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

#enterObject



17
18
19
# File 'lib/petli/stages/guess.rb', line 17

def enter
  pet.play(game: :guess)
end

#leaveObject



21
22
23
# File 'lib/petli/stages/guess.rb', line 21

def leave
  @pet.reset
end

#pick(dir) ⇒ Object



25
26
27
28
29
30
# File 'lib/petli/stages/guess.rb', line 25

def pick(dir)
  @petpickedleft = rand(1..2) == 1
  @pickedleft = dir == "l"
  (@petpickedleft == @pickedleft) ? @pet.celebrate : @pet.embarass
  @countdown = 10
end