From efe1abc826a7cd4e3284546af07e5129ca9ac07c Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sat, 2 Apr 2022 05:08:35 -0700 Subject: make interactive output slightly less awful --- dartbot.rb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/dartbot.rb b/dartbot.rb index 62a1e0e..5837db8 100755 --- a/dartbot.rb +++ b/dartbot.rb @@ -256,6 +256,19 @@ def output_visit(n, rem, points = nil, darts = nil, bust = false) puts str end +def output_int_visit(n, p_rem, rem, p_points = nil, points = nil, darts = nil, bust = false) + str = '(%2s) ' % n + str << (p_points ? colour_points(p_points) : ' ') + str << ' %3s' % p_rem + str << ' %3s' % rem + str << ' %s' % colour_points(points) if points + str << " \e[38;5;235m%s\e[0m" % visit_darts(darts) if darts + str << " \e[38;5;88mBUST\e[0m" if bust + str << " \e[38;5;76mWIN\e[0m" if rem.zero? + + puts str +end + def play_match(start_points = 501, output = true) rem = start_points m_darts = [] @@ -284,13 +297,13 @@ def play_int_match(start_points = 501, output = true) rem = start_points m_darts = [] - output_visit(m_darts.length, rem) if output + output_int_visit(m_darts.length, p_rem, rem) if output loop do rem, points, darts, bust = play_visit(rem) m_darts << darts - output_visit(m_darts.length, rem, points, darts, bust) if output + output_int_visit(m_darts.length, p_rem, rem, nil, points, darts, bust) if output if rem == 0 puts puts 'Dartbot wins. :(' @@ -300,7 +313,7 @@ def play_int_match(start_points = 501, output = true) print "Enter points: " p_points = gets.to_i p_rem -= p_points - puts "Remaining: #{p_rem}" + output_int_visit(m_darts.length, p_rem, rem, p_points, points, darts, bust) if output puts if p_rem == 0 puts 'You win! :)' -- cgit v1.2.3-70-g09d2