class Text2048::HighScore

High score manager

Constants

DB_FILE

Public Class Methods

new() click to toggle source
# File lib/text2048/high_score.rb, line 9
def initialize
  @score = 0
  load
end

Public Instance Methods

load() click to toggle source
# File lib/text2048/high_score.rb, line 14
def load
  @score = IO.read(DB_FILE).to_i if FileTest.exists?(DB_FILE)
  @score
end
maybe_update(score) click to toggle source
# File lib/text2048/high_score.rb, line 19
def maybe_update(score)
  load
  save(score) if score > @score
end
to_i() click to toggle source
# File lib/text2048/high_score.rb, line 24
def to_i
  @score
end

Private Instance Methods

save(score) click to toggle source
# File lib/text2048/high_score.rb, line 30
def save(score)
  File.open(DB_FILE, 'w') { |file| file.print score }
  @score = score
end