Class: Pacman

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

Overview

Trida Pacman je hlavni trida ktera reprezentuje celou hru.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePacman

Vytvori novou instanci hry



22
23
24
25
26
27
28
29
30
# File 'lib/pacman.rb', line 22

def initialize
  @pc_speed = 10
  @gh_sp = 15
  @time_mark = 0
  @area = Area.new
  @ghosts = []
  make_ghosts
  @player = Player.new(@area.pc_pos[:x], @area.pc_pos[:y], @pc_speed, 1)
end

Instance Attribute Details

#areaObject (readonly)

mapa hry



100
101
102
# File 'lib/pacman.rb', line 100

def area
  @area
end

#ghostsObject (readonly)

pole duchu ve hre



97
98
99
# File 'lib/pacman.rb', line 97

def ghosts
  @ghosts
end

#playerObject (readonly)

postava ovladana hracem



103
104
105
# File 'lib/pacman.rb', line 103

def player
  @player
end

Instance Method Details

#move(direction) ⇒ Object

Zmeni smer pohybu hrace na direction

  • Args :

    • direction -> novy smer pohybu hrace



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

def move(direction)
  @player.direction = direction
end

#updateObject

Aktualizuje stav hry

  • Returns :

    • GAME_OVER -> Konec hry



50
51
52
53
54
55
56
57
58
# File 'lib/pacman.rb', line 50

def update
  try_time
  @player.move if @player.can_move(@area)
  if @player.collect_bonus(@area) == 10
    make_ghosts_blue
    @time_mark = Time.now
  end
  update_ghosts
end