• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Help on implementing the grid for minesweeper

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
+-----+-----+
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 68961
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Something like that. Just adapt it for your needs and for the greater context of your already existing code.
 
I wasn't selected to go to mars. This tiny ad got in ahead of me:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic