A Minesweeper Problem (4)

1 Name: #!/usr/bin/anonymous : 2008-09-30 16:13 ID:29H5iYeO

Hallo.

I'm currently taking some Java classes at college. I'm very new at this, and while I can make very basic accounting programs (input data and output a price and stuff like that), one of the codes we were assigned to do is really starting to get on my nerves.

It's sort of a Minesweeper thingy, in the sense that the user must input the size of the 2D array first, then start typing either an asterisk ("*") or a dot (".") to determine where it's safe and where it's not. Dots are safe and asterisks are mines. After that, give the option to input another field.

Ok, so far, so good. The thing is that after receiving the dots and asterisks from the user, the program must output automatically the field, replacing the dots with a number that means how many adjacent mines are there. So, if one inputs:

4 4

*...
....
.*..
....

The output should be:

Field # 1:

*100
2210
1*10
1110

I'm having serious trouble on making the program read the values and transform them into numbers. Can Anonymous provide me with much needed help?

Thanks.

2 Name: #!/usr/bin/anonymous : 2008-09-30 23:09 ID:gfu34zAd

Make a 2 dimensional array that holds strings.
User inputs dimensions so create the 2 dimensional array with those dimensions.
Loop through the input placing the value of "*" in every mine position or a 0.
Loop through again. when you encounter an "*" you set the cells around it += 1 (minding the borders).

That is not the most efficient way of doing it but it is a way to get the correct output and demonstrate the idea.

3 Name: #!/usr/bin/anonymous : 2008-10-19 11:49 ID:Heaven

I had a good solution using a Cell model class but the faggy forum rejected my captcha and refused to let me go back to the previous page to retry it.

4 Name: #!/usr/bin/anonymous : 2008-10-21 01:01 ID:Heaven

>>3
write it in a real text editor, then copy and paste.
seriously who types directly into crappy web browser textboxes?

This thread has been closed. You cannot post in this thread any longer.