Refactoring code: added KeyAction method in Pacman class.