I have always been a minesweeper junky... I played for 1/2 an hour before looking at your code <G>
I think you have already partially solved this problem with your mine placement magic, walk through the grid and use the logic you used for incrementing the number of mines next to a particular location to see what the surrounding values are...
some comments on the rest of your code if I may :)sub draw_grid { print "# Wacky Fun Minesweeper!!!!\n"; for my $x (0..9) { print $x, ' '; for my $y (1..9) { if ($x == 0){ print $y, ' '; } else { print $blankgrid[$x][$y], ' '; } } print "\n"; } }
now instead of using write call draw_grid();
you can initialise both grids in the one double loop- (for modularity I would place the grid initialisation and the mine placement code in subroutines as well)
for my $x (1..9) { for my $y (1..9) { $blankgrid[$x][$y] = "_"; $grid[$x][$y] = 0; } }
your mainloop has a variable $minehit that you never use and I would replace $empty with something like $untested_squares so your main while loop becomes while ($untested_squares) { which IMO is nicer to read :)
Further optimisation left to the monastry gurus... I am going to go play some more :-)--
my $chainsaw = 'Perl';
In reply to Re: Need help with a minesweeper game
by greenFox
in thread Need help with a minesweeper game
by PsionicMan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |