0

I'm trying to make a Tic Tac Toe game for my Java class. I am not able to use JButtons only JPanels. I'm stuck on the part where my program determines if there are 3 x's or o's in a row.

public void winner()
	{
		if(3 = tictactoe[0].turn + tictactoe[1].turn + tictactoe[2].turn)
		{

			System.out.println("X has won");

		}


	}

I had established turn as being a 1(x) or a 2(o). If 3 panels in a row [0] + [1] + [2] = 3 then it would mean that "x" had won. I need to add more to it to check all panels but I am getting errors just testing it. tictactoe[] are the panels 0-8. Turn is in the class "MousePart" which contains the MouseEvent. Three of the errors are that it cannot find the variable turn. I'm not sure how to establish it so it knows to go to MousePart. The Fourth error is unexpected type - probably being the 3 = tictactoe[]. I'm not sure what to do.

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by hiddepolen
0

ok look at this pattern of arrays[row][column]
Case 1:
(hint] set a loop and if statement
[0][0],[0][1],[0,2] == win
[1][0],[1][1],[1,2] == win
[2][0],[2][1],[2,2] == win
Case 2:
(for loops and if statement)
[0][0],[1][0],[2,0] == win
[0][1],[1][1],[2,1] == win
[0][2],[1][2],[2,2] == win

Case 3:
no loops needed
[0][2],[1][1],[2][0]
[0][0],[1][1],[2][2]


hope that helps lol

0

If you post all your code, we can help you with the errors. Usually, the errors have a long explanation what they are, and on what line they occur. Check that.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.