Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Can someone help me what I am doing wrong with this code?

Can someone help me what I am doing wrong with this code?

Scheduled Pinned Locked Moved Java
questionjavagame-devhelptutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jainam Patel
    wrote on last edited by
    #1

    Hey Guys, I am making a TicTacToe Game in Java and I am having someone difficulty figuring out what I am doing Wrong.

    1. I made a tic tic toe board which look something like this.
      Hide Copy Code
      System.out.println(" | | );
      System.out.println( 0 | 1 | 2 );
      System.out.println( | | );
      System.out.println( -------------------------------);
      System.out.println( | | );
      System.out.println( 3 | 4 | 5 );
      System.out.println( | | );
      System.out.println( -------------------------------);
      System.out.println( | | );
      System.out.println( 6 | 7 | 8 );
      System.out.println( | | );

    2. I asked the user for a number between 0-8 and the number they choose will be Replaced by X.

    Say they choose number 5. This is how it will look like.

    Hide Copy Code
    System.out.println(" | | );
    System.out.println( 0 | 1 | 2 );
    System.out.println( | | );
    System.out.println( -------------------------------);
    System.out.println( | | );
    System.out.println( 3 | 4 | X );
    System.out.println( | | );
    System.out.println( -------------------------------);
    System.out.println( | | );
    System.out.println( 6 | 7 | 8 );
    System.out.println( | | );

    1. I don't know how to create a loop which will keep asking the user for a number until it reaches to all the 8 numbers. Also, how do I check if the number is taken or not.

    IT WILL BE GREAT IF YOU CAN HELP ME.

    Richard DeemingR A Z 3 Replies Last reply
    0
    • J Jainam Patel

      Hey Guys, I am making a TicTacToe Game in Java and I am having someone difficulty figuring out what I am doing Wrong.

      1. I made a tic tic toe board which look something like this.
        Hide Copy Code
        System.out.println(" | | );
        System.out.println( 0 | 1 | 2 );
        System.out.println( | | );
        System.out.println( -------------------------------);
        System.out.println( | | );
        System.out.println( 3 | 4 | 5 );
        System.out.println( | | );
        System.out.println( -------------------------------);
        System.out.println( | | );
        System.out.println( 6 | 7 | 8 );
        System.out.println( | | );

      2. I asked the user for a number between 0-8 and the number they choose will be Replaced by X.

      Say they choose number 5. This is how it will look like.

      Hide Copy Code
      System.out.println(" | | );
      System.out.println( 0 | 1 | 2 );
      System.out.println( | | );
      System.out.println( -------------------------------);
      System.out.println( | | );
      System.out.println( 3 | 4 | X );
      System.out.println( | | );
      System.out.println( -------------------------------);
      System.out.println( | | );
      System.out.println( 6 | 7 | 8 );
      System.out.println( | | );

      1. I don't know how to create a loop which will keep asking the user for a number until it reaches to all the 8 numbers. Also, how do I check if the number is taken or not.

      IT WILL BE GREAT IF YOU CAN HELP ME.

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      You have already posted this in QA, and received an answer: Can someone help me what I am doing wrong with this code?[^]


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      • J Jainam Patel

        Hey Guys, I am making a TicTacToe Game in Java and I am having someone difficulty figuring out what I am doing Wrong.

        1. I made a tic tic toe board which look something like this.
          Hide Copy Code
          System.out.println(" | | );
          System.out.println( 0 | 1 | 2 );
          System.out.println( | | );
          System.out.println( -------------------------------);
          System.out.println( | | );
          System.out.println( 3 | 4 | 5 );
          System.out.println( | | );
          System.out.println( -------------------------------);
          System.out.println( | | );
          System.out.println( 6 | 7 | 8 );
          System.out.println( | | );

        2. I asked the user for a number between 0-8 and the number they choose will be Replaced by X.

        Say they choose number 5. This is how it will look like.

        Hide Copy Code
        System.out.println(" | | );
        System.out.println( 0 | 1 | 2 );
        System.out.println( | | );
        System.out.println( -------------------------------);
        System.out.println( | | );
        System.out.println( 3 | 4 | X );
        System.out.println( | | );
        System.out.println( -------------------------------);
        System.out.println( | | );
        System.out.println( 6 | 7 | 8 );
        System.out.println( | | );

        1. I don't know how to create a loop which will keep asking the user for a number until it reaches to all the 8 numbers. Also, how do I check if the number is taken or not.

        IT WILL BE GREAT IF YOU CAN HELP ME.

        A Offline
        A Offline
        Afzaal Ahmad Zeeshan
        wrote on last edited by
        #3

        Why are you constantly posting same question in two different forums? I have already posted the answer to your problem on your question, Can someone help me what I am doing wrong with this code?[^]. Read that thread.

        The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

        1 Reply Last reply
        0
        • J Jainam Patel

          Hey Guys, I am making a TicTacToe Game in Java and I am having someone difficulty figuring out what I am doing Wrong.

          1. I made a tic tic toe board which look something like this.
            Hide Copy Code
            System.out.println(" | | );
            System.out.println( 0 | 1 | 2 );
            System.out.println( | | );
            System.out.println( -------------------------------);
            System.out.println( | | );
            System.out.println( 3 | 4 | 5 );
            System.out.println( | | );
            System.out.println( -------------------------------);
            System.out.println( | | );
            System.out.println( 6 | 7 | 8 );
            System.out.println( | | );

          2. I asked the user for a number between 0-8 and the number they choose will be Replaced by X.

          Say they choose number 5. This is how it will look like.

          Hide Copy Code
          System.out.println(" | | );
          System.out.println( 0 | 1 | 2 );
          System.out.println( | | );
          System.out.println( -------------------------------);
          System.out.println( | | );
          System.out.println( 3 | 4 | X );
          System.out.println( | | );
          System.out.println( -------------------------------);
          System.out.println( | | );
          System.out.println( 6 | 7 | 8 );
          System.out.println( | | );

          1. I don't know how to create a loop which will keep asking the user for a number until it reaches to all the 8 numbers. Also, how do I check if the number is taken or not.

          IT WILL BE GREAT IF YOU CAN HELP ME.

          Z Offline
          Z Offline
          zhijzan
          wrote on last edited by
          #4

          public class tictok {

          private int OO = 1;
          private int XX = -1;
          public int arr\[\] = new int\[10\];
          
          public int getArrPos(int i,int j)
          {
              if (i==1) {
                  return j == 4?1:j==15?2:j==26?3:-1;
              }
              if (i==5) {
                  return j == 4?4:j==15?5:j==26?6:-1;
              }
              if (i==9) {
                  return j == 4?7:j==15?8:j==26?9:-1;
              }
              return -1;
          }
          
          public void printMap() {
              for(int i=0;i<11;i++) {
                  for(int j=0;j<32;j++) {
                      if (i==3 || i==7) {
                          System.out.print("-");
                          continue;
                      }
                      if (j==10 || j==21) {
                          System.out.print("|");
                          continue;
                      }
                      if(getArrPos(i, j)!=-1){
                          if (arr\[getArrPos(i, j)\]== OO) {
                              System.out.print("O");
                          }else if (arr\[getArrPos(i, j)\]==XX) {
                              System.out.print("X");
                          }else  {
                              System.out.print(getArrPos(i, j));
                          }
                          continue;
                      }
                      System.out.print(" ");
                  }
                  System.out.println();
              }
          }
          
          public void play(int n,boolean isO)
          {
              if (n>9) {
                  System.out.println("silly B");
                  return;
              }
              arr\[n\]= isO?1:-1;
          }
          
          
          public static void main(String\[\] args) {
              tictok tt = new tictok();
              tt.play(8, true);
              tt.play(6, false);
              tt.printMap();
          
          }
          

          }

          is it useful?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups