How am I going to make this...?

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. :stuck_out_tongue:
All I know is that you need to use multi-dimensional arrays…
Any suggestions?
:slight_smile:

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. :smiley:

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 :wink:

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 :slight_smile:

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!