• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Map text file to a 2 dimensional array.

 
Jonathan Haybok
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All I want to do is store patterns that are imported from a text file. The text file would be simple asterisks that would signify an alive cell (cell with a filled background). Spaces would be just be cells that are not alive. I'm sure many of you know about the Game of Life (I've been told it's the most programmed game), and that's what I'm doing.

I have a grid that I create with 2d arrays. I fill cells in the grid by using another 2d array that just stores true/false values. So I just need to figure out how to map an input stream of character/spaces to indexes of an array.

Can anyone help me out with this? I'm having trouble figuring out how the input stream identifies characters, and how, for example, to extract the values of an asterisk that would correspond to array[0][0]. What equates to rows/columns in text files? I apologize ahead of time for my poor description of the problem. Hopefully someone understands it.

I know I will have to modify this block of code:
 
Joe Ess
Bartender
Posts: 9318
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A good place to start is the IO Chapter of the Java Tutorial. It explains what functionality is available in the API. I'm sure you'll find some features that make your job fairly simple.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic