Hi guys, I have a question. Using Java (of course) how would I make a Sudoku game? :o
I think people who know what Sudoku is will have a better time answering this.
All I know is that you need to use multi-dimensional arraysâŚ
Any suggestions?
Sukodo. My old enemy!
Well, you can use multi-dimension arrays.
However, youâd need to have an object to make up the different types of groupings. The Squares, the Lines, and the Diagonal (If youâre using this). From there, itâs pretty easy to work out how you do it.
Also! Are you askinâ for help with a class assignment? 'Cause I know a lot of teachers who give this one to their students to help them learn about game state stuff and the like.
No, not for a school assignment or anything of that sort. I just felt like making a puzzle game, and Sudoku is one of my fav puzzles.
So I decided on Sudoku.
And no, Iâm not doing diaganols.
Just vertical and horizontal.
Could you be a little more specific with the âdifferent type of groupingsâ thing?
Thanks! ;D
Sudoku could easily be made using just a 2D array.
What do you mean? ???
Sorry, Iâm not exactly the best Java programmerâŚ
Simply make a 2D array called Board or something like so:
int[][] level = {
{0,0,0,0,0,0,0,0,0,0,},
{0,1,1,1,1,1,1,1,1,1,},
{0,1,0,0,0,0,1,0,0,0,},
{0,1,0,0,0,0,1,0,0,0,},
{0,1,0,0,0,0,1,0,0,0,},
{0,1,1,1,1,1,1,1,1,1,},
{0,1,0,0,0,0,1,0,0,1,},
{0,1,0,0,0,0,1,0,0,1,},
{0,1,0,0,0,0,1,0,0,1,},
{0,1,0,0,0,0,1,0,0,1,},
};
Then you can either devise a way to generate levels, or put in preset levels.
I would make it so that a â99â or some number bigger than 0-9 represents a black space, then simply add a new Black object to an ArrayList and cycle through it, checking if it got clicked on or changed or whatever.
-Nathan
Thanks! Iâll try it out
No problem! This might help too: how to check through the array for the blank spots -
for (int x = 0; x < ROWS; x++)
{
for (int y = 0; y < COLUMNS; y++)
{
mapData = level[y][x];
if (mapData == 99)
{
EmptyTile e = new EmptyTile(e);
e.setX(x);
e.setY(y);
emptyTileList.add(e);
}
}
}
Thanks again! ;D
Or, simply just have a 2D int array that holds the visible numbers (0-9) and the not visible ones (-1 to -10, where you negate and subtract to get the right answer).
This way, a block, horizontal, or vertical check is extremely simple.
Also, when rendering the table, if the value is < 0, leave that cell blank
Thatâs dangerous. Youâd have to have two different arrays to hold the data then and match them up.
Because otherwise you can just put in values until it updates correctly to complete it!