Class: Status
- Inherits:
-
Object
- Object
- Status
- Defined in:
- lib/status.rb
Overview
This class handles the game status and things like the next figure, the score and so one
Copyright © 2011 Nikolay Nemshilov
Constant Summary collapse
- HEAD_FONT =
['Courier', Block::SIZE + 5, Color::GRAY].freeze
- TEXT_FONT =
['Courier New', Block::SIZE, Color::GRAY].freeze
- TEXT_WIDTH =
chars
22- SCORING_SYSTEM =
{ 1 => 100, 2 => 300, 3 => 500, 4 => 800, 5 => 1200 }
- LEVELUP =
the number of lines to level up
10
Instance Attribute Summary collapse
-
#figure ⇒ Object
Returns the value of attribute figure.
-
#figures ⇒ Object
Returns the value of attribute figures.
-
#level ⇒ Object
Returns the value of attribute level.
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#pos_x ⇒ Object
Returns the value of attribute pos_x.
-
#pos_y ⇒ Object
Returns the value of attribute pos_y.
-
#score ⇒ Object
Returns the value of attribute score.
Instance Method Summary collapse
- #count_drop(figure) ⇒ Object
- #count_kill(lines) ⇒ Object
- #draw ⇒ Object
-
#initialize(window, x, y) ⇒ Status
constructor
A new instance of Status.
- #reset! ⇒ Object
Constructor Details
#initialize(window, x, y) ⇒ Status
24 25 26 27 28 29 30 31 32 |
# File 'lib/status.rb', line 24 def initialize(window, x, y) @pos_x = x @pos_y = y @head_font = Font.new(window, HEAD_FONT[0], HEAD_FONT[1]) @text_font = Font.new(window, TEXT_FONT[0], TEXT_FONT[1]) reset! end |
Instance Attribute Details
#figure ⇒ Object
Returns the value of attribute figure.
8 9 10 |
# File 'lib/status.rb', line 8 def figure @figure end |
#figures ⇒ Object
Returns the value of attribute figures.
8 9 10 |
# File 'lib/status.rb', line 8 def figures @figures end |
#level ⇒ Object
Returns the value of attribute level.
8 9 10 |
# File 'lib/status.rb', line 8 def level @level end |
#lines ⇒ Object
Returns the value of attribute lines.
8 9 10 |
# File 'lib/status.rb', line 8 def lines @lines end |
#pos_x ⇒ Object
Returns the value of attribute pos_x.
8 9 10 |
# File 'lib/status.rb', line 8 def pos_x @pos_x end |
#pos_y ⇒ Object
Returns the value of attribute pos_y.
8 9 10 |
# File 'lib/status.rb', line 8 def pos_y @pos_y end |
#score ⇒ Object
Returns the value of attribute score.
8 9 10 |
# File 'lib/status.rb', line 8 def score @score end |
Instance Method Details
#count_drop(figure) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/status.rb', line 64 def count_drop(figure) if figure.distance > 0 @score += figure.distance * @level @figures += 1 end end |
#count_kill(lines) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/status.rb', line 71 def count_kill(lines) if lines.size > 0 @score += SCORING_SYSTEM[lines.size] * @level @lines += lines.size if @lines >= @levelup @level += 1 @levelup = @lines + LEVELUP - @lines % LEVELUP end end end |
#draw ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/status.rb', line 34 def draw draw_head "Next:", 0 @figure.pos_x = @pos_x @figure.pos_y = @pos_y + 2 @figure.draw draw_head "Score:", 9 draw_text "Level", @level, 10 draw_text "Score", @score, 11 draw_text "Lines", @lines, 12 draw_text "Figures", @figures, 13 draw_head "Winnars:", 18 @records.each_with_index do |entry, i| draw_text entry[0], entry[1], 19 + i end end |
#reset! ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/status.rb', line 52 def reset! @level = 1 @lines = 0 @score = 0 @figures = 0 # the next levelup lines num @levelup = LEVELUP @records = Records.top(6) end |