Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Game Of Life, some questions

 
Henrik Persson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I'm new to Java, and this is my first "real" project that I'm actually satisfied with, so I thought I'd share it with you. Took a few days to write.
It's a version of the famous Game Of Life by John Conway, where the cells are represented by checkboxes (only because making some other graphic version would be too advanced for me).
It looks alright, you can choose three different sizes and four different speeds. The layout might not be correct for all systems (it's optimized for OSX), but just a simple resize of the window so the checkboxes form a square pattern will do the trick.

Some questions:

-The checkCell()-method seems extremely clunky and awkward, and I guess there must be a better way to do it, any tips? Algorithms?
-The reason I put an infinite loop in the startGame()-method is because I kept getting exceptions when trying to stop and start the game, something about how threads work. Is there a better way to do this (without making a complete rewrite of the entire program)?
-Is there any way to make the gui platform independent?

Have fun! Code below:

GameOfLifeCell-class:



GameOfLife-class:


 
Paul Clapham
Sheriff
Pie
Posts: 20769
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you made things a lot harder for yourself by implementing the array of cells as a one-dimensional array.
 
Unnar Björnsson
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made this with javascript once, small project that was fun to do. You can take a look at it here it allows you to initialize the board and then press start, stop or reset. Just select view source in the browser to see the code. Since it is javascript that is similar to java syntax wise and since these kind of problem solving are language independent you might get some ideas from it.
Note: This is probably not the best or fastest way to implement this, it was just some pet project of mine I did for fun there is probably something that could be written better, also the code is not commented.
 
Henrik Persson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I think you made things a lot harder for yourself by implementing the array of cells as a one-dimensional array.

I wrote this program while reading the Head First Java book, and it wasn't until I finished the program that I found out about multi-dimensional arrays in the appendix, and it crossed my mind that I could have used one of those instead, but I fail to see how that would improve my code. Can you be more specific? Keep in mind that I am a total newbie to programming!

Unnar Björnsson wrote:I made this with javascript once, small project that was fun to do. You can take a look at it here it allows you to initialize the board and then press start, stop or reset. Just select view source in the browser to see the code. Since it is javascript that is similar to java syntax wise and since these kind of problem solving are language independent you might get some ideas from it.
Note: This is probably not the best or fastest way to implement this, it was just some pet project of mine I did for fun there is probably something that could be written better, also the code is not commented.

Thanks a lot! Google Chrome freezes when I try to view your code however, I'll try it in a different browser.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic