Created
March 11, 2019 21:24
-
-
Save CedricVanhaverbeke/e8fa706dc8f2fd00f1e5e3cc7355c723 to your computer and use it in GitHub Desktop.
This file contains 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
use Data::Dumper; | |
use Term::ANSIColor; | |
$clear_string = `clear`; | |
sub print_speelveld{ | |
my $aantalBommen = shift; | |
print " " x 10; | |
for my $i (0..8){ | |
printf("%-10s", $i - 4); | |
} | |
print "\n"; | |
print " " x 10; | |
for my $i (0..8){ | |
printf("%-10s", "____"); | |
} | |
print "\n\n"; | |
for my $i (0..8){ | |
printf("%2s|%-7s", $i-4, " "); | |
for my $j (0..8){ | |
printf("%-10s",$matrix->[$i][$j]{waarde}) if $matrix->[$i][$j]{omgedraaid} == 1; | |
printf("%-10s","X") if $matrix->[$i][$j]{omgedraaid} == 0; | |
} | |
print "\n\n"; | |
} | |
printf("Aantal bommen gevonden: %d", $aantalBommen); | |
print "\n\nVul coördinaten in met een spatie tussen: "; | |
} | |
for my $i (0..8){ | |
for my $j (0..8){ | |
$matrix->[$i][$j] = {waarde => "NOPE", omgedraaid => 0}; | |
} | |
} | |
print $clear_string; | |
for my $i (0..15){ | |
my $x = int(rand(9)); | |
my $y = int(rand(9)); | |
$matrix->[$x][$y]->{waarde} = "BOOM" | |
} | |
print_speelveld(0); | |
my $teller = 0; | |
my $aantalBommen = 0; | |
while($teller <= 15){ | |
my $input = <>; | |
my @array = split(" ", $input); | |
(my $newX, my $newY) = @array; | |
$matrix->[$newY + 4][$newX + 4]{omgedraaid} = 1; | |
$aantalBommen += 1 if $matrix->[$newY + 4][$newX + 4]{waarde} eq "BOOM"; | |
print $clear_string; | |
print_speelveld($aantalBommen); | |
$teller+=1; | |
} | |
# Show everything | |
for my $i (0..9){ | |
for my $j (0..9){ | |
$matrix->[$i][$j]{omgedraaid} = 1; | |
} | |
} | |
print $clear_string; | |
print_speelveld($aantalBommen); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment