Results 1 to 4 of 4
  1. #1
    hydride is offline Member
    Join Date
    Jan 2010
    Posts
    15
    Rep Power
    0

    Default Simple Tic Tac Toe class

    TicTacToeGame.class has only one method, whose public interface is
    Java Code:
    public String makeMark(int row, int column)
    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 turn
    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;
    
    		
    	}
    	}

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  3. #3
    hydride is offline Member
    Join Date
    Jan 2010
    Posts
    15
    Rep Power
    0

    Default

    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.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by hydride View Post
    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.
    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

  1. How to do a simple class+object thing
    By ilop12 in forum New To Java
    Replies: 8
    Last Post: 06-03-2010, 05:08 PM
  2. simple exercise for class, help please?
    By Boomer1 in forum Other IDEs
    Replies: 10
    Last Post: 11-02-2009, 07:12 AM
  3. dont let me create simple class
    By itaipee in forum New To Java
    Replies: 5
    Last Post: 01-11-2009, 12:07 PM
  4. Replies: 1
    Last Post: 11-12-2008, 04:43 PM
  5. A simple generic class
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 08:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •