This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Help on implementing the grid for minesweeper Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help on implementing the grid for minesweeper" Watch "Help on implementing the grid for minesweeper" New topic

Help on implementing the grid for minesweeper

Angela Li

Joined: Nov 04, 2011
Posts: 12
I'm writing minesweeper for class and we don't have to have a working GUI but we still need to have some type of grid that will show up on command prompt when the game is run. I am thinking about building a grid that will look something like this +-----+-----+
| X | X | for two cells. How should i design it so that i can connect the grid to my 2D arrays that represent what is inside the cell.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

So, you already have the content of the grid in a 2D array? You could write a method that prints the grid on the console. You'll probably want to have nested for-loops: one loop over the rows, which contains another loop over the columns.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38107
To enlarge on what Jesper said (you didn’t really say 2D array, did you, Jesper?), you can iterate along the line setting X characters, or maybe others like █ = (char)0x2588 and (char)0x2716 = ✖. I would have thought that is easiest done with a char[][]; you can set individual characters in such an array very quickly.
John McClellan
Ranch Hand

Joined: Aug 15, 2011
Posts: 35

Something like that. Just adapt it for your needs and for the greater context of your already existing code.
I agree. Here's the link:
subject: Help on implementing the grid for minesweeper
Similar Threads
dumb array definition error, help!!!
Any example of Grid (x and y axis)
Irregular Grid with Three-State Cells
Java Minesweeper Help
Grid Alignment and Null Exception