class Snake2d::Game

Public Class Methods

new() click to toggle source
# File lib/snake2d.rb, line 84
def initialize
  @ball_x = 10
  @ball_y = 10
  @score = 0
  @finished = false
end

Public Instance Methods

draw() click to toggle source
# File lib/snake2d.rb, line 91
def draw
  Square.new(x: @ball_x * SQUARE_SIZE, y: @ball_y * SQUARE_SIZE, size: SQUARE_SIZE, color: 'yellow')
  Text.new(text_message, color: 'green', x: 10, y: 10, size: 25, z: 1)
end
finish() click to toggle source
# File lib/snake2d.rb, line 106
def finish
  @finished = true
end
finished?() click to toggle source
# File lib/snake2d.rb, line 110
def finished?
  @finished
end
record_hit() click to toggle source
# File lib/snake2d.rb, line 100
def record_hit
  @score += 1
  @ball_x = rand(Window.width / SQUARE_SIZE)
  @ball_y = rand(Window.height / SQUARE_SIZE)
end
snake_hit_ball?(x, y) click to toggle source
# File lib/snake2d.rb, line 96
def snake_hit_ball?(x, y)
  @ball_x == x && @ball_y == y
end

Private Instance Methods

text_message() click to toggle source
# File lib/snake2d.rb, line 116
def text_message
  if finished?
    "Game over, Your Score was #{@score}. Press 'R' to restart. "
  else
    "Score: #{@score}"
  end
end