File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Help with method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Help with method" Watch "Help with method" New topic
Author

Help with method

John Daniels
Greenhorn

Joined: May 09, 2006
Posts: 4
I wrote a simple program for tictactoe and have everything working except a method to check and see if a player has won the game diagonally. I am not sure how to write the for loop to check the board.

Could someone please help.
Trevor Cole
Greenhorn

Joined: May 02, 2006
Posts: 5
John,

I wrote a TicTacToe in J2ME, I simply use an if statement to check the value of the three cells in the diagonal...

My code looks like this...

// check first diagonal
if ((cellValues[0] == cellValues[4]) && (cellValues[4] == cellValues[8])) {
tileType = cellValues[0];
}

// check second diagonal
if ((cellValues[2] == cellValues[4]) && (cellValues[4] == cellValues[6])) {
tileType = cellValues[2];
}

cellValues[] holds the current tileType (X, O or null).

Hope this helps,


Trevor
John Daniels
Greenhorn

Joined: May 09, 2006
Posts: 4
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with method