[Java] Sudoku Game, Help!

Magnus87

Well-Known Member
OP
Member
Joined
Apr 28, 2013
Messages
397
Trophies
1
XP
1,510
Country
Argentina
Im trying to do a Sudoku with Java and Its freak me out D:


The idea is making a game very simple without complex and rare methods
U4RnXPh.png
(Just its looks now)​
Its looks nice but source code is in an "structured" way and I'm trying to do with objects


Now I have 5 classes


  • Block=> Takes a .txt file and save it in an array with 81 positions
  • Board => Takes all blocks and make a new one with 0 (Hidden value)
  • Window=> Draw Frames and buttons (Now also have the buttons behaviors and I need to remove it)
  • LogicWindow => Here need to write all buttons methods also
  • Game=> Initialize a Window
I'm not very with Java so try to do easy for me

I need to understand it and then adapt it to my code
 
Joined
Jul 19, 2014
Messages
11
Trophies
0
XP
93
Country
United States
A good place to start is to have a method that allows for setting a position's value. Something like SetGridPosition(int x, int y, int value). (And the corresponding GetGridPosition method)

When a user clicks on a button, you could have an object be instanciated which will contain the grid position that they clicked, and then open a window to ask for what value they would like to input. Then, when they press 'okay', the SetGridPosition is called on that grid position with the user's input.

However, I would probably do something like setting whatever button the user clicks on into a textbox temporarily, until it becomes no longer active (the user clicked out of it) or presses enter or something.

As for the implementation of the SetGridPosition(), you could go the obvious hacky way of applying each button to each position by hand, but you could have a more elegant approach that would require less code. I don't know if you're creating the buttons by code or in an editor, but if you have the buttons created by code, you could hold a reference to each button upon it's creation in an array or multidimentional array. (Have a for loop through 0-8 for each y, and inside of that, one for each x. Multiply the x and y by the width and height of the button respectively to know where to position each button.)

If you have any more question, it seems the Programming section isn't very active on here, so I'd advise you to check out http://stackoverflow.com, it's extremely popular and you'll get an answer very quickly.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    Veho @ Veho: The cybertruck is a death trap.