Results 1 to 4 of 4
Thread: Simple Tic Tac Toe class
- 01-26-2011, 03:32 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 15
- Rep Power
- 0
Simple Tic Tac Toe class
TicTacToeGame.class has only one method, whose public interface is
Method makeMark returns: a null if the cell indicated by row and column has already been marked an X if it is X's turn (X gets to go first) a Y if it is Y's turnJava Code:public String makeMark(int row, int column)
Thus makeMark will have to keep of marks made previously and return the appropriate string for the requested cell.
Here's what I have so far. I want to first work with the "X" before checking the spaces.
Java Code:public class TicTacToeGame { public String makeMark(int row, int column){ boolean arr[][] = null; for (row=0; row<=2; row++){ for (column=0; column<=2; column++) { if (arr[row][column] = true) { System.out.println("X"); } } } return null; } }
-
You're getting null pointer exceptions aren't you? You're array is null, and that won't work. I don't think an array of boolean will work regardless since boolean only holds two values: true and false, and you need 3 values, empty, x and y. Myself, I'd use an array of an Enum, but you could use an int array as well.
- 01-26-2011, 03:44 AM #3
Member
- Join Date
- Jan 2010
- Posts
- 15
- Rep Power
- 0
Well first I want to check to see if the spaces are empty first. That's why i think i would only need true and false. The 3 values would come later.
-
This makes no sense.
1) First off, are you getting a nullpointerexception?
2) Having a null array tells you nothing about whether spaces are empty or not.
3) How will you tell whether an x or an o is in the space? Why not implement that now?
4) Then what is your current question?
Similar Threads
-
How to do a simple class+object thing
By ilop12 in forum New To JavaReplies: 8Last Post: 06-03-2010, 04:08 PM -
simple exercise for class, help please?
By Boomer1 in forum Other IDEsReplies: 10Last Post: 11-02-2009, 06:12 AM -
dont let me create simple class
By itaipee in forum New To JavaReplies: 5Last Post: 01-11-2009, 11:07 AM -
Simple example that reads a value from another class
By rizo in forum New To JavaReplies: 1Last Post: 11-12-2008, 03:43 PM -
A simple generic class
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:41 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks