about summary refs log tree commit diff stats
path: root/lib/Antlia/CLI.rakumod
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-04-29 20:46:30 +0530
committerAndinus <andinus@nand.sh>2021-04-29 20:46:30 +0530
commit3cf07e5d8f5579893a43a4300d44d4dbab90ba81 (patch)
tree736fefaf3d286f6fe37e332aacf4ec09e27d3899 /lib/Antlia/CLI.rakumod
parent7a5a05f5af12731bc714234726ab4049e68461f3 (diff)
downloadantlia-3cf07e5d8f5579893a43a4300d44d4dbab90ba81.tar.gz
Initial implementation
Diffstat (limited to 'lib/Antlia/CLI.rakumod')
-rw-r--r--lib/Antlia/CLI.rakumod52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/Antlia/CLI.rakumod b/lib/Antlia/CLI.rakumod
new file mode 100644
index 0000000..581bfe8
--- /dev/null
+++ b/lib/Antlia/CLI.rakumod
@@ -0,0 +1,52 @@
+use Terminal::Boxer;
+
+class Player is export {
+    has Str $.name;
+    has $.throw is rw;
+    has $.score is rw = 0;
+}
+
+#| text based Rock paper scissors game
+multi sub MAIN(
+    Int :$players where * == 2 = 2, #= Number of players (default: 2)
+) is export {
+    say "Antlia - text based Rock paper scissors game";
+    say "--------------------------------------------\n";
+
+    my Player $player1 = Player.new(name => prompt("[Player 1] Name: ").trim);
+    my Player $player2 = Player.new(name => prompt("[Player 2] Name: ").trim);
+
+    my %ascii-art = (
+        rock => %?RESOURCES<rock/2>.slurp,
+        paper => %?RESOURCES<paper/2>.slurp,
+        scissor => %?RESOURCES<scissor/2>.slurp,
+    );
+
+    my %score-against = (
+        rock => "scissor",
+        paper => "rock",
+        scissor => "paper"
+    );
+
+    loop {
+        print "\n";
+        say "- " x 40;
+
+        $player1.throw = %ascii-art.pick[0].key;
+        $player2.throw = %ascii-art.pick[0].key;
+
+        $player1.score += 1 if $player2.throw eq %score-against{$player1.throw};
+        $player2.score += 1 if $player1.throw eq %score-against{$player2.throw};
+
+        say ss-box(:40cw, %ascii-art{$player1.throw},
+                   %ascii-art{$player2.throw});
+        say ss-box(:40cw, "{$player1.name} ({$player1.score})",
+                   "{$player2.name} ({$player2.score})");
+
+        sink prompt "";
+    }
+}
+
+multi sub MAIN(
+    Bool :$version #= print version
+) is export { say "Antlia v" ~ $?DISTRIBUTION.meta<version>; }