Skip to content

Commit

Permalink
improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
wesley974 committed Mar 14, 2017
1 parent b9f4532 commit 9968b5a
Showing 1 changed file with 3 additions and 25 deletions.
28 changes: 3 additions & 25 deletions lib/user_interface.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'core'
require 'scoreboard'
require 'press_any_key'
require 'terminal-table'
require 'colored'
require 'format'
require 'sys_jobs'

# The user interface
class UserInterface
class UserInterface < SysJobs
def initialize
ctrlc_trap
@name = 'Guest'
Expand Down Expand Up @@ -51,11 +51,6 @@ def ask_for_number
number
end

def bybye
puts "Goodbye #{@name}.\n\n"
exit
end

def play
countdown(5)
@player = Core.new
Expand All @@ -68,7 +63,7 @@ def new_score
puts ' New Score !!'.red.bold \
if @board.add(@name, @player.tries, @rt)
view_score
press_a_key
press_any_key
play
end

Expand All @@ -91,25 +86,8 @@ def countdown(seconds)
puts 'Beat the best time!'.center(Format::SPACES)
end

def ctrlc_trap
trap('INT') do
ctrlc_action
end
end

def ctrlc_action
print "\r^C received. "
bybye
end

def info
@rt = @player.time
puts "#{@player.tries} attempts in " + @rt.to_s.red + "seconds!\n"
end

def press_a_key
puts 'Press any key to continue...'
returns = STDIN.getch
ctrlc_action if returns == "\u0003"
end
end

0 comments on commit 9968b5a

Please sign in to comment.