Sha256: 9ef1c483454c135e079dfdc8fc9f04526bda8139990e39e8e3c12861a6bf166d

Contents?: true

Size: 432 Bytes

Versions: 1

Compression:

Stored size: 432 Bytes

Contents

module GooseGame
  class Player
    attr_reader :name
    attr_accessor :position

    def initialize(name)
      @name = name
      @position = START
      @prev = nil
    end

    alias_method :to_s, :name

    def move(pos)
      return if pos == @position
      @prev, @position = @position, pos.to_i
    end

    def won?
      @position == FINISH
    end

    def prev
      @prev.to_i.zero? ? START : @prev
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
goose_game-1.0.0 lib/goose_game/player.rb