View Single Post
  #2 (permalink)  
Old 01-10-2008, 10:50 PM
gibsonrocker800's Avatar
gibsonrocker800 gibsonrocker800 is offline
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
well there are several ways you can do this. one way, the more inefficient way, it to set up arrays for all of the possible wins, and check if the board is equal to any of these ways. This is a mediocre way of doing it. So, the way i would do it is add a method to TicTacToe called public boolean rowsWin() in which it checks if the player won in the rows (horizontally). You just set up a loop that iterates through the array and if the element of the current iteration is equal to "x", add it to an ArrayList of Strings. Then you check to see if the size of the ArrayList is equal to 3, and if so, return true. if not, they obviously didn't win, because the loop only adds an element if that element is "x". Do the same thing for the columns, but changing the structure of the array iteration. Then, make a method for finalWin() and say... if rowsWin and columnsWin() return true, then return true (they won). Now, i'm not going to provide code because i want to see if you can figure this out on your own, but you now have the general logic needed. Good luck!
__________________
//Haha javac, can't see me now, can ya?
Reply With Quote