mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-12 15:50:20 -08:00
add termination logic
This commit is contained in:
@@ -35,6 +35,10 @@ sub run {
|
|||||||
($pile_size, $min_select, $max_select, $win_option, $start_option)
|
($pile_size, $min_select, $max_select, $win_option, $start_option)
|
||||||
= &get_user_input();
|
= &get_user_input();
|
||||||
|
|
||||||
|
if ($pile_size < 0) {
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
|
||||||
play($pile_size, $min_select, $max_select, $win_option, $start_option);
|
play($pile_size, $min_select, $max_select, $win_option, $start_option);
|
||||||
|
|
||||||
printf "\n";
|
printf "\n";
|
||||||
@@ -93,6 +97,9 @@ sub get_user_input {
|
|||||||
while ($pile_size < 1) {
|
while ($pile_size < 1) {
|
||||||
printf "%s", "ENTER PILE SIZE: ";
|
printf "%s", "ENTER PILE SIZE: ";
|
||||||
$pile_size = <STDIN>;
|
$pile_size = <STDIN>;
|
||||||
|
if ($pile_size < 0) {
|
||||||
|
return ($pile_size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while ($min_select < 1 || $max_select < 1 || $min_select > $max_select) {
|
while ($min_select < 1 || $max_select < 1 || $min_select > $max_select) {
|
||||||
@@ -264,5 +271,6 @@ sub get_computer_remove_amount {
|
|||||||
return (int(rand($max_select - $min_select)) + $min_select);
|
return (int(rand($max_select - $min_select)) + $min_select);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# start the game
|
# start the game
|
||||||
run();
|
run();
|
||||||
|
|||||||
Reference in New Issue
Block a user