Class: Cliptic::Main::Player::Game

Inherits:
Object
  • Object
show all
Includes:
Database, Menus, Windows
Defined in:
lib/cliptic/main.rb

Constant Summary

Constants included from Database

Database::Dir_Path, Database::File_Path

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date: Date.today) ⇒ Game

Returns a new instance of Game.



609
610
611
612
613
614
615
616
617
618
# File 'lib/cliptic/main.rb', line 609

def initialize(date:Date.today)
  @date  = date
  init_windows
  @timer = Timer.new(time:state.time, bar:top_b, 
                     callback:->{board.update})
  @ctrls = Controller.new(game:self)
  @unsaved  = false
  @continue = true
  draw
end

Instance Attribute Details

#boardObject (readonly)

Returns the value of attribute board.



606
607
608
# File 'lib/cliptic/main.rb', line 606

def board
  @board
end

#bot_bObject (readonly)

Returns the value of attribute bot_b.



606
607
608
# File 'lib/cliptic/main.rb', line 606

def bot_b
  @bot_b
end

#continueObject

Returns the value of attribute continue.



608
609
610
# File 'lib/cliptic/main.rb', line 608

def continue
  @continue
end

#ctrlsObject (readonly)

Returns the value of attribute ctrls.



606
607
608
# File 'lib/cliptic/main.rb', line 606

def ctrls
  @ctrls
end

#dateObject (readonly)

Returns the value of attribute date.



606
607
608
# File 'lib/cliptic/main.rb', line 606

def date
  @date
end

#modeObject

Returns the value of attribute mode.



608
609
610
# File 'lib/cliptic/main.rb', line 608

def mode
  @mode
end

#stateObject (readonly)

Returns the value of attribute state.



606
607
608
# File 'lib/cliptic/main.rb', line 606

def state
  @state
end

#timerObject (readonly)

Returns the value of attribute timer.



606
607
608
# File 'lib/cliptic/main.rb', line 606

def timer
  @timer
end

#top_bObject (readonly)

Returns the value of attribute top_b.



606
607
608
# File 'lib/cliptic/main.rb', line 606

def top_b
  @top_b
end

#unsavedObject

Returns the value of attribute unsaved.



608
609
610
# File 'lib/cliptic/main.rb', line 608

def unsaved
  @unsaved
end

Instance Method Details

#exitObject



675
676
677
678
# File 'lib/cliptic/main.rb', line 675

def exit
  @continue = false
  Screen.clear
end

#game_overObject



670
671
672
673
674
# File 'lib/cliptic/main.rb', line 670

def game_over
  save if $config[:auto_save]
  timer.stop
  completed if board.puzzle.complete?
end

#pauseObject



644
645
646
647
# File 'lib/cliptic/main.rb', line 644

def pause
  timer.stop
  Menus::Pause.new(game:self).choose_opt
end

#playObject



619
620
621
622
623
624
625
626
# File 'lib/cliptic/main.rb', line 619

def play
  if state.done
    show_completed_menu
  else
    add_to_recents
    game_and_timer_threads.map(&:join)
  end
end

#redrawObject



627
628
629
630
631
632
# File 'lib/cliptic/main.rb', line 627

def redraw
  save
  Screen.clear
  init_windows
  draw
end

#resetObject



661
662
663
664
665
# File 'lib/cliptic/main.rb', line 661

def reset
  state.delete if state.exists?
  board.clear_all_cells
  timer.reset
end

#reset_menuObject



657
658
659
660
# File 'lib/cliptic/main.rb', line 657

def reset_menu
  timer.stop
  Reset_Progress.new(game:self)
end

#revealObject



666
667
668
669
# File 'lib/cliptic/main.rb', line 666

def reveal
  state.reveals+= 1
  board.reveal_clue
end

#saveObject



652
653
654
655
656
# File 'lib/cliptic/main.rb', line 652

def save
  state.save(game:self)
  bot_b.time_str(t:5, x:10, str:"Saved!")
  self.unsaved = false
end

#unpauseObject



648
649
650
651
# File 'lib/cliptic/main.rb', line 648

def unpause
  timer.start
  board.redraw
end

#user_inputObject



641
642
643
# File 'lib/cliptic/main.rb', line 641

def user_input
  board.grid.getch
end