summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-04-02 05:08:35 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-04-02 05:08:35 -0700
commitefe1abc826a7cd4e3284546af07e5129ca9ac07c (patch)
treefa34d898cb43e8ea638021861fcb7e3d662d364c
parent172229560dd8a7dba317a13d7b954409f7af3fcb (diff)
downloaddartboat-efe1abc826a7cd4e3284546af07e5129ca9ac07c.tar.gz
dartboat-efe1abc826a7cd4e3284546af07e5129ca9ac07c.tar.xz
make interactive output slightly less awful
-rwxr-xr-xdartbot.rb19
1 files 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! :)'