Results 1 to 3 of 3
  1. #1
    ecc.soccer is offline Member
    Join Date
    Oct 2013
    Posts
    6
    Rep Power
    0

    Default Board method for Tic Tac Toe game

    //we have not learned 2D arrays. I am stuck on how to create a tic tac tow board without using 2D arrays. Please help

    public class Board
    {
    // instance variables - replace the example below with your own
    private char [] spots = new char[9];

    /**
    * Constructor for objects of class Board
    */
    public Board()
    {
    // initialise instance variables
    spots = new char[]{'1', '2', '3', '4', '5', '6', '7', '8', '9'};
    }

    /**
    * Draws the current board.
    */
    public void drawBoard()
    {

    }

    /**
    * Determines if this board is full.
    *
    * @return true if there are no available spots on this board, false else
    */

    public boolean full() {

    }

    /**
    * Get the marker that is on the given spot
    *
    * @param place the spot on the board, 1-9
    * @return the char on the given spot
    */

    public char getSpot(int place) {

    }

    /**
    * Determine if the given spot is available.
    *
    * @param place hte spot, 1-9, on the board
    * @return true if the given spot is unoccupied, false els
    */

    public boolean isAvailable(int place) {

    }

    /**
    * print the availbale characters
    */

    public static void printChars() {
    }

    /**
    * put the given mark on the given place of this board, if the given place is unoccupied
    *
    * @param place the spot, 1-9, on which to place the marker
    * @param mark the mark to put on the given spot
    * @return place if the spot is not occupied, -1 else
    */

    public int putSpotOnBoard(int place, char mark) {

    }
    }

  2. #2
    ecc.soccer is offline Member
    Join Date
    Oct 2013
    Posts
    6
    Rep Power
    0

    Default Re: Board method for Tic Tac Toe game

    Class Board

    java.lang.Object
    extended by Board
    public class Board
    extends java.lang.Object
    Board displays the Tic Tac Toe board. It has one instance variable, an array of characters, which are referred to as spots in the documentation. Here is an example of the array, and the corresponding tic tac toe board:

    array: {'x', 'o', 'x', 'x', 'o', 'x','x', 'o', 'x'}

    board:
    x | o | x
    ---|---|---
    x | o | x
    ---|---|---
    x | o | x

    Note that the array goes from 0 to 8, but the places the spots go are from 1 - 9. The figure below shows the places on the board. This is in fact what the board looks like when it is first created.
    Board right after it's created

    1 | 2 | 3
    ---|---|---
    4 | 5 | 6
    ---|---|---
    7 | 8 | 9

    Version:
    Nov 24, 2013
    Author:
    llambert

    Constructor Summary
    Board()
    Default (and only) constructor.

    Method Summary
    void drawBoard()
    Draw the current board.
    boolean full()
    Determine if this board is full.
    char getSpot(int place)
    Get the marker that is on the given spot.
    boolean isAvailable(int place)
    Determine if the given spot is available to play.
    static void printChars()
    Print the available characters.
    int putSpotOnBoard(int place, char mark)
    Put the given mark on the given place of this board, if the given place is unoccupied (contains a '1' - '9').

    Methods inherited from class java.lang.Object
    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait


    Constructor Detail
    Board

    public Board()
    Default (and only) constructor. Array is initialized to contain 9 characters, '1', '2', '3', ... '9'. See the last figure in the javadoc header for what a newly created board looks like.
    Method Detail
    drawBoard

    public void drawBoard()
    Draw the current board. It starts and ends with a blank line. See the first figure in the javadoc header for an example of what a board looks like.
    full

    public boolean full()
    Determine if this board is full. A spot is unoccupied if it has a '1', '2', ... or '9'.
    Returns:
    true if there are no available spots on this board, false else
    getSpot

    public char getSpot(int place)
    Get the marker that is on the given spot.
    Parameters:
    place - the spot on the board, 1-9.
    Returns:
    the char on the given spot
    isAvailable

    public boolean isAvailable(int place)
    Determine if the given spot is available to play. A spot is unoccupied if it has a '1', '2', ... or '9'.
    Parameters:
    place - the spot, 1 - 9, on the board.
    Returns:
    true if the given spot is unoccupied, false else
    printChars

    public static void printChars()
    Print the available characters. This method prints all of the UNICODE characters so that a player can see the available characters from which they can pick their marker. Note that some UNICODE characters are wider than the standard characters (e.g., letters or numbers). Picking them might cause the board alignment to be somewhat askew. This method is not called during the playing of the game.
    putSpotOnBoard

    public int putSpotOnBoard(int place,
    char mark)
    Put the given mark on the given place of this board, if the given place is unoccupied (contains a '1' - '9').
    Parameters:
    place - the spot, 1 - 9, on which to place the marker
    mark - the marker to put on the given spot
    Returns:
    place if the spot is not occupied, -1 else

  3. #3
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,376
    Rep Power
    5

    Default Re: Board method for Tic Tac Toe game

    Actually, your second post confuses the issue. It would be clearer to just use code with comments which describe the unusual. And please place your code between code tags [CODE][/CODE] for better formatting.

    With regard to your output, it looks okay except the boarders need better alignment. So what is the problem?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Java board game
    By sumys in forum New To Java
    Replies: 10
    Last Post: 03-18-2012, 09:23 PM
  2. Board Game arrays?
    By linc186 in forum New To Java
    Replies: 1
    Last Post: 03-19-2011, 09:19 PM
  3. Help with JAVA board game
    By corky1501 in forum New To Java
    Replies: 5
    Last Post: 02-09-2011, 03:18 AM
  4. need help making a game board
    By Don k in forum New To Java
    Replies: 2
    Last Post: 04-30-2010, 12:09 AM
  5. game board design
    By tomitu in forum New To Java
    Replies: 12
    Last Post: 02-27-2010, 05:31 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
  •