Class: APanzer::Game

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

Constant Summary collapse

PANZER =
[]

Instance Method Summary collapse

Constructor Details

#initializeGame

Returns a new instance of Game.



35
36
37
38
39
40
# File 'lib/a_panzer.rb', line 35

def initialize
  @position = 0
  @sprite = 0
  @pew = false
  @moving = false
end

Instance Method Details

#animateObject



65
66
67
68
69
70
71
72
73
74
# File 'lib/a_panzer.rb', line 65

def animate
  if @pew
    @sprite += 1
    @sprite %= PANZER.size
    @pew = false if @sprite == 0
  elsif @moving
    @position += @moving
    @moving = false if @position == 0
  end
end

#boardObject



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

def board
  PANZER[@sprite].split("\n").map { |l| "#{" " * @position}#{l}" }
end

#move(x) ⇒ Object



54
55
56
57
58
# File 'lib/a_panzer.rb', line 54

def move(x)
  return if @pew
  @moving = x
  animate
end

#moving?Boolean

Returns:

  • (Boolean)


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

def moving?
  @moving
end

#pew?Boolean

Returns:

  • (Boolean)


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

def pew?
  @pew
end

#shootObject



60
61
62
63
# File 'lib/a_panzer.rb', line 60

def shoot
  @pew = true
  animate
end