diff options
-rwxr-xr-x | dartbot.rb | 19 |
1 files changed, 16 insertions, 3 deletions
@@ -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! :)' |