class RubyTerminalGames::Snake::Apple
Attributes
height[R]
position[R]
width[R]
Public Class Methods
new(width:, height:)
click to toggle source
# File lib/ruby_terminal_games/snake/apple.rb, line 5 def initialize(width:, height:) @width = width @height = height @position = [height - 4, width - 4] end
Public Instance Methods
move(snake)
click to toggle source
# File lib/ruby_terminal_games/snake/apple.rb, line 11 def move(snake) begin moved = [ rand(height - 4) + 2, rand(width - 4) + 2 ] end while snake.used?(moved) @position = moved end