Class: Cliptic::Main::Puzzle::Clue

Inherits:
Object
  • Object
show all
Defined in:
lib/cliptic/main.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#ansObject (readonly)

Returns the value of attribute ans.



299
300
301
# File 'lib/cliptic/main.rb', line 299

def ans
  @ans
end

#cellsObject

Returns the value of attribute cells.



301
302
303
# File 'lib/cliptic/main.rb', line 301

def cells
  @cells
end

#coordsObject (readonly)

Returns the value of attribute coords.



299
300
301
# File 'lib/cliptic/main.rb', line 299

def coords
  @coords
end

#dirObject (readonly)

Returns the value of attribute dir.



299
300
301
# File 'lib/cliptic/main.rb', line 299

def dir
  @dir
end

#doneObject

Returns the value of attribute done.



301
302
303
# File 'lib/cliptic/main.rb', line 301

def done
  @done
end

#hintObject (readonly)

Returns the value of attribute hint.



299
300
301
# File 'lib/cliptic/main.rb', line 299

def hint
  @hint
end

#indexObject

Returns the value of attribute index.



301
302
303
# File 'lib/cliptic/main.rb', line 301

def index
  @index
end

#lengthObject (readonly)

Returns the value of attribute length.



299
300
301
# File 'lib/cliptic/main.rb', line 299

def length
  @length
end

#nextObject

Returns the value of attribute next.



301
302
303
# File 'lib/cliptic/main.rb', line 301

def next
  @next
end

#prevObject

Returns the value of attribute prev.



301
302
303
# File 'lib/cliptic/main.rb', line 301

def prev
  @prev
end

#startObject (readonly)

Returns the value of attribute start.



299
300
301
# File 'lib/cliptic/main.rb', line 299

def start
  @start
end

Instance Method Details

#activateObject



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

#checkObject



324
325
326
327
328
# File 'lib/cliptic/main.rb', line 324

def check
  if full?
    correct? ? mark_correct : mark_incorrect
  end
end

#clearObject



332
333
334
# File 'lib/cliptic/main.rb', line 332

def clear
  cells.each{|c| c.write(" ")}
end

#deactivateObject



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

Returns:

  • (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

Returns:

  • (Boolean)


321
322
323
# File 'lib/cliptic/main.rb', line 321

def has_cell?(y:, x:)
  coords.include?(Pos.mk(y,x))
end

#metaObject



309
310
311
# File 'lib/cliptic/main.rb', line 309

def meta
  @meta || "#{index} #{dir==:a ? "across" : "down"}"
end

#revealObject



335
336
337
338
# File 'lib/cliptic/main.rb', line 335

def reveal
  ans.zip(cells){|char, cell| cell.write(char)}
  mark_correct
end