Sha256: 71b35bcc8d34d815dcd750cddbab801f07852a57865522c89ff7cfb99d443607
Contents?: true
Size: 1.09 KB
Versions: 6
Compression:
Stored size: 1.09 KB
Contents
# encoding: UTF-8 require 'typesafe_enum' # A direction on the hexagonal board of the game. Possible directions are: # * RIGHT # * UP_RIGHT # * UP_LEFT # * LEFT # * DOWN_LEFT # * DOWN_RIGHT # Access them as Direction::RIGHT for example. class Direction < TypesafeEnum::Base new :RIGHT new :UP_RIGHT new :UP_LEFT new :LEFT new :DOWN_LEFT new :DOWN_RIGHT # @param direction [Direction] starting direction # @param turns [Integer] number of turns (positive means turning # counterclockwise). # @return [Direction] The direction when turning the given number of steps # from the given direction. def self.get_turn_direction(direction, turns) # order of directions is equal to counterclockwise turning Direction.find_by_ord((direction.ord + turns) % 6) end # @return [Turn] The Turn action to get from from_direction to to_direction. def self.from_to(from_direction, to_direction) distance = (to_direction.ord - from_direction.ord + 6) % 6 if distance > 3 distance = distance - 6 end Turn.new(distance) end end
Version data entries
6 entries across 6 versions & 1 rubygems