Created
February 9, 2013 14:29
-
-
Save Shinpeim/4745443 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
class Player | |
attr_reader :position | |
def initialize(position) | |
@position = position | |
end | |
def move(direction) | |
case direction | |
when :up | |
@position[:y] -= 10 | |
when :down | |
@position[:y] += 10 | |
when :left | |
@position[:x] -= 10 | |
when :right | |
@position[:x] += 10 | |
end | |
end | |
end | |
player = Player.new(:x => 100, :y => 100) | |
player.move(:up) | |
p player.position # => {:x => 100, :y => 90} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment