亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? boardpanel.java

?? 這是一個用java編寫的網絡對戰五子棋程序
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
import java.awt.*;
import java.awt.event.*;
import java.util.Arrays;
import javax.swing.*;
import java.io.*;

/**
 * <p>Title: chesser</p>
 * <p>Description: wu zi qi game</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: e-top</p>
 * @author cylix
 * @version 1.0
 */

public class BoardPanel extends JPanel{
    private  static Image white = null;
    private  static Image black = null;
    private static int xp;           // position of x to put chessman
    private static int yp;           // position of y to put chessman
    private Cursor handCursor;
    private Cursor defaultCursor;
    protected static int board[][];    // record of each position black or white
    private int color=1;             // record player's chess color 1=black 2=white    
    
    int STEPCOUNTER=0;
    int BASE=5;
    int DEEPTH=3;
    int MINDEEPTH=3;
    int MAX1=5;
    long INVALID=9000000;
    int chessBoard[][];    

    // draw the line number with x/y direction
    String line = "a        b        c       d        e        f        g        h         i         j        k         l        m       n        o";
    char [] rowNum1 = {'1','2','3','4','5','6','7','8','9'};
    char [] rowNum2={'1','0','1','1','1','2','1','3','1','4','1','5'};

     public BoardPanel(){
//        this.wzq=wz;
        try {
            handCursor=new Cursor(12);
            defaultCursor = new Cursor(0);
            board = new int[15][15];
//            black = wzq.black;
//            white = wzq.white;

          //  this.setBackground(Color.yellow);
            //this.setForeground(Color.BLUE);
          //  this.setBorder(BorderFactory.createLoweredBevelBorder());

            jbInit();
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }

    public void paint(Graphics gc){
        super.paint(gc);
        //this.setBackground(Color.gray);
        //this.invalidate();
        gc.setColor(Color.blue);
        //gc.setColor(new Color(255, 255, 240));
        // draw number of X direction
        gc.drawString(line,25,15);
        // draw number of Y direction
        for(int i=0;i<9;i++){
            gc.drawChars(rowNum1,i,1,10,35+i*30);
        }
        for(int i=9,j=0;i<15;i++,j+=2){
            gc.drawChars(rowNum2,j,2,10,35+i*30);
        }
        // draw the chess board
        for (int i = 0; i < 15; i++) {
            gc.drawLine(30, 30 + i * 30, 450, 30 + i * 30); //draw raw
            gc.drawLine(30 + i * 30, 30, 30 + i * 30, 450); //draw column
        }
        gc.drawLine(25, 25, 455, 25);
        gc.drawLine(25, 25, 25, 455);
        gc.drawLine(25, 455, 455, 455);
        gc.drawLine(455, 25, 455, 455);

        //when window repaint to replay the original status of board
        for(int i=0;i<15;i++){
            for (int j = 0; j < 15; j++) {
                xp=16+i*30;
                yp=16+j*30;
                if (board[i][j] == 1){
                    gc.setColor(Color.black);
                    gc.fillOval(xp,yp,28,28);
                    //gc.drawImage(black, 16 + i * 30, 16 + j * 30, this);
                }
                if (board[i][j] == 2){
                    gc.setColor(Color.white);
                    gc.fillOval(xp,yp,28,28);
                    //gc.drawImage(white, 16 + i * 30, 16 + j * 30, this);
                }
            }
        }
    }

    private void jbInit() throws Exception {
        this.addMouseMotionListener(new ChessWZQ_this_mouseMotionAdapter(this));
        this.addMouseListener(new ChessWZQ_this_mouseAdapter(this));
    }
    public int getColor(){
        return color;
    }
    public void setColor(int cr){
        color=cr;
    }
    /**
     * clear board when updated
     */
    public void clearBoard(){
        for(int i=0;i<15;i++){
            for(int j=0;j<15;j++)
                board[i][j]=0;
        }
        repaint();
    }

    void this_mouseClicked(MouseEvent e) {
        int x=0,y=0;
        if(color==0){
            return;
        }
        x=e.getX();
        y=e.getY();
        if(x>20&&x<460&&y>20&&y<460&&(x%30<10||x%30>20)&&(y%30<10||y%30>20)){
            if(ChessWZQ.beginFlag==false){
                ChessWZQ.label6.setText("You may not do that");
                return;
            }
            xp = x / 30 * 30 - 14;
            yp = y / 30 * 30 - 14;
            if (x % 30 > 20) {
                xp += 30;
            }
            if (y % 30 > 20) {
                yp += 30;
            }
            x=xp/30;y=yp/30;
            if(board[x][y]!=0){
                return;
            }
            // client 's board
            board[xp / 30][yp / 30] = color;

            Graphics g=this.getGraphics();
            if(color==1){//black
                g.setColor(Color.black);
            }
            if(color==2){//white
                g.setColor(Color.white);
            }
            g.fillOval(xp, yp, 28, 28);

            ChessWZQ.beginFlag=false;

            // setting coordinate (x,y)
//            x=xp/30;y=yp/30;
            if(ChessWZQ.ptocFlag==false){
                Message msg = new Message();
                msg.color = color;
                msg.coordinateX = x;
                msg.coordinateY = y;
                msg.type = 2; //press chessman

                //send message to server
                try {
                    ChessWZQ.out.writeObject(msg);
                }
                catch (IOException ee) {
                    ee.printStackTrace();
                }
            }
           char cc = (char)(x+65);
           ChessWZQ.label6.setText("put on ( "+cc+" , "+(y+1)+" )");
           /// computer to put
           if(ChessWZQ.ptocFlag==true){
               if(judge(xp/30,yp/30,color)==true){
                   //System.out.println("people win");
                   Message ms = new Message();
                   ms.type=20;
                   strToCharArray("You",ms.msg);
                   try{
                       ChessWZQ.out.writeObject(ms);
                   }catch(IOException er){
                       er.printStackTrace();
                   }
               }
               ChessWZQ.beginFlag = false;
               int position = 0, bestX = 0, bestY = 0;
               Analyse aa = new Analyse(BoardPanel.board);
               position = aa.computerDo();
               bestY = position % 100 - 1;
               bestX = position / 100 - 1;
               updateBoard(bestX, bestY);
               drawChess(bestX, bestY);
               ChessWZQ.beginFlag = true; //for people to put
               cc=(char)(bestX+65);
               ChessWZQ.label6.setText("put on ( "+cc+" , "+(bestY+1)+" )");
               if(judge(bestX,bestY,ChessWZQ.cColor)==true){
                   //System.out.println("computer win");
                   Message msg = new Message();
                   msg.type=20;
                   strToCharArray("Computer",msg.msg);
                   try{
                       ChessWZQ.out.writeObject(msg);
                   }catch(IOException err){
                       err.printStackTrace();
                   }
               }
           }
        }
    }
    // convert string to array which is end with '\0'
    public void strToCharArray(String str,char [] arr){
        int i;
        for(i=0;i<str.length()&&i<49;i++){
            arr[i] = str.charAt(i);
        }
        arr[i]='\0';
    }

    /**
     * return the chessman's x coordinate  0<=x<15
     * @return
     */
    protected int getXP(){
        return xp/30;
    }
    protected int getYP(){
        return yp/30;
    }
    /**
     * put a chessman and display it (x,y) position on the panel
     * draw chessman on (x,y)
     * @param x
     * @param y
     */
    public void drawChess(int x,int y){
        Graphics g=this.getGraphics();
        char cc = (char)(x+65);
        int temp = y+1;
        x=x*30+16;
        y=y*30+16;
        if(color==1)
            g.setColor(Color.white);
        else
            g.setColor(Color.black);
        g.fillOval(x, y, 28, 28);
        ChessWZQ.label6.setText("Player put on ( "+cc+" , "+temp+" )");
    }
    /**
     * update board status when B put a chessman
     * @param x B's chessman's X coordinate 0<=x<15
     * @param y B's chessman's Y coordinate 0<=y<15
     */
    public void updateBoard(int x,int y){
        int tcolor=0;
        if(color==1) tcolor=2;
        else tcolor=1;
        board[x][y]=tcolor;
    }

    public char intToChar(int x){
        char temp='\0';
        if(x>=0&&x<=9)
            temp=(char)(48+x);
        else if(x>=10 &&x<=15){
            temp=(char)(55+x);
        }
        return temp;
    }

    /**
     * mouseMoved Event
     * @param e
     */
    void this_mouseMoved(MouseEvent e) {
        int x=0,y=0;
        x=e.getX();
        y=e.getY();
        if(x>20&&x<460&&y>20&&y<460&&(x%30<10||x%30>20)&&(y%30<10||y%30>20)){
            this.setCursor(handCursor); //HAND_CURSOR
        }
        else{
            this.setCursor(defaultCursor);
        }
    }
    /**
     * judge if a man win the game
     * @param x  the newest kid's x coordinate
     * @param y  the newest kid's y coordinate
     * @return
     */
    protected boolean judge(int x,int y,int clr){
        int i=0,j=0,count=0;
        // x direction
        for(i=0,count=0;x-i>=0&&i<5;i++){
            if (clr==board[x-i][y]){
                count++;
            }else{
                break;
            }
  //          System.out.println("( "+x+" , "+y+" )"+"count = "+count);
            if(count==5)
                return true;
        }
        for(i=1;x+i<15&&i<5;i++){
            if(clr==board[x+i][y]){
                count++;
            }else{
                break;
            }
            if(count==5)
                return true;
        }
        // y direction
        for(i=0,count=0;y-i>=0&&i<5;i++){
            if (clr==board[x][y-i]){
                count++;
            }else{
                break;
            }
//            System.out.println("( "+x+" , "+y+" )"+"count = "+count);
            if(count==5)
                return true;
        }
        for(i=1;y+i<15&&i<5;i++){
            if(clr==board[x][y+i]){
                count++;
            }else{
                break;
            }
    //        System.out.println("( "+x+" , "+y+" )"+"count = "+count);
            if(count==5)
                return true;
        }
        // '\' direction
        for(i=0,count=0;x-i>=0&&y-i>=0&&i<5;i++){
            if(clr==board[x-i][y-i]){
                count++;
            }else{
                break;
            }
//            System.out.println("( "+x+" , "+y+" )"+"count = "+count);
            if(count==5)
                return true;
        }
        for(i=1;x+i<15&&y+i<15&&i<5;i++){
            if(clr==board[x+i][y+i]){
                count++;
            }else{
                break;
            }
  //          System.out.println("( "+x+" , "+y+" )"+"count = "+count);
            if(count==5){
                return true;
            }
        }
        // '/' direction
        for(i=0,count=0;x+i<15 && y-i>=0 &&i<5; i++){
            if(clr==board[x+i][y-i]){
                count++;
            }else{
                count=0;
            }
  //          System.out.println("( "+x+" , "+y+" )"+"count = "+count);
            if(count==5)
                return true;
        }
        for(i=1;x-i>=0 && y+i<15 &&i<5;i++){
            if(clr==board[x-i][y+i]){
                count++;
            }else{
                break;
            }
//            System.out.println("( "+x+" , "+y+" )"+"count = "+count);
            if(count==5){
                return true;
            }
        }
        return false;
    }
    class Queue{
        int position;
        long mark;
    } ;
    
    class Analyse {
    
    Analyse(int chessc[][]){
        int i, j;
        chessBoard = new int[17][17];
        for (i = 0; i <= 16; i++) {
            for (j = 0; j <= 16; j++) {
                if (i == 0 || j == 0 || i == 16 || j == 16) {
                    chessBoard[i][j] = 4;
                }
                else {
                    chessBoard[i][j] = chessc[i - 1][j - 1];
                }
            }
        }
    }
    /**
     *
     * @param base
     * @param pow
     * @return
     */
    private long pow(int base, int pow){
       int i;
       long result=1;
       for(i=1;i<=pow;i++){
           result*=base;
       }
       return result;
   }
   /**
    *
    * @param x
    * @param y
    * @param side
    * @return
    */
   private long analyseUd(int x, int y, int side){
       int tt[][] = new int[17][17];
       int i, j;
       int tempx, tempy;
       long mark = 0;
       int base = BASE;
       int uppersign = 0;
       int downsign = 0;
       int c_count = 1;

       for (i = 0; i < 17; i++) {
           for (j = 0; j < 17; j++) {
               tt[i][j] = chessBoard[i][j];
           }
       }
       tt[y][x] = side;
      // up and down
       tempx = x;
       tempy = y;
       if (tt[tempy - 1][tempx] != side) {
           if (tt[tempy - 1][tempx] == 0) {
               uppersign = 1;
           }
           if (tt[tempy - 1][tempx] != 0) {
               uppersign = 0;
           }
       }
       else {
           tempy -= 1;
           while (tt[tempy][tempx] == side) {
               c_count += 1;
               tempy--;
           }
           if (tt[tempy][tempx] == 0) {
               uppersign = 1;
           }
           if (tt[tempy][tempx] != 0) {
               uppersign = 0;
           }
       }
       tempx = x;
       tempy = y;
       if (tt[tempy + 1][tempx] != side) {
           if (tt[tempy + 1][tempx] == 0) {
               downsign = 1;
           }
           if (tt[tempy + 1][tempx] != 0) {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
午夜精品一区二区三区电影天堂 | 成人性色生活片| 精品国产123| 国产一区二区三区最好精华液| 精品国产一区久久| 国产成人在线电影| 亚洲欧美视频在线观看| 欧美日韩高清一区二区| 久草这里只有精品视频| 日本一区二区三区久久久久久久久不| 丰满白嫩尤物一区二区| 依依成人精品视频| 91精品福利在线一区二区三区 | 国产一区二区三区四| 国产精品色一区二区三区| 在线观看国产精品网站| 美女网站色91| ●精品国产综合乱码久久久久| 欧美影视一区二区三区| 精品亚洲国内自在自线福利| 亚洲欧洲性图库| 337p亚洲精品色噜噜| 国产69精品久久99不卡| 亚洲成a人v欧美综合天堂| 精品美女在线播放| 色综合天天综合狠狠| 毛片基地黄久久久久久天堂| 国产精品福利电影一区二区三区四区| 欧洲生活片亚洲生活在线观看| 男女视频一区二区| 亚洲精品成a人| 久久久亚洲精品石原莉奈| 在线观看国产精品网站| 国产精品18久久久久| 午夜亚洲福利老司机| 日本一区二区成人| 欧美一区二区在线观看| 色综合色综合色综合色综合色综合| 免费观看日韩av| 一区二区三区国产精华| 久久久久久久久久看片| 欧美精品第1页| 99精品国产91久久久久久 | 一区二区三区久久| 337p粉嫩大胆噜噜噜噜噜91av| 欧美亚洲一区二区在线| 成人午夜激情片| 国产自产高清不卡| 日本亚洲欧美天堂免费| 亚洲一区二区三区国产| 国产精品区一区二区三区| 日韩欧美一区二区久久婷婷| 欧洲一区在线电影| 色综合亚洲欧洲| 成人黄色软件下载| 国产成人av一区二区三区在线| 免费在线观看不卡| 日韩国产精品久久久| 夜夜揉揉日日人人青青一国产精品| 国产精品久久久久久久岛一牛影视 | a美女胸又www黄视频久久| 国产在线观看一区二区| 美女mm1313爽爽久久久蜜臀| 日韩精品一二三| 亚洲第四色夜色| 亚洲色图色小说| 国产精品久久久久久久久快鸭| 国产欧美日韩精品a在线观看| 精品美女一区二区三区| 精品理论电影在线| 精品国产一区二区国模嫣然| 欧美一区二区三区婷婷月色| 欧美肥胖老妇做爰| 91精品国产黑色紧身裤美女| 欧美人狂配大交3d怪物一区| 欧美精品在欧美一区二区少妇| 欧美日韩精品免费| 欧美一区午夜视频在线观看| 日韩视频免费直播| 精品国产一区二区三区不卡 | 国产欧美一区二区在线| 国产女主播一区| 国产精品久久三| 亚洲视频小说图片| 亚洲精品国产无天堂网2021| 亚洲国产成人porn| 日韩av成人高清| 国产一区二区三区在线观看精品 | 精品成人a区在线观看| 久久综合狠狠综合| 国产精品久久久久久久久免费樱桃| 亚洲欧洲另类国产综合| 亚洲一区二区欧美激情| 麻豆精品一区二区| 国产91在线观看| 在线亚洲一区二区| 91精品免费观看| 日本一区二区三区久久久久久久久不| 国产精品久久精品日日| 亚洲影院理伦片| 精品在线观看视频| 91在线视频18| 欧美精品乱码久久久久久| 久久综合精品国产一区二区三区| 国产精品超碰97尤物18| 午夜国产不卡在线观看视频| 国内欧美视频一区二区 | 在线观看不卡视频| 欧美成人一级视频| 亚洲乱码国产乱码精品精98午夜| 香港成人在线视频| 懂色av噜噜一区二区三区av| 欧美亚洲综合久久| 久久久91精品国产一区二区精品| 亚洲美女在线一区| 国产在线播放一区| 欧美日韩一区久久| 国产精品视频看| 青青国产91久久久久久| k8久久久一区二区三区 | 欧美精品一级二级| 国产精品午夜免费| 琪琪一区二区三区| 色综合久久中文综合久久97| 欧美成人艳星乳罩| 亚洲国产一区二区三区青草影视 | 久久国产欧美日韩精品| 在线观看网站黄不卡| 久久精品视频网| 美国精品在线观看| 欧美日韩国产综合一区二区三区 | 欧美三区在线观看| 中文字幕免费观看一区| 秋霞午夜鲁丝一区二区老狼| 色狠狠一区二区三区香蕉| 欧美激情一区在线| 激情综合一区二区三区| 欧美怡红院视频| 亚洲免费资源在线播放| 成人成人成人在线视频| 精品免费视频.| 免费看欧美女人艹b| 精品视频一区二区不卡| 国产精品久久久久久久久免费桃花| 国内偷窥港台综合视频在线播放| 欧美精品丝袜中出| 午夜久久电影网| 欧美自拍偷拍一区| 亚洲永久免费av| 色综合久久中文综合久久牛| 中文字幕一区二区三区在线不卡 | 成人午夜在线免费| 久久影院午夜片一区| 久草精品在线观看| 2024国产精品| 国产黄色精品网站| 国产亚洲短视频| 国产综合久久久久久久久久久久| 欧美大片国产精品| 久久国产生活片100| 日韩欧美成人激情| 精品一区二区三区视频| 精品播放一区二区| 国产91露脸合集magnet| 国产精品三级久久久久三级| 成人性色生活片| 自拍av一区二区三区| 色综合久久99| 亚洲动漫第一页| 欧美肥大bbwbbw高潮| 琪琪久久久久日韩精品| 精品美女在线观看| 成人性生交大片免费看视频在线| 国产精品网站在线| 色婷婷综合在线| 亚洲aaa精品| 精品日韩一区二区三区| 国产高清精品久久久久| 国产精品电影一区二区| 在线亚洲免费视频| 蜜芽一区二区三区| 久久精品一区四区| 99re这里都是精品| 亚洲成人免费视频| 日韩精品一区二区三区视频在线观看 | 精品av久久707| 成人av动漫网站| 亚洲6080在线| 欧美精品一区二区三区蜜桃| 风间由美性色一区二区三区| 亚洲精选视频免费看| 欧美精品xxxxbbbb| 国产白丝网站精品污在线入口| 亚洲乱码日产精品bd| 337p亚洲精品色噜噜狠狠| 懂色av一区二区夜夜嗨| 午夜精品久久久久久久久久久| 精品国产免费视频| 91在线视频18| 欧日韩精品视频|