Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: hi everyone Can someone please help Warning NOOB here

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default hi everyone Can someone please help Warning NOOB here

    I know this is really simple. I have a tick tack toe game and when i run it it works and there are no errors. but the X's and O'x do not show in the board can someone please look at the code and show me the right way to do it. i know this is kinda lame question but i have been looking all over the net and cant seem to figure out the proper way to do it. I know the problem is in the "gameBoard" method and its cause i am telling the code to print the same board every time but i dont know how to do it the right way


    package chap7MDA;

    import java.util.Scanner;


    public class chapexe7we {


    public static void main(String[] args) {

    char[][] board = new char [3][3];//make a game board

    gameBoard(board);// call the method game board to make the board

    do {
    makeAMove(board, 'X');
    gameBoard(board);

    if(wiNNing('X', board)) {
    System.out.println("X player won");
    System.exit(1);
    }

    else if(tie(board)) {
    System.out.println("No body won, It's a Draw Partners");
    System.exit(2);
    }



    makeAMove(board, 'O');
    gameBoard(board);


    if(wiNNing('O', board)) {
    System.out.println("O player won");
    System.exit(3);
    }

    else if(tie(board)) {
    System.out.println("No body won, It's a Draw Partners");
    System.exit(4);
    }

    } while(true);


    }//end main




    public static void gameBoard(char [][] gBoard){

    for(int i = 0; i < 3; i++){//populate the board with boarders
    for(int j = 0; j < i; j++) {
    System.out.println("\n-------------");
    System.out.print("| | | | ");

    }
    }
    System.out.println("\n-------------");//put a line at the bottom

    }//end gameBoard


    public static void makeAMove (char [][]board, char XsAnd0s){
    Scanner input = new Scanner(System.in);//make a scanner object called input

    boolean turn = false;

    do{

    System.out.println("Please enter the row for " + XsAnd0s + ":" );//prompt user
    int row = input.nextInt();//take in a value for the row
    System.out.println("Please enter the column for " + XsAnd0s + ":");//prompt user
    int col = input.nextInt();//take in a value for the column

    if (board[row][col] == 0){
    board[row][col] = XsAnd0s;
    turn = true;
    }
    else {
    System.out.println("The other player already has this spot");
    }

    }
    while(!turn);
    }

    public static boolean wiNNing(char XOs, char[][]board ){

    for (int i = 0; i <3; i++)
    if(XOs == board[i][0] && XOs == board[i][1] && XOs ==board[i][2])
    return true;

    for (int j = 0; j < 3; j++)
    if (XOs == board[0][j] && XOs == board[1][j] && XOs == board[2][j])
    return true;
    if(XOs == board[0][0] && XOs == board[1][1] && XOs == board[2][2])
    return true;

    return XOs == board[0][2] && XOs == board[1][1] && XOs == board[2][0];

    }

    public static boolean tie (char[][] board){
    boolean noWinner = false;
    for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++)
    if(board[i][j] == 0)
    return noWinner;


    }
    return true;
    }



    }//end exercise7


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,751
    My Mood
    Mellow
    Thanks
    233
    Thanked 711 Times in 697 Posts

    Default Re: hi everyone Can someone please help Warning NOOB here

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

Similar Threads

  1. I'm a noob, noob questions.
    By Mickyy in forum Java Theory & Questions
    Replies: 6
    Last Post: October 25th, 2013, 07:27 AM
  2. Warning when I do a build
    By mad_hatter in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 24th, 2012, 02:26 PM
  3. Warning! Greenhorn alert
    By Montrell79 in forum Member Introductions
    Replies: 2
    Last Post: March 6th, 2012, 02:56 AM
  4. Serializable compiler warning
    By kc120us in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: September 25th, 2011, 04:12 PM
  5. suppress warning
    By mDennis10 in forum Java Theory & Questions
    Replies: 2
    Last Post: September 10th, 2011, 10:06 AM