Created
February 23, 2020 09:08
-
-
Save kijuky/36b5bfd7338539f98cbc800df3188626 to your computer and use it in GitHub Desktop.
ババ抜き
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# ババ抜き | |
# | |
# | |
# カードが引かれたかどうかを表す配列。 | |
# 1 なら引かれていない。0 なら引かれている。 | |
my @card = (1, 1, 1, 1, 1, 1); | |
# | |
# ババを決定。 | |
srand(); | |
my $baba = int(rand(6)); | |
# print("ババは $baba\n"); | |
# | |
# メインルーチン。 | |
my $while_loop = 0; | |
my $draw = -1; | |
while($while_loop < 6) { | |
print("残っているカード :"); | |
for ($i = 0; $i < 6; $i++) { | |
if (@card[$i] == 1) { | |
print("$i "); | |
} | |
} | |
print("\n"); | |
print("カードを一枚引いてください : "); | |
$draw = <STDIN>; | |
print("\n"); | |
if (@card[$draw] == 0) { | |
print("そのカードは既に引いています\n"); | |
print("別のカードを指定してください\n"); | |
} elsif ($draw == $baba) { | |
print("残念。そのカードはババでした\n"); | |
last; | |
} else { | |
print("…。ババではありませんでした\n"); | |
@card[$draw] = 0; | |
$while_loop++; | |
} | |
print("\n"); | |
} | |
if ($while_loop == 6) { | |
print("おめでとうございます。あなたの勝ちです"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment