From 77c11d9115e6a3384a6570e39aa27073df03f5b8 Mon Sep 17 00:00:00 2001 From: Andinus Date: Sun, 2 May 2021 14:51:11 +0530 Subject: 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. --- lib/Antlia/CLI.rakumod | 12 +++++++----- 1 file 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 = .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; } -- cgit 1.4.1-2-gfad0