Class: SnakeGame::Position

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/position.rb

Overview

Class for storing coordinates

Constant Summary

Constants included from Constants

Constants::EVASION, Constants::FPS, Constants::HEIGHT, Constants::NEXTLEVEL, Constants::STEP, Constants::WIDTH

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y) ⇒ Position

Returns a new instance of Position.



8
9
10
11
# File 'lib/position.rb', line 8

def initialize(x, y)
  @x = x
  @y = y
end

Instance Attribute Details

#xObject

Returns the value of attribute x.



7
8
9
# File 'lib/position.rb', line 7

def x
  @x
end

#yObject

Returns the value of attribute y.



7
8
9
# File 'lib/position.rb', line 7

def y
  @y
end

Instance Method Details

#+(other) ⇒ Object



17
18
19
# File 'lib/position.rb', line 17

def +(other)
  Position.new (x + other.x) % WIDTH, (y + other.y) % HEIGHT
end

#==(other) ⇒ Object



13
14
15
# File 'lib/position.rb', line 13

def ==(other)
  x == other.x && y == other.y
end