Class: Snake2d::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/snake2d.rb

Instance Method Summary collapse

Constructor Details

#initializeGame

Returns a new instance of Game.



84
85
86
87
88
89
# File 'lib/snake2d.rb', line 84

def initialize
  @ball_x = 10
  @ball_y = 10
  @score = 0
  @finished = false
end

Instance Method Details

#drawObject



91
92
93
94
# 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

#finishObject



106
107
108
# File 'lib/snake2d.rb', line 106

def finish
  @finished = true
end

#finished?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/snake2d.rb', line 110

def finished?
  @finished
end

#record_hitObject



100
101
102
103
104
# 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) ⇒ Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/snake2d.rb', line 96

def snake_hit_ball?(x, y)
  @ball_x == x && @ball_y == y
end