Class: Snake2d::Game
- Inherits:
-
Object
- Object
- Snake2d::Game
- Defined in:
- lib/snake2d.rb
Instance Method Summary collapse
- #draw ⇒ Object
- #finish ⇒ Object
- #finished? ⇒ Boolean
-
#initialize ⇒ Game
constructor
A new instance of Game.
- #record_hit ⇒ Object
- #snake_hit_ball?(x, y) ⇒ Boolean
Constructor Details
#initialize ⇒ Game
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
#draw ⇒ Object
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(, color: 'green', x: 10, y: 10, size: 25, z: 1) end |
#finish ⇒ Object
106 107 108 |
# File 'lib/snake2d.rb', line 106 def finish @finished = true end |
#finished? ⇒ Boolean
110 111 112 |
# File 'lib/snake2d.rb', line 110 def finished? @finished end |
#record_hit ⇒ Object
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
96 97 98 |
# File 'lib/snake2d.rb', line 96 def snake_hit_ball?(x, y) @ball_x == x && @ball_y == y end |