<commit_before>class Window < Gosu::Window
  NUM_TILES = 6
  TILE_COLS = 2
  VELOCITY = 3
  BLACK = Gosu::Color.argb(0xff000000)

  module YAccessible
    attr_writer :y
    def y
      @y.to_i
    end
  end

  def initialize
    super(1200, 800, false)
    @carpet = Carpet.new(self)
    @backgrounds = NUM_TILES.times.collect do
      Gosu::Image.new(self, 'media/background.jpg', true).extend(YAccessible)
    end
    @font = Gosu::Font.new(self, Gosu::default_font_name, 60)
    @yplus = -@backgrounds.last.height
    @counter = 0
    @genielamps = []
    @endboss = []
    @score = 1
  end

  def draw
    @carpet.draw
    @font.draw("Score: #{@score}", 10, 10, 5, 1, 1, color = BLACK)
    @backgrounds.each_with_index do | bg, index |
      bg.y = (index / TILE_COLS) * bg.height + @yplus
      bg.draw((index % TILE_COLS) * bg.width, bg.y, 1)
    end
    @genielamps.each {|genielamp| genielamp.draw}
    @endboss.each {|endboss| endboss.draw}
  end

  def update
    @counter += 1
    if button_down? Gosu::KbLeft
      @carpet.move_left
    end
    if button_down? Gosu::KbRight
      @carpet.move_right
    end
    scroll_background
    unless @score == 0
      if @counter % 120 == 1
        @genielamps.push LampWithGenie.new(self)
      end
    else
      @endboss.push Endboss.new(self) if @endboss.empty? && @genielamps.empty?
    end
    scroll_lamps
    @genielamps.any? do |genielamp|
      if !genielamp.lamp.rubbed? && @carpet.collides_with?(genielamp.lamp)
        genielamp.lamp.rub!
      end
      if genielamp.lamp.rubbed? && !genielamp.genie.captured? && @carpet.collides_with?(genielamp.genie)
        genielamp.genie.capture!
        if genielamp.genie.good?
          @score += 1
        else
          @score -= 1
        end
      end
      @genielamps.each do |genielamp|
        if genielamp.off_screen?(self)
          @genielamps.delete(genielamp)
        end
      end
    end

  end

  def scroll_background
    bg = @backgrounds.last
    if bg.y >= ((NUM_TILES / TILE_COLS) - 1) * bg.height - VELOCITY
      @yplus = -bg.height
    else
      @yplus += VELOCITY - 1
    end
  end

  def scroll_lamps
    @genielamps.each do |genielamp|
      genielamp.scroll(VELOCITY)
    end
  end
end
<commit_msg>Endboss without array<commit_after>class Window < Gosu::Window
  NUM_TILES = 6
  TILE_COLS = 2
  VELOCITY = 3
  BLACK = Gosu::Color.argb(0xff000000)

  module YAccessible
    attr_writer :y
    def y
      @y.to_i
    end
  end

  def initialize
    super(1200, 800, false)
    @carpet = Carpet.new(self)
    @backgrounds = NUM_TILES.times.collect do
      Gosu::Image.new(self, 'media/background.jpg', true).extend(YAccessible)
    end
    @font = Gosu::Font.new(self, Gosu::default_font_name, 60)
    @yplus = -@backgrounds.last.height
    @counter = 0
    @genielamps = []
    @endboss = nil
    @score = 1
  end

  def draw
    @carpet.draw
    @font.draw("Score: #{@score}", 10, 10, 5, 1, 1, color = BLACK)
    @backgrounds.each_with_index do | bg, index |
      bg.y = (index / TILE_COLS) * bg.height + @yplus
      bg.draw((index % TILE_COLS) * bg.width, bg.y, 1)
    end
    @genielamps.each {|genielamp| genielamp.draw}
    @endboss.draw if !@endboss.nil?
  end

  def update
    @counter += 1
    if button_down? Gosu::KbLeft
      @carpet.move_left
    end
    if button_down? Gosu::KbRight
      @carpet.move_right
    end
    scroll_background
    unless @score == 0
      if @counter % 120 == 1
        @genielamps.push LampWithGenie.new(self)
      end
    else
      @endboss = Endboss.new(self) if @endboss.nil? && @genielamps.empty?
    end
    scroll_lamps
    @genielamps.any? do |genielamp|
      if !genielamp.lamp.rubbed? && @carpet.collides_with?(genielamp.lamp)
        genielamp.lamp.rub!
      end
      if genielamp.lamp.rubbed? && !genielamp.genie.captured? && @carpet.collides_with?(genielamp.genie)
        genielamp.genie.capture!
        if genielamp.genie.good?
          @score += 1
        else
          @score -= 1
        end
      end
      @genielamps.each do |genielamp|
        if genielamp.off_screen?(self)
          @genielamps.delete(genielamp)
        end
      end
    end
  end

  def scroll_background
    bg = @backgrounds.last
    if bg.y >= ((NUM_TILES / TILE_COLS) - 1) * bg.height - VELOCITY
      @yplus = -bg.height
    else
      @yplus += VELOCITY - 1
    end
  end

  def scroll_lamps
    @genielamps.each do |genielamp|
      genielamp.scroll(VELOCITY)
    end
  end
end

{'fraction_non_alphanumeric': 0.11655480984340044, 'fraction_numerical': 0.0174496644295302, 'mean_word_length': 2.321693907875186, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2513454', 'n_tokens_mistral': 1802, 'n_tokens_neox': 1700, 'n_words': 351}