File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Help with method

John Daniels

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

Joined: May 02, 2006
Posts: 5

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,

John Daniels

Joined: May 09, 2006
Posts: 4
I agree. Here's the link:
subject: Help with method
It's not a secret anymore!