blob: 3bcdfd92849667929d8b75a35933538e769156af (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
use Terminal::Boxer;
class Player is export {
has Str $.name;
has $.throw is rw;
has $.score is rw = 0;
my %ascii-art = (
rock => %?RESOURCES<rock/2>.slurp,
paper => %?RESOURCES<paper/2>.slurp,
scissor => %?RESOURCES<scissor/2>.slurp,
);
method throw-art() {
return %ascii-art{$!throw} ~ "\n$!name ($!score)";
}
}
#| 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 @players;
for 1 .. $players {
push @players, Player.new(name => prompt("[Player $_] Name: ").trim);
}
my %score-against = (
rock => "scissor",
paper => "rock",
scissor => "paper"
);
my Int $round = 0;
loop {
say "[Round {++$round}]";
for @players -> $player {
$player.throw = <rock scissor paper>.pick[0];
}
for @players -> $player {
for @players -> $player-against {
$player.score += 1 if $player-against.throw eq %score-against{$player.throw};
}
}
say ss-box(:4col, :20cw, @players.map(*.throw-art));
}
}
multi sub MAIN(
Bool :$version #= print version
) is export { say "Antlia v" ~ $?DISTRIBUTION.meta<version>; }
|