我需要在我的代码中使用“ruby2d”并编写一个简单的程序来构建我的蛇游戏。我试图让程序在屏幕上弹出一个窗口。这是我的代码
require 'ruby2d'
set background: 'navy'
#width = 640 / 20 =32
#height = 480 / 2- = 24
GRID_SIZE = 20
class Snake
def init
@positions = [[2,0], [2,1], [2,2], [2,3]]
end
def draw
@positions.each do |position|
Square.new(x:position[0] * GRID_SIZE, y: position[1] * GRID_SIZE, size: GRID_SIZE, color: 'white')
end
end
end
snake = Snake.new
snake.draw
show
我还在终端中运行了命令 gem install ruby2d 它给了我这个错误,
Fetching ruby2d-0.10.0.gem
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.