How to use Pascal to write a minesweeper game?
Write a program to input an H x W array of 0’s and 1’s where H and W are also user inputs.
You may assume that both H and W are non-zero and at most 10. The array represents an H
x W minefield so that a cell with a 1 (resp. 0) means the cell contains (does not contain) a
bomb. Your program should print the minefield as follows:
(1) If a cell contains a bomb, print a ‘#’.
(2) If a cell does not contain a bomb and is not adjacent to any bomb, print a ‘.’
(3) Otherwise, print the number of neighboring bombs.
Sample input and output (user input in boldface):
5 5
1 0 0 1 0
1 1 0 0 0
0 0 0 0 0
0 0 0 0 1
0 0 0 0 0
#32#1
##211
22111
...1#
...11
Last edited by wtxwt; 10-27-2007 at 10:15 AM.
|