Class: Cliptic::Main::Puzzle::Clue
- Inherits:
-
Object
- Object
- Cliptic::Main::Puzzle::Clue
- Defined in:
- lib/cliptic/main.rb
Instance Attribute Summary collapse
-
#ans ⇒ Object
readonly
Returns the value of attribute ans.
-
#cells ⇒ Object
Returns the value of attribute cells.
-
#coords ⇒ Object
readonly
Returns the value of attribute coords.
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#done ⇒ Object
Returns the value of attribute done.
-
#hint ⇒ Object
readonly
Returns the value of attribute hint.
-
#index ⇒ Object
Returns the value of attribute index.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#next ⇒ Object
Returns the value of attribute next.
-
#prev ⇒ Object
Returns the value of attribute prev.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Instance Method Summary collapse
- #activate ⇒ Object
- #check ⇒ Object
- #clear ⇒ Object
- #deactivate ⇒ Object
- #full? ⇒ Boolean
- #has_cell?(y:, x:) ⇒ Boolean
-
#initialize(ans:, hint:, dir:, start:) ⇒ Clue
constructor
A new instance of Clue.
- #meta ⇒ Object
- #reveal ⇒ Object
Constructor Details
#initialize(ans:, hint:, dir:, start:) ⇒ Clue
Returns a new instance of Clue.
302 303 304 305 306 307 308 |
# File 'lib/cliptic/main.rb', line 302 def initialize(ans:, hint:, dir:, start:) @ans, @dir, @start = ans, dir, start @length = ans.length @hint = parse_hint(hint) @coords = map_coords(**start, l:length) @done = false end |
Instance Attribute Details
#ans ⇒ Object (readonly)
Returns the value of attribute ans.
299 300 301 |
# File 'lib/cliptic/main.rb', line 299 def ans @ans end |
#cells ⇒ Object
Returns the value of attribute cells.
301 302 303 |
# File 'lib/cliptic/main.rb', line 301 def cells @cells end |
#coords ⇒ Object (readonly)
Returns the value of attribute coords.
299 300 301 |
# File 'lib/cliptic/main.rb', line 299 def coords @coords end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
299 300 301 |
# File 'lib/cliptic/main.rb', line 299 def dir @dir end |
#done ⇒ Object
Returns the value of attribute done.
301 302 303 |
# File 'lib/cliptic/main.rb', line 301 def done @done end |
#hint ⇒ Object (readonly)
Returns the value of attribute hint.
299 300 301 |
# File 'lib/cliptic/main.rb', line 299 def hint @hint end |
#index ⇒ Object
Returns the value of attribute index.
301 302 303 |
# File 'lib/cliptic/main.rb', line 301 def index @index end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
299 300 301 |
# File 'lib/cliptic/main.rb', line 299 def length @length end |
#next ⇒ Object
Returns the value of attribute next.
301 302 303 |
# File 'lib/cliptic/main.rb', line 301 def next @next end |
#prev ⇒ Object
Returns the value of attribute prev.
301 302 303 |
# File 'lib/cliptic/main.rb', line 301 def prev @prev end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
299 300 301 |
# File 'lib/cliptic/main.rb', line 299 def start @start end |
Instance Method Details
#activate ⇒ Object
312 313 314 315 |
# File 'lib/cliptic/main.rb', line 312 def activate cells.first.set_number(active:true) cells.each{|c| c.underline} end |
#check ⇒ Object
324 325 326 327 328 |
# File 'lib/cliptic/main.rb', line 324 def check if full? correct? ? mark_correct : mark_incorrect end end |
#clear ⇒ Object
332 333 334 |
# File 'lib/cliptic/main.rb', line 332 def clear cells.each{|c| c.write(" ")} end |
#deactivate ⇒ Object
316 317 318 319 320 |
# File 'lib/cliptic/main.rb', line 316 def deactivate cells.first.set_number(active:false) cells.each{|c| c.write} check if $config[:auto_mark] end |
#full? ⇒ Boolean
329 330 331 |
# File 'lib/cliptic/main.rb', line 329 def full? get_buffer.reject{|b| b == " "}.count == length end |
#has_cell?(y:, x:) ⇒ Boolean
321 322 323 |
# File 'lib/cliptic/main.rb', line 321 def has_cell?(y:, x:) coords.include?(Pos.mk(y,x)) end |
#meta ⇒ Object
309 310 311 |
# File 'lib/cliptic/main.rb', line 309 def @meta || "#{index} #{dir==:a ? "across" : "down"}" end |
#reveal ⇒ Object
335 336 337 338 |
# File 'lib/cliptic/main.rb', line 335 def reveal ans.zip(cells){|char, cell| cell.write(char)} mark_correct end |