Class: Text2048::HighScore

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

Overview

High score manager

Constant Summary collapse

DB_FILE =
File.expand_path('~/.text2048')

Instance Method Summary collapse

Constructor Details

#initializeHighScore

Returns a new instance of HighScore.



9
10
11
12
# File 'lib/text2048/high_score.rb', line 9

def initialize
  @score = 0
  load
end

Instance Method Details

#loadObject



14
15
16
17
# 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) ⇒ Object



19
20
21
22
# File 'lib/text2048/high_score.rb', line 19

def maybe_update(score)
  load
  save(score) if score > @score
end

#to_iObject



24
25
26
# File 'lib/text2048/high_score.rb', line 24

def to_i
  @score
end