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

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

?? boardpanel.java

?? 用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一区二区三区免费野_久草精品视频
91美女在线看| 国产黑丝在线一区二区三区| 日本道色综合久久| 国产精品福利电影一区二区三区四区| 精品无人码麻豆乱码1区2区 | aaa亚洲精品| 国产精品超碰97尤物18| 91免费观看国产| 亚洲国产综合在线| 日韩一区二区高清| 黄色小说综合网站| 国产精品高潮呻吟| 欧美视频一区二区三区四区 | 国内精品自线一区二区三区视频| 精品成人a区在线观看| 成人午夜精品在线| 亚洲一区二区三区三| 欧美一区二区三区成人| 国产成人在线视频免费播放| 国产精品麻豆99久久久久久| 在线看国产一区二区| 日韩成人一区二区三区在线观看| 精品国产乱子伦一区| 99re这里只有精品视频首页| 亚洲国产欧美日韩另类综合| 日韩一级片网址| 成人黄色网址在线观看| 五月天精品一区二区三区| 精品国产乱码久久久久久久久| 不卡视频一二三| 日本免费在线视频不卡一不卡二| 久久久久久97三级| 欧美日韩卡一卡二| 国产sm精品调教视频网站| 亚洲图片一区二区| 日本一区二区三区四区| 欧美视频一二三区| 国产aⅴ综合色| 日韩精品免费专区| 一区在线观看视频| 精品对白一区国产伦| 一本色道**综合亚洲精品蜜桃冫 | 亚洲一二三四区| 亚洲精品一区二区精华| 在线国产电影不卡| 风间由美性色一区二区三区| 日韩精品亚洲一区二区三区免费| 国产精品毛片高清在线完整版| 8v天堂国产在线一区二区| 国产精品一区2区| 日本怡春院一区二区| 一区二区在线观看视频| 欧美高清一级片在线观看| 欧美一区2区视频在线观看| 一本一本大道香蕉久在线精品 | www.成人网.com| 日本不卡一区二区| 亚洲电影在线免费观看| 亚洲精品久久久蜜桃| 国产精品水嫩水嫩| 国产色爱av资源综合区| 日韩精品一区二区三区视频| 91精品国模一区二区三区| 欧美这里有精品| 91网站最新地址| 91一区一区三区| 成人黄色大片在线观看| 国产成人亚洲综合a∨婷婷图片| 日韩中文欧美在线| 日韩高清不卡一区二区三区| 亚洲成人免费视| 亚洲一区在线视频观看| 一区二区三区四区在线播放 | 欧美一区二区三区小说| 欧美影院午夜播放| 日本精品视频一区二区| 91蜜桃传媒精品久久久一区二区| 成人精品国产一区二区4080| 国产成人精品亚洲777人妖| 久久99久久99| 黑人巨大精品欧美黑白配亚洲| 美女一区二区视频| 麻豆中文一区二区| 精品无码三级在线观看视频| 老鸭窝一区二区久久精品| 日本在线不卡一区| 精东粉嫩av免费一区二区三区| 精品亚洲国产成人av制服丝袜| 国内精品久久久久影院薰衣草| 国内精品不卡在线| 丰满亚洲少妇av| 日本高清免费不卡视频| 欧美美女激情18p| 日韩精品一区二区三区蜜臀 | 在线播放中文一区| 日韩欧美国产精品一区| 久久视频一区二区| 日本一区二区三区国色天香| 亚洲天堂免费在线观看视频| 亚洲男同1069视频| 日韩激情在线观看| 国内成人精品2018免费看| 福利电影一区二区三区| 91极品视觉盛宴| 日韩亚洲国产中文字幕欧美| 久久精品视频免费| 亚洲激情图片一区| 狠狠狠色丁香婷婷综合久久五月| 国产a精品视频| 欧美日韩综合色| 久久久亚洲国产美女国产盗摄 | 成人免费视频caoporn| 色婷婷av一区二区三区gif| 91麻豆精品国产综合久久久久久| 精品国产凹凸成av人网站| 国产精品久久福利| 偷拍一区二区三区| 东方欧美亚洲色图在线| 欧美日韩精品久久久| 精品sm捆绑视频| 亚洲欧美国产三级| 久久99久久99| 欧美午夜免费电影| 国产调教视频一区| 丝袜美腿成人在线| 97超碰欧美中文字幕| 欧美不卡一区二区| 一区二区三区精品| 成人午夜私人影院| 欧美一区二区三区四区在线观看 | 久久午夜免费电影| 午夜激情一区二区| av福利精品导航| 久久五月婷婷丁香社区| 午夜精品久久久久久久久久| 成人午夜电影久久影院| 日韩精品中文字幕一区| 亚洲一区二区三区四区的 | 精品一区二区综合| 91黄色免费看| 中文字幕中文字幕中文字幕亚洲无线| 美女视频免费一区| 欧美日本在线观看| 一区二区三区鲁丝不卡| 成人h动漫精品一区二区| 精品日韩av一区二区| 五月天激情小说综合| 在线视频你懂得一区| 国产精品私人自拍| 福利视频网站一区二区三区| 久久综合久久综合九色| 免费的国产精品| 欧美日韩国产一区| 亚洲综合图片区| 一本到不卡免费一区二区| 中文字幕乱码日本亚洲一区二区 | 蜜桃视频一区二区三区在线观看| 日本久久精品电影| 亚洲精品视频免费观看| 99热这里都是精品| 中文字幕在线一区二区三区| 高清在线不卡av| 久久精品一区八戒影视| 国产一区二区免费在线| 精品久久久三级丝袜| 久久精品国产**网站演员| 日韩视频在线永久播放| 美女性感视频久久| 日韩欧美一二三| 美女www一区二区| 精品久久久久久久一区二区蜜臀| 看电影不卡的网站| 久久综合国产精品| 国产激情一区二区三区四区| 国产午夜久久久久| 成人免费毛片app| 一区二区三区四区亚洲| 欧美日韩亚州综合| 日韩国产精品91| 精品福利av导航| 丁香桃色午夜亚洲一区二区三区| 国产丝袜欧美中文另类| 99久久精品久久久久久清纯| 国产精品超碰97尤物18| 欧美日韩精品一区二区三区蜜桃| 欧美aaa在线| 国产欧美日韩不卡| 在线日韩av片| 毛片基地黄久久久久久天堂| 精品国产伦一区二区三区观看方式| 国产高清成人在线| 亚洲人快播电影网| 666欧美在线视频| 精品一区二区在线视频| 国产精品美女视频| 欧美性猛交一区二区三区精品| 日韩高清中文字幕一区| 久久久精品日韩欧美| 一本久久综合亚洲鲁鲁五月天| 水野朝阳av一区二区三区|