Results 1 to 5 of 5

Thread: Output My Board

  1. #1
    Join Date
    Dec 2013
    Posts
    16
    Rep Power
    0

    Default Output My Board

    Hello everyone I have been busy working on a program with two packages one to test the board and the board. I have not been able to find the problem with my code.

    Java Code:
    
    ///Main class
    import games.board.*; 
    import games.board.Board; 
    import games.board.Cell; 
    import games.board.Mark; 
    
    public class BoardGameTester { 
    
    public static void main(String[] args) { 
    
    // 3x3 board for Tic Tac Toe 
    Board tttgameboard = new Board (3,3); 
    
    // 6x7 board for Connect Four 
    Board cfgameboard = new Board (6,7); 
    
    // 5x8 board for Mastermind; blue mark 
    Board mmgameboard = new Board (5,8); 
    
    
    
    
    System.out.println (" Tic Tac Toe game board "); 
    tttgameboard.setCell(Mark.CROSS,1,1); 
    System.out.println(tttgameboard.toString()); 
    
    System.out.println(" Connect Four game board "); 
    cfgameboard.setCell(Mark.RED,0,0); 
    System.out.println(cfgameboard.toString()); 
    
    System.out.println (" Mastermind game board "); 
    mmgameboard.setCell(Mark.GREEN,0,0); 
    System.out.println(mmgameboard.toString()); 
    } 
    } 
    
    //Board class
    package games.board; 
    
    public class Board { 
    private Cell[][] cells; 
    
    public Board(int i, int i0) { 
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. 
    } 
    
    public class Board { 
    private Cell[][] cells; 
    
    public Board(int rows, int columns) { 
    cells = new Cell[rows][columns]; 
    for (int r = 0; r < cells.length; r++) { 
    for (int c = 0; c < cells[r].length; c++) { 
    cells [r][c] = new Cell (r,c); 
    
    } 
    } 
    } 
    
    public void setCell (Mark mark, int row, int column) throws 
    IllegalArgumentException { 
    if (cells[row][column].getContent() == Mark.EMPTY) 
    cells[row][column].setContent(mark); 
    else throw new IllegalArgumentException ("Player already there!"); 
    } 
    public Cell getCell(int row, int column) { 
    
    return cells[row][column]; 
    } 
    
    
    public String toString() { 
    StringBuilder str = new StringBuilder(); 
    
    for (int r = 0; r < cells.length; r++) { 
    str.append("|"); 
    
    
    
    for (int c = 0; c < cells.length; c++) { 
    switch (cells[r][c].getContent()) { 
    case NOUGHT: 
    str.append("O"); 
    break; 
    case CROSS: 
    str.append("X"); 
    break; 
    case YELLOW: 
    str.append("Y"); 
    break; 
    case RED: 
    str.append("R"); 
    break; 
    case BLUE: 
    str.append("B"); 
    break; 
    case GREEN: 
    str.append("G"); 
    break; 
    case MAGENTA: 
    str.append("M"); 
    break; 
    case ORANGE: 
    str.append("N"); 
    break; 
    default: //Empty 
    str.append(" "); 
    } 
    str.append("|"); 
    } 
    str.append("\n"); 
    } 
    return str.toString(); 
    } 
    } 
    //Cell class
    package games.board; 
    
    public class Cell { 
    private Mark content; 
    private int row, column; 
    
    public Cell(int row, int column) { 
    this.row = row; 
    this.column = column; 
    content = Mark.EMPTY; 
    } 
    
    public Mark getContent() { return content;} 
    
    public void setContent (Mark content) { this.content = content; } 
    
    public int getRow() { return row; } 
    
    public int getColumn() { return column; } 
    } 
    //Mark class
    package games.board; 
    
    public class Mark { 
    static Mark EMPTY; 
    public static Mark RED; 
    public static Mark GREEN; 
    
    
    //Result when game is completed 
    public enum Mark {EMPTY, NOUGHT, CROSS, YELLOW, RED, BLUE, GREEN, MAGENTA, ORANGE} 
    } 
    //Outcome class
    package games.board; 
    public class Outcome { 
    
    public enum Outcome { 
    PLAYER1_WIN, PLAYER2_WIN, CONTINUE, TIE} 
    } 
    //Player class
    package games.board; 
    public class Player { 
    
    public enum Player{ 
    FIRST,SECOND} 
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,932
    Rep Power
    8

    Default Re: Output My Board

    What does this code do? Does it compile? Does it run? Does it exhibit some strange behavior? Something else?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Output My Board

    It's not clear that there is a problem unless you state what the code is supposed to do vs. what it actually does.
    Get in the habit of using standard Java naming conventions!

  4. #4
    Join Date
    Dec 2013
    Posts
    16
    Rep Power
    0

    Default Re: Output My Board

    I am debugging code in console and in Netbeans. I has many errors that I am working to clean up. The first error right off is games.board is said to not exist seems strange to me as I know it does.

  5. #5
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Output My Board

    Your classpath probably isn't set right. Google it.
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. How do i create this board ?
    By hunterr1234 in forum AWT / Swing
    Replies: 21
    Last Post: 10-30-2011, 08:19 PM
  2. Replies: 2
    Last Post: 06-29-2011, 09:08 AM
  3. BlueJ Tic-Tac-Toe Board
    By AshtonRose in forum New To Java
    Replies: 9
    Last Post: 04-10-2011, 12:33 AM
  4. TINI Board
    By ApheoXAIO in forum New To Java
    Replies: 1
    Last Post: 07-03-2010, 12:52 PM
  5. How to do a score board?
    By vlan in forum Java Applets
    Replies: 11
    Last Post: 06-03-2010, 10:10 AM

Posting Permissions

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