ServeOneClient.java
上传用户:ptnike
上传日期:2007-06-15
资源大小:61k
文件大小:25k
源码类别:

棋牌游戏

开发平台:

Java

  1. import java.io.*;
  2. import java.net.*;
  3. /**
  4.  * <p>Title: chess server</p>
  5.  * <p>Description: chess server</p>
  6.  * <p>Copyright: Copyright (c) 2003</p>
  7.  * <p>Company: e-top</p>
  8.  * @author cylix
  9.  * @version 1.0
  10.  */
  11. public class ServeOneClient extends Thread{
  12.     private Socket socket;
  13.     private String player=null;
  14.     protected ObjectInputStream in;
  15.     protected ObjectOutputStream out;
  16.     public ServeOneClient(Socket s)
  17.         throws IOException {
  18.         socket = s;
  19.         //System.out.println("server socket begin ...");
  20.         in =new ObjectInputStream(
  21.             socket.getInputStream());
  22.         // Enable auto-flush:
  23.         out = new ObjectOutputStream(
  24.             socket.getOutputStream());
  25.         //System.out.println("server socket in and out ...");
  26.         // If any of the above calls throw an
  27.         // exception, the caller is responsible for
  28.         // closing the socket. Otherwise the thread
  29.         // will close it.
  30.         start(); // Calls run()
  31.     }
  32.     public void run() {
  33.         Message obj=new Message();
  34.         while (true) {
  35.             try {
  36.                 obj =(Message)in.readObject();
  37.                 // write message by doMessage() function
  38.                 doMessage(obj);
  39.             }catch(ClassNotFoundException er){}
  40.             catch(IOException e){}
  41.         }
  42.     /*
  43.         System.out.println("closing...");
  44.         try {
  45.             socket.close();
  46.         }catch (IOException e) {}
  47.      */
  48.     }
  49.     /**
  50.      * deal with messages
  51.      * @param msg
  52.      * @return 1= victory request 2=socket closeed
  53.      */
  54.     public int doMessage(Message msg){
  55.         //System.out.println("doMessage begin...type="+msg.type);
  56.         switch(msg.type){
  57.             case 1:{//new connect to the server
  58.                 sendNewPlayer(msg); //here client must reply with type==10
  59.                 addPlayer(msg);     // msg.msg == new player's name
  60.                 break;
  61.             }
  62.             case 2:{// put chessman
  63.                 putChessman(msg);
  64.                 break;
  65.             }
  66.             case 3:{//request for another to play
  67.                 requestAnother(msg);
  68.                 break;
  69.             }
  70.             case 4:{
  71.                 denyRequest(msg);
  72.                 break;
  73.             }
  74.             case 5:{
  75.                 acceptRequest(msg);
  76.                 break;
  77.             }
  78.             case 6:{//send victory
  79.                 checkVictory(msg);
  80.                 break;
  81.             }
  82.             case 7:{//send disconnection
  83.                 getdisconnect(msg);
  84.                 break;
  85.             }
  86.             case 8:{//save game
  87.                 break;
  88.             }
  89.             case 12:{//setting information
  90.                 boolean flag=true;
  91.                 setting(msg,flag);
  92.                 break;
  93.             }
  94.             case 13:{
  95.                 boolean flag=false;
  96.                 setting(msg,flag);
  97.                 break;
  98.             }
  99.             case 19:{
  100.                 playerRefresh(msg);
  101.                 break;
  102.             }
  103.             case 20:{
  104.                 try{
  105.                     this.out.writeObject(msg);
  106.                 }catch(IOException e){
  107.                     e.printStackTrace();
  108.                 }
  109.                 break;
  110.             }
  111.             default:{
  112.             }
  113.         }//end switch
  114.         return 0; // end correctly
  115.     }
  116.     /**
  117.      * judge game and update all client's panel
  118.      * type = 7 sender will close game
  119.      * @param msg
  120.      */
  121.     public void getdisconnect(Message msg){
  122.         Group gg = null;
  123.         Player pp = null;
  124.         String str=null;
  125.         //if disconnector in a group
  126.         for(int i=0;i<Server.groupList.size();i++){
  127.             gg = (Group)Server.groupList.get(i);
  128.             if(this.equals(gg.selfSocket)==true){
  129.                 //send gg.player win
  130.                 msg.type=6; // gg.player win
  131.                 try{
  132.                     gg.playerSocket.out.writeObject(msg);
  133.                 }catch(IOException e){
  134.                     e.printStackTrace();
  135.                 }
  136.                 sendLeftMsg(gg.self);
  137.                 //update groupList
  138.                 Server.groupList.remove(gg);
  139.                 return;
  140.             }
  141.             if(this.equals(gg.playerSocket)==true){
  142.                 msg.type=6;
  143.                 try{
  144.                     gg.selfSocket.out.writeObject(msg);
  145.                 }catch(IOException e){
  146.                     e.printStackTrace();
  147.                 }
  148.                 sendLeftMsg(gg.player);
  149.                 Server.groupList.remove(gg);
  150.                 return;
  151.             }
  152.         }
  153.         // if disconnector in the playerList
  154.         for(int i=0;i<Server.playerList.size();i++){// find disconnector
  155.             pp = (Player)Server.playerList.get(i);
  156.             if(this.equals(pp.selfSocket)==true){
  157.                 break;
  158.             }
  159.         }
  160.         sendLeftMsg(pp.self);
  161.         Server.playerList.remove(pp); // remove disconnector from list
  162.         updateClient();
  163.     }
  164.     private void sendLeftMsg(String str){
  165.         char cc;
  166.         for(int i=0;i<50;i++){
  167.             cc=str.charAt(i);
  168.             if(cc!='')
  169.                 System.out.print(cc);
  170.             else break;
  171.         }
  172.         System.out.print(" has left server ...n");
  173.     }
  174.     /**
  175.      * deny request of play
  176.      * type ==4 msg == requestor's name
  177.      * @param msg
  178.      */
  179.     public void denyRequest(Message msg){
  180.         String denyName=null;
  181.         Player pp=null;
  182.         for(int i=0;i<Server.playerList.size();i++){
  183.             pp = (Player)Server.playerList.get(i);
  184.             if(this.equals(pp.selfSocket)==true){
  185.                 denyName = new String(pp.self);
  186.                 break;
  187.             }
  188.         }
  189.         for(int i=0;i<Server.playerList.size();i++){
  190.             pp = (Player)Server.playerList.get(i);
  191.             if(arrayMatchString(msg.msg,pp.self)==true){
  192.                 Message ms = new Message();
  193.                 ms.type=4;
  194.                 strToCharArray(denyName,ms.msg);
  195.                 try{// requestor 's socket send msg to it's client
  196.                     pp.selfSocket.out.writeObject(ms);
  197.                 }catch(IOException er){
  198.                     er.printStackTrace();
  199.                 }
  200.                 break;
  201.             }
  202.         }
  203.     }
  204.     /**
  205.      * B accept request of A server will update List
  206.      * type ==5 msg == A's name
  207.      * @param msg
  208.      */
  209.     public void acceptRequest(Message msg){
  210.         Player pps=null,ppd=null;//ppd = B pps = A
  211.         String acceptName=null;
  212.         for(int i=0;i<Server.playerList.size();i++){
  213.             ppd = (Player)Server.playerList.get(i);
  214.             if(this.equals(ppd.selfSocket)==true){
  215.                 break;
  216.             }
  217.         }
  218.         for(int i=0;i<Server.playerList.size();i++){
  219.             pps = (Player)Server.playerList.get(i);
  220.             if(arrayMatchString(msg.msg,pps.self)==true){
  221.                 break;
  222.             }
  223.         }
  224.         Message ss = new Message();
  225.         ss.type=14; // for B to set color and settings
  226.         ss.color=msg.color;
  227.         try{
  228.             ppd.selfSocket.out.writeObject(ss);
  229.         }catch(IOException e){
  230.             e.printStackTrace();
  231.         }
  232.         ss.type=5; // B's accept A's requestion
  233.         strToCharArray(ppd.self,ss.msg);
  234.         try{
  235.             pps.selfSocket.out.writeObject(ss);
  236.         }catch(IOException e){
  237.             e.printStackTrace();
  238.         }
  239.         //upload list display here, server will update Arraylist
  240.         Group p1 = new Group();
  241.         p1.self=new String(pps.self);
  242.         p1.selfSocket = pps.selfSocket;
  243.         p1.selfColor = pps.color;
  244.         p1.player = new String(ppd.self);
  245.         p1.playerSocket = ppd.selfSocket;
  246.         if(p1.selfColor==1){
  247.             p1.playerColor = 2;
  248.         }else{
  249.             p1.playerColor = 1;
  250.         }
  251.         p1.Setting = pps.setting;
  252.         Server.groupList.add(p1);
  253.         ///System.out.println(p1.self+p1.selfColor+" player "+p1.player+p1.playerColor);
  254.         if(Server.playerList.size()==2){
  255.             msg.type=15;
  256.             try{
  257.                 pps.selfSocket.out.writeObject(msg);
  258.                 ppd.selfSocket.out.writeObject(msg);
  259.             }catch(IOException e){
  260.                 e.printStackTrace();
  261.             }
  262.         }
  263.         Server.playerList.remove(pps);
  264.         Server.playerList.remove(ppd);
  265.         //System.out.println(" after create a group,playerlist size  = "+Server.playerList.size());
  266.         updateClient();
  267.     }
  268.     /**
  269.      * update client List when new group create or player left
  270.      */
  271.     public void updateClient(){
  272.         Message msg = new Message();
  273.         Player pp = null,ppm = null;
  274.         for(int i=0;i<Server.playerList.size();i++){
  275.             pp = (Player)Server.playerList.get(i);
  276.             msg.type=15;   //update client player list box
  277.             try{  //clear client list box
  278.    //             System.out.println("clear "+pp.self+"'s list box");
  279.                 pp.selfSocket.out.writeObject(msg);
  280.             }catch(IOException e){
  281.                 e.printStackTrace();
  282.             }
  283.             for(int j=0;j<Server.playerList.size();j++){
  284.                 ppm=(Player)Server.playerList.get(j);
  285.                 strToCharArray(ppm.self,msg.msg);
  286.                 msg.type=9;
  287.                 try{
  288.                     //System.out.println("updating ..."+pp.self+" list box about"+ppm.self);
  289.                     pp.selfSocket.out.writeObject(msg);
  290.                 }catch(IOException e){
  291.                     e.printStackTrace();
  292.                 }
  293.             }
  294.         }
  295.         // later ,group player 's list box will be updateed here
  296.     }
  297.     /**
  298.      * judge whether arr[] is equal to str
  299.      * @param arr
  300.      * @param str
  301.      * @return
  302.      */
  303.     private boolean arrayMatchString(char []arr,String str){
  304.         for(int i=0; i<50 && str.charAt(i)!='';i++){
  305.             if(arr[i]!=str.charAt(i))
  306.                 return false;
  307.         }
  308.         return true;
  309.     }
  310.     /**
  311.      * type ==3
  312.      * @param msg
  313.      */
  314.     public void requestAnother(Message msg){
  315.         Player pp = null;  // receiver
  316.         Player spp = null; // sender
  317.         String senderName=null;
  318.         // get sender's name
  319.         for(int i=0;i<Server.playerList.size();i++){
  320.             spp = (Player)Server.playerList.get(i);
  321.             if(this.equals(spp.selfSocket)==true){
  322.                 senderName = new String(spp.self);
  323.                 //System.out.println("requestor 's name = "+senderName);
  324.                 break;
  325.             }
  326.         }
  327.         for(int i=0;i<Server.playerList.size();i++){
  328.             pp = (Player)Server.playerList.get(i);
  329.             if(arrayMatchString(msg.msg,pp.self)==true){
  330.                 Message ms = new Message();
  331.                 strToCharArray(senderName,ms.msg);
  332.                 ms.type=3;
  333.                 if(spp.color==1){
  334.                     ms.color = 2; //set another's color
  335.                 }
  336.                 else{
  337.                     ms.color = 1;
  338.                 }
  339.                 ms.setting=spp.setting;
  340.                 try{// player B socket send msg to B's Client
  341.                     pp.selfSocket.out.writeObject(ms);
  342.                     //System.out.println("type= "+ms.type+"  "+pp.self+ " send msg to name = "+ms.msg[0]+"with B's color"+ms.color);
  343.                 }catch(IOException er){
  344.                     er.printStackTrace();
  345.                 }
  346.                 break;
  347.             }
  348.         }
  349.     }
  350.     // convert string to array which is end with ''
  351.     public void strToCharArray(String str,char [] arr){
  352.         int i=0;
  353.         for(i=0;i<str.length()&&i<49;i++){
  354.             arr[i] = str.charAt(i);
  355.         }
  356.         arr[i]='';
  357.     }
  358.     /**
  359.      * setting information flag
  360.      * @param msg
  361.      */
  362.     public void setting(Message msg,boolean flag){
  363.         int i=0;
  364.         Player pp=null;
  365.         for(i=0;i<Server.playerList.size();i++){
  366.             pp =(Player) Server.playerList.get(i);
  367.             if(this.equals(pp.selfSocket)==true){
  368.                 if(flag==true)
  369.                     pp.setting=msg.setting;
  370.                 else
  371.                     pp.color=msg.color;
  372.                 //System.out.println("setting "+pp.setting+"color = "+pp.color);
  373.             }
  374.         }
  375.     }
  376.     /**
  377.      * filter array 's black space which is end of the array
  378.      * @param arr
  379.      * @param str
  380.      */
  381.     public String arrayToString(char [] arr){
  382.         int i=0,length=0;
  383.         while(arr[i]!='' && i<50){
  384.             i++;
  385.         }
  386.         length=i;
  387.         char [] ss = new char[length];
  388.         for(i=0;i<length;i++){
  389.             ss[i]=arr[i];
  390.         }
  391.         String str = new String(ss);
  392.         return str;
  393.         //System.out.println("arraytoString "+str+"length = "+length);
  394.     }
  395.     /**
  396.      * add new player to all client's Player List
  397.      * ... read server player list and send msg to everyone of them
  398.      * @param player
  399.      */
  400.     public void sendNewPlayer(Message player){
  401.         Player pp=null;
  402.         player.type=9;
  403. //        System.out.println("send new Player ...");
  404.         for(int i=0;i<Server.playerList.size();i++){
  405.             pp=(Player)Server.playerList.get(i);
  406.             try{
  407.                 if(pp.self!=null){//send message to all but itself
  408.                     //System.out.println(pp.self+" add list "+player.msg[0]+"i = "+i);
  409.                     pp.selfSocket.out.writeObject(player);
  410.                 }
  411.             }catch(IOException e){
  412.                 e.printStackTrace();
  413.             }
  414.         }
  415.     }
  416.     /**
  417.      * a player end a game and wait for a new one
  418.      * @param msg
  419.      */
  420.     public void playerRefresh(Message player){
  421.         Player ppo = new Player();
  422.         Player pp = null;
  423.         ppo.color = player.color;
  424.         ppo.self = new String(player.msg);
  425.         ppo.selfSocket = this;
  426.         Server.playerList.add(ppo);
  427.         for(int i=0;i<Server.playerList.size();i++){
  428.             pp = (Player)Server.playerList.get(i);
  429.             if(this.equals(pp.selfSocket)==false){
  430.                 Message msg = new Message();
  431.                 strToCharArray(pp.self, msg.msg);
  432.                 msg.type = 9;
  433.                 msg.color = pp.color;
  434. //                System.out.println("refresh " + pp.self + "serverlist size " +
  435.   //                                 Server.playerList.size());
  436.                 try {
  437.                     this.out.writeObject(msg);
  438.                 }
  439.                 catch (IOException e) {
  440.                     e.printStackTrace();
  441.                 }
  442.             }
  443.         }
  444.         Message ms = new Message();
  445.         strToCharArray(ppo.self, ms.msg);
  446.         ms.type=10;
  447.         try{
  448.             this.out.writeObject(ms);
  449.         }catch(IOException e){
  450.             e.printStackTrace();
  451.         }
  452.         //Message ms = new Message();
  453.         player.type=10;
  454.         for(int i=0 ;i<Server.playerList.size();i++){
  455.             pp = (Player)Server.playerList.get(i);
  456.             if(this.equals(pp.selfSocket)!=true){
  457.                 try{
  458.                     pp.selfSocket.out.writeObject(player);
  459.                 }catch(IOException e){
  460.                     e.printStackTrace();
  461.                 }
  462.             }
  463.         }
  464.     }
  465.     /**
  466.      * add the new player to server playerList
  467.      * @param player
  468.      */
  469.     public void addPlayer(Message player){
  470.         int i=0;
  471.         Player pp=null,tp=null;
  472.         for(i=0;i<Server.playerList.size();i++){
  473.             pp=(Player)Server.playerList.get(i);
  474.             if(this.equals(pp.selfSocket)==true){
  475.                 //System.out.println("match socket ok and send to itself...");
  476.                 pp.self = new String(player.msg);
  477.                 try{
  478.                     for (int j = 0; j < Server.playerList.size(); j++) {
  479.                         Message temp = new Message();
  480.                         tp = (Player) Server.playerList.get(j);
  481.                         if (tp.self != null) {
  482.                             strToCharArray(tp.self, temp.msg);
  483.                             //temp.coordinateX=(byte)j;
  484.                             temp.type = 10; //reply for type==1
  485.                             //System.out.println("host "+pp.self+" add list to client name = "+temp.coordinateX+temp.msg[0]);
  486.                             pp.selfSocket.out.writeObject(temp);
  487.                         }
  488.                     }
  489.                    // out.writeObject(player);
  490.                 }catch(IOException e){
  491.                     e.printStackTrace();
  492.                 }
  493.                 break;
  494.             }
  495.         }/*
  496.         System.out.print("welcome ");
  497.         int k=0;
  498.         while(true){
  499.             if(player.msg[k]!='')
  500.                 System.out.print(player.msg[k++]);
  501.             else break;
  502.         }
  503.         System.out.println();*/
  504.         //System.out.println(" at "+pp.selfSocket.socket.toString());
  505.     }
  506.     public Socket getSocket(){
  507.         return socket;
  508.     }
  509.     /**
  510.      * check whether msg sender is win
  511.      * type=6 msg = winner 's name
  512.      * @param msg
  513.      */
  514.     public void checkVictory(Message msg){
  515.     }
  516.     /**
  517.      * type = 2 ,(msg.coordinateX,msg.coordinateY).msg.color
  518.      * @param msg
  519.      */
  520.     public void putChessman(Message msg){
  521.         Group gg = new Group();
  522.         ServeOneClient soc=null;
  523.         String tName=null;
  524.         int color=0;
  525.         // modify server board
  526.         for(int i=0;i<Server.groupList.size();i++){
  527.             gg = (Group)Server.groupList.get(i);
  528.             if(this.equals(gg.selfSocket)==true){
  529.                 soc = gg.playerSocket;
  530.                 tName = new String(gg.player);
  531.                 color = gg.selfColor;
  532.                 break;
  533.             }
  534.             if(this.equals(gg.playerSocket)==true){
  535.                 soc = gg.selfSocket;
  536.                 tName = new String(gg.self);
  537.                 color = gg.playerColor;
  538.                 break;
  539.             }
  540.         }
  541.         gg.board[msg.coordinateX][msg.coordinateY]=color;
  542.         // whether someone win the game
  543.         if(judge(gg,msg.coordinateX,msg.coordinateY)==true){// a man win
  544.             // tell the two and remove them form the group list
  545.             try{
  546.                 msg.type=6;  // win the game
  547.                 this.out.writeObject(msg);// tell this ,he win the game
  548.                 msg.type=17; // failed in the game
  549.                 soc.out.writeObject(msg); // tell soc ,he failed
  550. //                System.out.println("send failed to "+tName);
  551.             }catch(IOException e){
  552.                 e.printStackTrace();
  553.             }
  554.             Server.groupList.remove(gg); // remove from list
  555.             return;
  556.         }
  557.         // send msg to another player
  558.         try{
  559.             //System.out.println("server put chess man "+msg.coordinateX+","+msg.coordinateY);
  560.             soc.out.writeObject(msg);
  561.         }catch(IOException e){
  562.             e.printStackTrace();
  563.         }
  564.     }
  565.     /**
  566.      * judge if a man win the game
  567.      * @param gg a group for judge
  568.      * @param x  the newest kid's x coordinate
  569.      * @param y  the newest kid's y coordinate
  570.      * @return
  571.      */
  572.     private boolean judge(Group gg,int x,int y){
  573.         int i = 0, j = 0, count = 0;
  574.         int color=gg.board[x][y];
  575.         // x direction
  576.         for (i = 0, count = 0; x - i >= 0 && i < 5; i++) {
  577.             if (color == gg.board[x - i][y]) {
  578.                 count++;
  579.             }
  580.             else {
  581.                 break;
  582.             }
  583. //          System.out.println("( "+x+" , "+y+" )"+"count = "+count);
  584.             if (count == 5)
  585.                 return true;
  586.         }
  587.         for (i = 1; x + i < 15 && i < 5; i++) {
  588.             if (color == gg.board[x + i][y]) {
  589.                 count++;
  590.             }
  591.             else {
  592.                 break;
  593.             }
  594.             if (count == 5)
  595.                 return true;
  596.         }
  597.         // y direction
  598.         for (i = 0, count = 0; y - i >= 0 && i < 5; i++) {
  599.             if (color == gg.board[x][y - i]) {
  600.                 count++;
  601.             }
  602.             else {
  603.                 break;
  604.             }
  605. //            System.out.println("( "+x+" , "+y+" )"+"count = "+count);
  606.             if (count == 5)
  607.                 return true;
  608.         }
  609.         for (i = 1; y + i < 15 && i < 5; i++) {
  610.             if (color == gg.board[x][y + i]) {
  611.                 count++;
  612.             }
  613.             else {
  614.                 break;
  615.             }
  616. //        System.out.println("( "+x+" , "+y+" )"+"count = "+count);
  617.             if (count == 5)
  618.                 return true;
  619.         }
  620.         // '' direction
  621.         for (i = 0, count = 0; x - i >= 0 && y - i >= 0 && i < 5; i++) {
  622.             if (color == gg.board[x - i][y - i]) {
  623.                 count++;
  624.             }
  625.             else {
  626.                 break;
  627.             }
  628. //            System.out.println("( "+x+" , "+y+" )"+"count = "+count);
  629.             if (count == 5)
  630.                 return true;
  631.         }
  632.         for (i = 1; x + i < 15 && y + i < 15 && i < 5; i++) {
  633.             if (color == gg.board[x + i][y + i]) {
  634.                 count++;
  635.             }
  636.             else {
  637.                 break;
  638.             }
  639. //          System.out.println("( "+x+" , "+y+" )"+"count = "+count);
  640.             if (count == 5) {
  641.                 return true;
  642.             }
  643.         }
  644.         // '/' direction
  645.         for (i = 0, count = 0; x + i < 15 && y - i >= 0 && i < 5; i++) {
  646.             if (color == gg.board[x + i][y - i]) {
  647.                 count++;
  648.             }
  649.             else {
  650.                 count = 0;
  651.             }
  652. //          System.out.println("( "+x+" , "+y+" )"+"count = "+count);
  653.             if (count == 5)
  654.                 return true;
  655.         }
  656.         for (i = 1; x - i >= 0 && y + i < 15 && i < 5; i++) {
  657.             if (color == gg.board[x - i][y + i]) {
  658.                 count++;
  659.             }
  660.             else {
  661.                 break;
  662.             }
  663. //            System.out.println("( "+x+" , "+y+" )"+"count = "+count);
  664.             if (count == 5) {
  665.                 return true;
  666.             }
  667.         }
  668.         return false;
  669.     }
  670.     /**
  671.      * judge if a man win the game
  672.      * @param gg a group for judge
  673.      * @param x  the newest kid's x coordinate
  674.      * @param y  the newest kid's y coordinate
  675.      * @return
  676.      */
  677. /*    private boolean judge(Group gg,int x,int y){
  678.         int borderX=0,borderY=0,counter=0,i=0;
  679.         int color=gg.board[x][y];
  680.         if(x-4<0)            borderX=0;
  681.         else            borderX=x-4;
  682.         if(y-4<0)            borderY=0;
  683.         else            borderY=y-4;
  684.         // x direction
  685.         while(borderX+i<x+5 && borderX+i<15){
  686.             if(color==gg.board[borderX+i][y]){
  687.                 counter++;
  688.             }else{
  689.                 counter=0;
  690.             }
  691.             i++;
  692.             if(counter==5){
  693. //                System.out.println("color "+color+gg.board[borderX+i][y]+"return form x "+(borderX+i)+","+y+"x,y"+x+","+y);
  694.                 return true;
  695.             }
  696.         }
  697.         // y direction
  698.         i=0;counter=0;
  699.         while(borderY+i<y+5 && borderY+i<15){
  700.             if(color==gg.board[x][borderY+i]){
  701.                 counter++;
  702.             }else{
  703.                 counter=0;
  704.             }
  705.             i++;
  706.             if(counter==5){
  707. //                System.out.println("color "+color+gg.board[x][borderY+i]+"return form y "+x+","+(borderY+i)+","+y+"x,y"+x+","+y);
  708.                 return true;
  709.             }
  710.         }
  711.         // '' direction
  712.         if(borderX>borderY)
  713.             borderX = x-(y-borderY);
  714.         else
  715.             borderY = y-(x-borderX);
  716.         i=0;counter=0;
  717.         while(borderX+i<x+5 && borderY+i<y+5 && borderY+i<15&&borderX+i<15){
  718.             if(color==gg.board[borderX+i][borderY+i]){
  719. //                System.out.println("coordinate  \  "+(borderX+i)+","+(borderY+i)+","+y+"x,y"+x+","+y);
  720.                 counter++;
  721.             }else{
  722.                 counter=0;
  723.             }
  724.             i++;
  725.             if(counter==5){
  726. //                System.out.println("return form  \  "+(borderX+i)+","+(borderY+i)+","+y+"x,y"+x+","+y);
  727.                 return true;
  728.             }
  729.         }
  730.         // '/' direction
  731.         if(x+4>=15){
  732.             borderX = 14;
  733.         }
  734.         else{
  735.             borderX = x+4;
  736.         }
  737.         if(borderX-x<y-borderY){
  738.             borderY = y - (borderX - x);
  739.         }
  740.         else{
  741.             borderX = x + (y - borderY);
  742.         }
  743.         i=0;counter=0;
  744.         while(borderX-i>x-5 && borderY+i<y+5 && borderX-i>=0 && borderY+i<15){
  745.             if(color==gg.board[borderX-i][borderY+i]){
  746.                 counter++;
  747.             }else{
  748.                 counter=0;
  749.             }
  750.             i++;
  751.             if(counter==5){
  752. //                System.out.println("color "+color+gg.board[borderX-i][borderY+i]+"return form '/'   "+(borderX-i)+","+(borderY+i)+","+y+"x,y"+x+","+y);
  753.                 return true;
  754.             }
  755.         }
  756.         return false;
  757.     }
  758. */
  759. } ///:-)