[Java] Sudoku Game, Help!

Discussion in 'Computer Programming, Emulation, and Game Modding' started by Magnus87, Dec 19, 2014.

  1. Magnus87

    Magnus87 GBAtemp Regular

    Apr 28, 2013
    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
    (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
  2. LividPixel

    LividPixel Member

    Jul 19, 2014
    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.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice