about summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-05-02 14:51:11 +0530
committerAndinus <andinus@nand.sh>2021-05-02 14:54:11 +0530
commit77c11d9115e6a3384a6570e39aa27073df03f5b8 (patch)
tree34b15954949bb724198fddec5fd9f9e81531a8fb /lib
parent1f04837b94524732b5ff12ef848d943dc70b51b4 (diff)
downloadantlia-77c11d9115e6a3384a6570e39aa27073df03f5b8.tar.gz
Print columns based on number of players, move SIGINT tap
SIGINT tap was moved right before the loop. If user sends SIGINT
before the loop starts then the behaviour shouldn't change.
Diffstat (limited to 'lib')
-rw-r--r--lib/Antlia/CLI.rakumod12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/Antlia/CLI.rakumod b/lib/Antlia/CLI.rakumod
index 4ea62d3..14dc8ca 100644
--- a/lib/Antlia/CLI.rakumod
+++ b/lib/Antlia/CLI.rakumod
@@ -17,9 +17,6 @@ class Player is export {
     }
 }
 
-my Bool $end-loop = False;
-signal(SIGINT).tap({$end-loop = True;});
-
 #| text based Rock paper scissors game
 multi sub MAIN(
     Bool :$autoname, #= Autoname the players
@@ -44,6 +41,12 @@ multi sub MAIN(
     );
 
     my Int $round = 0;
+    my Int $columns = @players.elems < 4 ?? (@players.elems < 3 ?? 2 !! 3)
+                       !! (@players.elems %% 4 ?? 4
+                           !! (@players.elems %% 3 ?? 3 !! 4));
+
+    my Bool $end-loop = False;
+    signal(SIGINT).tap({$end-loop = True;});
     loop {
         for @players -> $player {
             $player.throw = <rock scissor paper>.pick[0];
@@ -57,8 +60,7 @@ multi sub MAIN(
         }
 
         say "[Round {++$round}]";
-        say ss-box(:4col, :20cw, @players.map(*.throw-art));
-
+        say ss-box(col => $columns, :20cw, @players.map(*.throw-art));
         last if $end-loop;
     }