给个email到[email protected]
我直接给你个TTT代码
你要网络对战的还是单机 的?

解决方案 »

  1.   

    我要的是用户定大小的。不知你的是不是。
    如果试试我的程序就最好了,我要解决nullpointer Exception,逻辑不难的。
    谢谢了好心人。
    那位帮我调试一下吧,我知道比较过分,但是要影响我得GPA啊。
      

  2.   

    我跟蹤進去看了一下,你在開頭賦值的array數組,在進入totalTest()函數時,array變為null,所以就丟出空指針異常了jdk的demo目錄里有這個遊戲的demo,也許你知道了~~~ hehe
      

  3.   

    String array[][] = new String[size][size];
    你把array又定义了一次,改为:
    array = new String[size][size];就Ok啦,不过你的程序还有很多问题,自己慢慢解决吧,嘿嘿...
      

  4.   

    我知道你的錯誤了!
    你的array定義了兩遍!!!
    你賦值的array是局部變量,而你真正的array並沒有賦值,只要把第二次出現的array前面的String去掉就ok了
      

  5.   

    aiur兄台,如何解决呢,用传递吗?
    snowredfox:你的方法不行啊
      

  6.   

    肯定行,我都运行过啦...
      public static void main(String args[])
      {
       array = new String[size][size];
               }
      

  7.   

    你的
    public static boolean rowTest(int pos, int size)
    这个方法的这个语句出错:if(array[(pos-1)/size][i] != array[(pos-1)/size][i+1])array为空对象!!!
      

  8.   

    唉,怎麼又冒出個數組越界的異常了,在colTest()函數我先後輸了5和6,你在colTest中的if(array[i][(pos-1)%size -1] != array[i+1][(pos-1)%size -1])
    明顯就出錯了, (pos-1)%size-1 這個值為-1,當然數組越界了
    你要注意"%"是取模,不是取整,也許你該用"/"
      

  9.   

    不好意思,Null的问题解决了,不过我实在是没时间了。早上8:00就要交了,我在加国,现在凌晨两点,帮帮忙了。 我不是那种偷懒的人。再次谢谢了各位。
      

  10.   

    不明白你具体的思路是什么,不过有一点两个字符串是不能直接比较大小的,比如这句:(array[i][(pos-1)%size -1] != array[i+1][(pos-1)%size -1])应该写为(!array[i][(pos-1)%size -1].equals(array[i+1][(pos-1)%size -1]))你函数中对数组边界值处理得不好,没有保证对数组的操作是在数组的范围之类.记住,数组的下标是以0开始的,而不是1自己努力吧!
      

  11.   

    我都该好了,exception都去掉了
    不过我只输入了一次,就说我赢了。唉。
      

  12.   

    懒了,没有给你加上异常处理,所以一定要合法输入
    程序很小,哪里要用300分
    希望对你还来得及import javax.swing.JOptionPane; public class Tictacto
    {
    static String array[][];
    static int size;// the size of the game
    static int counter;
    static int pos;
    static boolean win = false;  

      public static void main(String args[])
      {
       size = Integer.parseInt(JOptionPane.showInputDialog(
       "Enter the size fo the :(3-10)"));
      
       array = new String[size][size];
      
       for(int i = 0; i < size; i++ )
         for(int t = 0; t < size; t++)
            array[t][i] = "e"; // "e" indicates the position 
                                 // has not been used.  
                                 
       print(array, size);
       while(!win)
       {     
        pos = Integer.parseInt(JOptionPane.showInputDialog("Choose the position: "));     
        play(pos, counter,size);
        counter++;
        win = totalTest(pos, size);
        print(array, size);
        }
      
       System.out.println("Congratulations! You won !!!");
        System.exit(0);
      }
         
       
       // show the steps of the palyer
       public static void play(int pos, int counter, int size)  
       {
          if(array[(pos-1)/size][(pos-1)%size] =="e")
            if(counter%2 == 1)
               array[(pos-1)/size][(pos-1)%size] = "x";
        else
           array[(pos-1)/size][(pos-1)%size] = "o";
       }
       
       // total
       public static boolean totalTest(int pos, int size)
       { 
         boolean r1, r2, r3, r4;
         r1 = rowTest(pos,size);
         r2 = colTest(pos,size);
         r3 = left(pos,size);
         r4 = right(pos, size);
         System.out.println(r1);
         System.out.println(r2);
         System.out.println(r3); 
         System.out.println(r4);      
         if(r1||r2||r3||r4)
            return true;
         else
            return false;      
       }
        // test the row
       public static boolean rowTest(int pos, int size)
       {
       
        for(int i =0; i < size - 1; i++){    
    if(array[(pos-1)/size][i].equals("e"))
    return false;
           if(array[(pos-1)/size][i] != array[(pos-1)/size][i+1] )
            return false;        
        }
        return true;
        } 
        
        // test the column
        public static boolean colTest(int pos, int size)
        {      
         for(int i = 0; i < size - 1; i++){
          if(array[i][(pos-1)%size ].equals("e"))
    return false;
          if(array[i][(pos-1)%size ] != array[i+1][(pos-1)%size ])
      return false;  
    }
       return true;
        }
        
        // test the left cross
        public static boolean left(int pos, int size)
        {
         for (int i = 0; i < size - 1; i++){
         if(array[i][i].equals("e"))
    return false;
            if(array[i][i] != array[i+1][i+1])
              return false;           
        }
            return true;
        }
        
        // test the right cross
        public static boolean right(int pos, int size)
        {
         for(int i = 0; i < size - 1; i++){
         if(array[size-1-i][i].equals("e"))
    return false;
             if(array[size-1-i][i] != array[size-1-i-1][i+1])
              return false;           
          }     
          return true;          
        }
        
        // print to Screen
        public static void print(String arr[][], int size)
        {            
                 
         for(int p = 0; p < size;  p++,System.out.println())
            for(int q = 0; q < size; q++)
                System.out.print(arr[p][q] + "  ");
              System.out.println();        
        }     
      }