def sum x, y x + y end
class Game attr_accessor :grid_size def initialize grid_size @grid_size = grid_size #... end
game = Game.new # Equivalently: game = Game.new()
if v == Up or v == Down game.change_dir v elsif v == Esc Gtk.main_quit else puts v end
if is_apple pos then return false end
for x in 1..3 puts x endgives:
1 2 3
5.times { @snake_body.push( last ) }
w.connect( "key_press" ) do |widget, event| v = event.keyval # ... end
for x in 1...3 puts x endgives:
1 2
size = [ 3, 4 ] @cr.rectangle 0, 0, *size # (rectangle takes 4 arguments)
@game.snake_body.each do |pos| gfx.dot Snake_color, pos end
case @snake_dir when Up x = pos[0] y = pos[1] - 1 # No fallthrough! when Down x = pos[0] y = pos[1] + 1 end
return a # is not the same as: return a
Patreon! | patreon.com/andybalaam |
---|---|
Videos | youtube.com/user/ajbalaam |
@andybalaam | |
Blog | artificialworlds.net/blog |
Projects | artificialworlds.net |