if (row == 1) {
row = 0;
}
How about: row = row - 1
If you can read Javascript, here's one way to do it:
http://normsstuff.zxq.net/Games/TicTacToe.html#top
Type: Posts; User: Norm
if (row == 1) {
row = 0;
}
How about: row = row - 1
If you can read Javascript, here's one way to do it:
http://normsstuff.zxq.net/Games/TicTacToe.html#top
Define a 2 dim array: theField and fill it with ImageView objects.
It replaces the 9 variables like this: row1_field1_img
You may have to change the indexes to be 0 based: 0-2 vs 1-3
int[][] gameboard = new int[3][3]; // define 2 dim gameboard array
Look at something like this:
if(gameboard[row][field] == 0) {
theField[row][field].setImageDrawable(GetPlayer());
gameboard[row][field] = curPlayer;
changePlayer();
}
I don't think you are using the array like an array. The code is using the array's slots like 9 different variables with the same name and a unique suffix like: [5]
Try using a 2 dim array that...
Or use an array of Field objects:
Field[] theSquares = new Field[9];
Then assign each slot with a Field object;
Or define the array with existing the existing Field objects:
Field[]...
Here is the tutorial for arrays:
Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
I suggest you put the current code aside for now and write a simple program with...
Can you explain where the problem is?
Defining an array
assigning values to the slots in an array
referencing the contents of a slot in an array
Can you use an array for the board instead of 9 different variables? The array can hold references to the Field objects. That will reduce the number of if tests needed.