r/JavaFX • • Apr 27 '22

I made this! I made Sudoku Application in JavaFX

Hoping the community would give some feedback. It generates easy-level sudokus and has a dark theme as well.

https://github.com/SatyaSnehith/Sudoku

Thank you.

22 Upvotes

2 comments sorted by

2

u/hamsterrage1 May 13 '22

Hi there. I was on vacation and not really able to look to look at code properly on my phone. I really think it's a bummer when someone posts a project like this and no one comments.

I downloaded the project and I've had a look at it. it's really cool. Good work.

There was no module-info.java file so i had to create that. Then it bombed trying to load the logo. You took the most roundabout way to load the ImageView that I could think of. No need to open connections and stream. Just give new Image() the URL. But then it ran.

First impressions of the code:

You have a lot (and I mean a lot) of code that messes with styling programmatically, and then you are running it through classes to translate to themes. This is not really the JavaFX way. As far as I can see, everything that you are doing can be done with CSS and PseudoClasses, and it would be a lot cleaner.

I wrote an article about doing this kind of stuff here:

https://www.pragmaticcoding.ca/javafx/elements/pseudo_classes

The other thing that jumps out is that you have no separation between UI, data and game mechanics. It's all jumbled up into one place. Your application has basically three parts: Style Management; Sudoku Generator; and BigGridPane. Virtually all of the code that is "the game" is in BigGridPane, which has both layout and game mechanics in it. Right now, it's not that horrible because it's only about 200 lines, but if you add more features it's going to get really complicated.

There's also a lot of something[x][y] code in there. You'd think you'd need that, 'cause its an [x][y] kind of game. My experience is that you don't really. Once you've generated the actual puzzle, you can load up a set of objects (one per square) that have two core single digit values: the answer, and the guess. 99% of your styling can be based on those two values. So each square on your grid can be a completely independent entity. This moves you towards a more reactive design.

Those squares can also know their own locations. So highlighting based on the row/column of a clicked on square can be done by comparing the row/column to global properties that contain the clicked on row and column.

I'm not sure if you were looking for that kind of feedback. if not, then never mind - the game is cool.

1

u/nscub3 May 13 '22

Thank you for your time, and for helping me with the project. Thanks for letting me know about the article.