This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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

Win a copy of Building Microservices this week in the Design forum!
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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Help with method
It's not a secret anymore!