자바 2 인 오목 게임(6)행 바둑 방 변환 실현

29891 단어 Java오목
앞의 두 문장:자바,2 인 오목 게임 실현(2)바둑판 그리 기;자바 2 인 오목 게임 실현(3)바둑 알 그리 기자바 2 인 오목 게임(4)낙 자 동작의 실현,클릭 하여 볼 수 있 습 니 다.

앞에서 우 리 는 이미 바둑판 과 바둑 알 을 그 렸 고 자 유 롭 게 떨 어 질 수 있 으 며 바둑판 에 5 연주 가 있 는 지 판단 할 수 있다.다음 작업 은 매번 바둑 을 놓 은 후 바둑 을 두 는 쪽(곧 다음 바둑 의 색깔 은 흰색->검은색 또는 검은색->흰색)을 교환 하고,승 리 를 판단 하여 색깔 판단 조건 을 증가 시 키 는 것 이다(바둑판 에 5 연주 가 존재 한다->바둑판 에 같은 색 의 5 연주 가 존재 한다).

메 인 모듈 Main.java 와 바둑 알 류 Chessman.java 는 변 하지 않 습 니 다.Draw ChessBoard.java 의 낙 자 함수 mousePressed 와 5 연주 판단 함수 isWin 을 조정 해 야 합 니 다.
Main.java

package xchen.test.simpleGobang; 
 
import java.awt.Container; 
import javax.swing.JFrame; 
 
import xchen.test.simpleGobang.DrawChessBoard; 
 
public class Main extends JFrame{ 
  private DrawChessBoard drawChessBoard; 
  public Main() {    
    drawChessBoard = new DrawChessBoard(); 
     
    //Frame   
    setTitle("     "); 
     
    Container containerPane =getContentPane(); 
    containerPane.add(drawChessBoard);    
  } 
  public static void main(String[] args) { 
    Main m = new Main(); 
    m.setSize(800, 800); 
    m.setVisible(true); 
  } 
} 

Chessman.java

package xchen.test.simpleGobang; 
 
public class Chessman { 
  private int color;//1-white,0-black 
  private boolean placed = false; 
  int matchCount = 1; 
   
  public Chessman(int color,boolean placed){ 
    this.color=color; 
    this.placed=placed; 
  } 
   
  public boolean getPlaced() { 
    return placed; 
  } 
 
  public void setPlaced(boolean placed) { 
    this.placed = placed; 
  } 
 
  public int getColor() { 
    return color; 
  } 
 
  public void setColor(int color) { 
    this.color = color; 
  } 
} 
첫 번 째 단 계 는 mousePressed 함 수 를 수정 하여 매번 바둑 을 놓 은 후에 바둑 을 두 는 쪽 을 상대방 에 게 양보 합 니 다(즉,매번 바둑 을 놓 을 때마다 바둑 의 색깔 을 바 꿉 니 다).
DrawChessBoard.java 의 mousePressed 함수 부분 은 매번 chessColor 의 값 을 수정 하면 됩 니 다.

@Override 
//             
public void mousePressed(MouseEvent e) { 
  int point_x=e.getX(); 
  int point_y=e.getY(); 
 
  int imgWidth = boardImg.getHeight(this); 
  int imgHeight = boardImg.getWidth(this); 
  int FWidth = getWidth(); 
  int FHeight= getHeight(); 
 
  int x=(FWidth-imgWidth)/2; 
  int y=(FHeight-imgHeight)/2; 
 
  int span_x=imgWidth/ROWS; 
  int span_y=imgHeight/ROWS; 
 
  //System.out.println("press"); 
  int status_x = 0; 
  int status_y = 0; 
  if(point_x>=x && point_x<=x+imgWidth && point_y>=y && point_y <= y+imgHeight) 
  { 
    //System.out.println("  "); 
    for(int i=0;i<ROWS+1;i++) 
    { 
      if(point_x>=x-chessman_width/2+1+i*span_x) 
      { 
        if(point_x<=x+chessman_width/2-1+i*span_x)//   width/2             
        { 
          //System.out.println("point x "+i+" "+point_x+" "+(x-chessman_width/2+i*span_x)+" "+(x+chessman_width/2+i*span_x)); 
          status_x = i; 
        } 
      } 
    } 
    for(int i=0;i<ROWS+1;i++) 
    { 
      if(point_y>=y-chessman_width/2+1+i*span_y) 
      { 
        if(point_y <= y+chessman_width/2-1+i*span_y) 
        { 
          //System.out.println("point y "+i+" "+point_y+" "+(y-chessman_width/2+1+i*span_y)+" "+(y+chessman_width/2-1+i*span_y)); 
          status_y = i; 
        } 
      } 
    } 
     
    Chessman chessman = new Chessman(chessColor, true); 
    chessStatus[status_x][status_y]=chessman; 
    System.out.println("chess color:"+chessColor); 
    if(chessColor==BLACK) 
    { 
      chessColor = WHITE; 
    }else { 
      chessColor = BLACK; 
    } 
    repaint(); 
    if(isWin(status_x, status_y, chessStatus)) 
    { 
      System.out.println("WIN!!!!!"); 
    } 
  } 
} 
운행 하 다

두 번 째 단 계 는 승 리 를 판단 하여 색상 판단 조건 을 증가 시 킵 니 다(바둑판 에 5 연 주 를 존재 합 니 다->바둑판 에 같은 색 의 5 연 주 를 존재 합 니 다)
isWin 함수 의 판단 조건 에 Chessman.getColor 의 색상 판단 을 추가 합 니 다.
isWin 함수 코드

boolean isWin(int point_x,int point_y,Chessman[][] cm) 
{   
  for(int i=0;i<ROWS+1;i++) 
  { 
    for(int j=0;j<ROWS+1;j++) 
    { 
      //     
      if(chessStatus[i][j]!=null&&chessStatus[i][j].getPlaced()==true) 
      { 
        int matchColor = chessStatus[i][j].getColor(); 
        //      
        for(int n=1;n<=4;n++) 
        { 
          if((i+n>=0)&&(i+n)<=ROWS) 
          { 
            if(chessStatus[i+n][j]!=null&&chessStatus[i+n][j].getPlaced()==true&&chessStatus[i+n][j].getColor()==matchColor) 
            { 
              chessStatus[i][j].matchCount++; 
              System.out.println("pos:"+i+" "+j+" right count++:"+(i+n)+" "+j+" count:"+chessStatus[i][j].matchCount); 
              if(chessStatus[i][j].matchCount==5) 
              { 
                return true; 
              } 
            }else 
            { 
              break; 
            }   
          } 
        } 
        //      
        for(int n=1;n<=4;n++) 
        { 
          if((i-n>=0)&&(i-n)<=ROWS) 
          { 
            if(chessStatus[i-n][j]!=null&&chessStatus[i-n][j].getPlaced()==true&&chessStatus[i-n][j].getColor()==matchColor) 
            { 
              chessStatus[i][j].matchCount++; 
              System.out.println("pos:"+i+" "+j+" "+"left count++:"+(i-n)+" "+j+" count:"+chessStatus[i][j].matchCount); 
              if(chessStatus[i][j].matchCount==5) 
              { 
                return true; 
              } 
            }else 
            { 
              if(chessStatus[i-n][j]!=null) 
              { 
                chessStatus[i][j].matchCount = 1; 
              } 
              break; 
            } 
          } 
        } 
        chessStatus[i][j].matchCount=1;//refresh count 
      } 
    } 
  } 
 
  for(int i=0;i<ROWS+1;i++) 
  { 
    for(int j=0;j<ROWS+1;j++) 
    { 
      //   
      if(chessStatus[i][j]!=null&&chessStatus[i][j].getPlaced()==true) 
      { 
        int matchColor = chessStatus[i][j].getColor(); 
        //    ,        ,y       
        for(int n=1;n<=4;n++) 
        { 
          if((j+n>=0)&&(j+n)<=ROWS) 
          { 
            if(chessStatus[i][j+n]!=null&&chessStatus[i][j+n].getPlaced()==true&&chessStatus[i][j+n].getColor()==matchColor) 
            { 
              chessStatus[i][j].matchCount++; 
              System.out.println("pos:"+i+" "+j+" up count++:"+(i)+" "+(j+n)+" count:"+chessStatus[i][j].matchCount); 
              if(chessStatus[i][j].matchCount==5) 
              { 
                return true; 
              } 
            }else 
            { 
              break; 
            }   
          } 
        } 
        //     
        for(int n=1;n<=4;n++) 
        { 
          if((j-n>=0)&&(j-n)<=ROWS) 
          { 
            if(chessStatus[i][j-n]!=null&&chessStatus[i][j-n].getPlaced()==true&&chessStatus[i][j-n].getColor()==matchColor) 
            { 
              chessStatus[i][j].matchCount++; 
              System.out.println("pos:"+i+" "+j+" "+"left count++:"+(i)+" "+(j-n)+" count:"+chessStatus[i][j].matchCount); 
              if(chessStatus[i][j].matchCount==5) 
              { 
                return true; 
              } 
            }else 
            { 
              if(chessStatus[i][j-n]!=null) 
              { 
                chessStatus[i][j].matchCount = 1; 
              } 
              break; 
            } 
          } 
        } 
        chessStatus[i][j].matchCount=1;//refresh count 
      } 
    } 
  } 
 
  //  :     
  for(int i=0;i<ROWS+1;i++) 
  { 
    for(int j=0;j<ROWS+1;j++) 
    { 
      //   
      if(chessStatus[i][j]!=null&&chessStatus[i][j].getPlaced()==true) 
      { 
        int matchColor = chessStatus[i][j].getColor(); 
        //    ,        ,y       
        for(int n=1;n<=4;n++) 
        { 
          if((j-n>=0)&&(j-n)<=ROWS&&(i-n)>=0&&(i-n)<=ROWS) 
          { 
            if(chessStatus[i-n][j-n]!=null&&chessStatus[i-n][j-n].getPlaced()==true&&chessStatus[i-n][j-n].getColor()==matchColor) 
            { 
              chessStatus[i][j].matchCount++; 
              System.out.println("pos:"+i+" "+j+" up count++:"+(i-n)+" "+(j-n)+" count:"+chessStatus[i][j].matchCount); 
              if(chessStatus[i][j].matchCount==5) 
              { 
                return true; 
              } 
            }else 
            { 
              break; 
            }   
          } 
        } 
        //   
        for(int n=1;n<=4;n++) 
        { 
          if((j+n>=0)&&(j+n)<=ROWS&&(i+n)>=0&&(i+n)<=ROWS) 
          { 
            if(chessStatus[i+n][j+n]!=null&&chessStatus[i+n][j+n].getPlaced()==true&&chessStatus[i+n][j+n].getColor()==matchColor) 
            { 
              chessStatus[i][j].matchCount++; 
              System.out.println("pos:"+i+" "+j+" "+"left count++:"+(i+n)+" "+(j+n)+" count:"+chessStatus[i][j].matchCount); 
              if(chessStatus[i][j].matchCount==5) 
              { 
                return true; 
              } 
            }else 
            { 
              if(chessStatus[i+n][j+n]!=null) 
              { 
                chessStatus[i][j].matchCount = 1; 
              } 
              break; 
            } 
          } 
        } 
        chessStatus[i][j].matchCount=1;//refresh count 
      } 
    } 
  } 
 
  //  :     
  for(int i=0;i<ROWS+1;i++) 
  { 
    for(int j=0;j<ROWS+1;j++) 
    { 
      //   
      if(chessStatus[i][j]!=null&&chessStatus[i][j].getPlaced()==true) 
      { 
        int matchColor = chessStatus[i][j].getColor(); 
        //    ,        ,y       
        for(int n=1;n<=4;n++) 
        { 
          if((j+n>=0)&&(j+n)<=ROWS&&(i-n)>=0&&(i-n)<=ROWS) 
          { 
            if(chessStatus[i-n][j+n]!=null&&chessStatus[i-n][j+n].getPlaced()==true&&chessStatus[i-n][j+n].getColor()==matchColor) 
            { 
              chessStatus[i][j].matchCount++; 
              System.out.println("pos:"+i+" "+j+" up count++:"+(i-n)+" "+(j+n)+" count:"+chessStatus[i][j].matchCount); 
              if(chessStatus[i][j].matchCount==5) 
              { 
                return true; 
              } 
            }else 
            { 
              break; 
            }   
          } 
        } 
        //   
        for(int n=1;n<=4;n++) 
        { 
          if((j-n>=0)&&(j-n)<=ROWS&&(i+n)>=0&&(i+n)<=ROWS) 
          { 
            if(chessStatus[i+n][j-n]!=null&&chessStatus[i+n][j-n].getPlaced()==true&&chessStatus[i+n][j-n].getColor()==matchColor) 
            { 
              chessStatus[i][j].matchCount++; 
              System.out.println("pos:"+i+" "+j+" "+"left count++:"+(i+n)+" "+(j-n)+" count:"+chessStatus[i][j].matchCount); 
              if(chessStatus[i][j].matchCount==5) 
              { 
                return true; 
              } 
            }else 
            { 
              if(chessStatus[i+n][j-n]!=null) 
              { 
                chessStatus[i][j].matchCount = 1; 
              } 
              break; 
            } 
          } 
        } 
        chessStatus[i][j].matchCount=1;//refresh count 
      } 
    } 
  }     
 
  return false;   
} 
실행 해 봐!

완전한 DrawChessBoard.java

package xchen.test.simpleGobang; 
 
import java.awt.Color; 
import java.awt.Graphics; 
import java.awt.Graphics2D; 
import java.awt.Image; 
import java.awt.RadialGradientPaint; 
import java.awt.Toolkit; 
import java.awt.event.MouseEvent; 
import java.awt.event.MouseListener; 
 
import javax.swing.JPanel; 
 
public class DrawChessBoard extends JPanel implements MouseListener{ 
  final static int BLACK=0; 
  final static int WHITE=1; 
  public int chessColor = BLACK; 
  int chessman_width=30; 
   
  public Image boardImg; 
  final private int ROWS = 19; 
  Chessman[][] chessStatus=new Chessman[ROWS+1][ROWS+1];  
 
  public DrawChessBoard() { 
    boardImg = Toolkit.getDefaultToolkit().getImage("res/drawable/chessboard2.png"); 
    if(boardImg == null) 
      System.err.println("png do not exist"); 
 
    addMouseListener(this); 
  }   
  @Override 
  protected void paintComponent(Graphics g) { 
    // TODO Auto-generated method stub 
    super.paintComponent(g); 
 
    int imgWidth = boardImg.getHeight(this); 
    int imgHeight = boardImg.getWidth(this); 
    int FWidth = getWidth(); 
    int FHeight= getHeight(); 
 
    int x=(FWidth-imgWidth)/2; 
    int y=(FHeight-imgHeight)/2; 
 
    int span_x=imgWidth/ROWS; 
    int span_y=imgHeight/ROWS; 
 
    g.drawImage(boardImg, x, y, null); 
 
    //    
    for(int i=0;i<ROWS;i++) 
    { 
      g.drawLine(x, y+i*span_y, FWidth-x,y+i*span_y); 
    } 
    //    
    for(int i=0;i<ROWS;i++) 
    { 
      g.drawLine(x+i*span_x, y, x+i*span_x,FHeight-y); 
    } 
 
    //    
    for(int i=0;i<ROWS+1;i++) 
    { 
      for(int j=0;j<ROWS+1;j++) 
      { 
        if(chessStatus[i][j]!=null&&chessStatus[i][j].getPlaced()==true) 
        { 
          //System.out.println("draw chessman "+i+" "+j); 
          int pos_x=x+i*span_x; 
          int pos_y=y+j*span_y; 
          float radius_b=40; 
          float radius_w=80; 
          float[] fractions = new float[]{0f,1f}; 
          java.awt.Color[] colors_b = new java.awt.Color[]{Color.BLACK,Color.WHITE}; 
          Color[] colors_w = new Color[]{Color.WHITE,Color.BLACK}; 
          RadialGradientPaint paint; 
          if(chessStatus[i][j].getColor()==1) 
          { 
            //System.out.println("draw white chess"); 
            paint = new RadialGradientPaint(pos_x-chessman_width/2f, pos_y-chessman_width/2f, radius_w*2, fractions, colors_w); 
          }else{ 
            //System.out.println("draw black chess"); 
            paint = new RadialGradientPaint(pos_x-chessman_width/2f, pos_y-chessman_width/2f, radius_b*2, fractions, colors_b); 
          } 
          ((Graphics2D)g).setPaint(paint); 
 
          ((Graphics2D)g).fillOval(pos_x-chessman_width/2,pos_y-chessman_width/2,chessman_width,chessman_width); 
        } 
      } 
    } 
  } 
 
  @Override 
  //             
  public void mousePressed(MouseEvent e) { 
    int point_x=e.getX(); 
    int point_y=e.getY(); 
 
    int imgWidth = boardImg.getHeight(this); 
    int imgHeight = boardImg.getWidth(this); 
    int FWidth = getWidth(); 
    int FHeight= getHeight(); 
 
    int x=(FWidth-imgWidth)/2; 
    int y=(FHeight-imgHeight)/2; 
 
    int span_x=imgWidth/ROWS; 
    int span_y=imgHeight/ROWS; 
 
    //System.out.println("press"); 
    int status_x = 0; 
    int status_y = 0; 
    if(point_x>=x && point_x<=x+imgWidth && point_y>=y && point_y <= y+imgHeight) 
    { 
      //System.out.println("  "); 
      for(int i=0;i<ROWS+1;i++) 
      { 
        if(point_x>=x-chessman_width/2+1+i*span_x) 
        { 
          if(point_x<=x+chessman_width/2-1+i*span_x)//   width/2             
          { 
            //System.out.println("point x "+i+" "+point_x+" "+(x-chessman_width/2+i*span_x)+" "+(x+chessman_width/2+i*span_x)); 
            status_x = i; 
          } 
        } 
      } 
      for(int i=0;i<ROWS+1;i++) 
      { 
        if(point_y>=y-chessman_width/2+1+i*span_y) 
        { 
          if(point_y <= y+chessman_width/2-1+i*span_y) 
          { 
            //System.out.println("point y "+i+" "+point_y+" "+(y-chessman_width/2+1+i*span_y)+" "+(y+chessman_width/2-1+i*span_y)); 
            status_y = i; 
          } 
        } 
      } 
       
      if(chessStatus[status_x][status_y]==null||chessStatus[status_x][status_y].getPlaced()==false) 
      { 
        Chessman chessman = new Chessman(chessColor, true); 
        chessStatus[status_x][status_y]=chessman; 
        System.out.println("chess color:"+chessColor); 
        if(chessColor==BLACK) 
        { 
          chessColor = WHITE; 
        }else { 
          chessColor = BLACK; 
        } 
        repaint(); 
        if(isWin(status_x, status_y, chessStatus)) 
        { 
          System.out.println("WIN!!!!!"); 
        } 
      } 
    } 
  } 
  @Override 
  //                
  public void mouseClicked(MouseEvent e) { 
    // TODO Auto-generated method stub 
  } 
  @Override 
  public void mouseReleased(MouseEvent e) { 
    // TODO Auto-generated method stub 
 
  } 
  @Override 
  public void mouseEntered(MouseEvent e) { 
    // TODO Auto-generated method stub 
 
  } 
  @Override 
  public void mouseExited(MouseEvent e) { 
    // TODO Auto-generated method stub  
  } 
 
  boolean isWin(int point_x,int point_y,Chessman[][] cm) 
  {   
    for(int i=0;i<ROWS+1;i++) 
    { 
      for(int j=0;j<ROWS+1;j++) 
      { 
        //     
        if(chessStatus[i][j]!=null&&chessStatus[i][j].getPlaced()==true) 
        { 
          int matchColor = chessStatus[i][j].getColor(); 
          //      
          for(int n=1;n<=4;n++) 
          { 
            if((i+n>=0)&&(i+n)<=ROWS) 
            { 
              if(chessStatus[i+n][j]!=null&&chessStatus[i+n][j].getPlaced()==true&&chessStatus[i+n][j].getColor()==matchColor) 
              { 
                chessStatus[i][j].matchCount++; 
                System.out.println("pos:"+i+" "+j+" right count++:"+(i+n)+" "+j+" count:"+chessStatus[i][j].matchCount); 
                if(chessStatus[i][j].matchCount==5) 
                { 
                  return true; 
                } 
              }else 
              { 
                break; 
              }   
            } 
          } 
          //      
          for(int n=1;n<=4;n++) 
          { 
            if((i-n>=0)&&(i-n)<=ROWS) 
            { 
              if(chessStatus[i-n][j]!=null&&chessStatus[i-n][j].getPlaced()==true&&chessStatus[i-n][j].getColor()==matchColor) 
              { 
                chessStatus[i][j].matchCount++; 
                System.out.println("pos:"+i+" "+j+" "+"left count++:"+(i-n)+" "+j+" count:"+chessStatus[i][j].matchCount); 
                if(chessStatus[i][j].matchCount==5) 
                { 
                  return true; 
                } 
              }else 
              { 
                if(chessStatus[i-n][j]!=null) 
                { 
                  chessStatus[i][j].matchCount = 1; 
                } 
                break; 
              } 
            } 
          } 
          chessStatus[i][j].matchCount=1;//refresh count 
        } 
      } 
    } 
 
    for(int i=0;i<ROWS+1;i++) 
    { 
      for(int j=0;j<ROWS+1;j++) 
      { 
        //   
        if(chessStatus[i][j]!=null&&chessStatus[i][j].getPlaced()==true) 
        { 
          int matchColor = chessStatus[i][j].getColor(); 
          //    ,        ,y       
          for(int n=1;n<=4;n++) 
          { 
            if((j+n>=0)&&(j+n)<=ROWS) 
            { 
              if(chessStatus[i][j+n]!=null&&chessStatus[i][j+n].getPlaced()==true&&chessStatus[i][j+n].getColor()==matchColor) 
              { 
                chessStatus[i][j].matchCount++; 
                System.out.println("pos:"+i+" "+j+" up count++:"+(i)+" "+(j+n)+" count:"+chessStatus[i][j].matchCount); 
                if(chessStatus[i][j].matchCount==5) 
                { 
                  return true; 
                } 
              }else 
              { 
                break; 
              }   
            } 
          } 
          //     
          for(int n=1;n<=4;n++) 
          { 
            if((j-n>=0)&&(j-n)<=ROWS) 
            { 
              if(chessStatus[i][j-n]!=null&&chessStatus[i][j-n].getPlaced()==true&&chessStatus[i][j-n].getColor()==matchColor) 
              { 
                chessStatus[i][j].matchCount++; 
                System.out.println("pos:"+i+" "+j+" "+"left count++:"+(i)+" "+(j-n)+" count:"+chessStatus[i][j].matchCount); 
                if(chessStatus[i][j].matchCount==5) 
                { 
                  return true; 
                } 
              }else 
              { 
                if(chessStatus[i][j-n]!=null) 
                { 
                  chessStatus[i][j].matchCount = 1; 
                } 
                break; 
              } 
            } 
          } 
          chessStatus[i][j].matchCount=1;//refresh count 
        } 
      } 
    } 
 
    //  :     
    for(int i=0;i<ROWS+1;i++) 
    { 
      for(int j=0;j<ROWS+1;j++) 
      { 
        //   
        if(chessStatus[i][j]!=null&&chessStatus[i][j].getPlaced()==true) 
        { 
          int matchColor = chessStatus[i][j].getColor(); 
          //    ,        ,y       
          for(int n=1;n<=4;n++) 
          { 
            if((j-n>=0)&&(j-n)<=ROWS&&(i-n)>=0&&(i-n)<=ROWS) 
            { 
              if(chessStatus[i-n][j-n]!=null&&chessStatus[i-n][j-n].getPlaced()==true&&chessStatus[i-n][j-n].getColor()==matchColor) 
              { 
                chessStatus[i][j].matchCount++; 
                System.out.println("pos:"+i+" "+j+" up count++:"+(i-n)+" "+(j-n)+" count:"+chessStatus[i][j].matchCount); 
                if(chessStatus[i][j].matchCount==5) 
                { 
                  return true; 
                } 
              }else 
              { 
                break; 
              }   
            } 
          } 
          //   
          for(int n=1;n<=4;n++) 
          { 
            if((j+n>=0)&&(j+n)<=ROWS&&(i+n)>=0&&(i+n)<=ROWS) 
            { 
              if(chessStatus[i+n][j+n]!=null&&chessStatus[i+n][j+n].getPlaced()==true&&chessStatus[i+n][j+n].getColor()==matchColor) 
              { 
                chessStatus[i][j].matchCount++; 
                System.out.println("pos:"+i+" "+j+" "+"left count++:"+(i+n)+" "+(j+n)+" count:"+chessStatus[i][j].matchCount); 
                if(chessStatus[i][j].matchCount==5) 
                { 
                  return true; 
                } 
              }else 
              { 
                if(chessStatus[i+n][j+n]!=null) 
                { 
                  chessStatus[i][j].matchCount = 1; 
                } 
                break; 
              } 
            } 
          } 
          chessStatus[i][j].matchCount=1;//refresh count 
        } 
      } 
    } 
 
    //  :     
    for(int i=0;i<ROWS+1;i++) 
    { 
      for(int j=0;j<ROWS+1;j++) 
      { 
        //   
        if(chessStatus[i][j]!=null&&chessStatus[i][j].getPlaced()==true) 
        { 
          int matchColor = chessStatus[i][j].getColor(); 
          //    ,        ,y       
          for(int n=1;n<=4;n++) 
          { 
            if((j+n>=0)&&(j+n)<=ROWS&&(i-n)>=0&&(i-n)<=ROWS) 
            { 
              if(chessStatus[i-n][j+n]!=null&&chessStatus[i-n][j+n].getPlaced()==true&&chessStatus[i-n][j+n].getColor()==matchColor) 
              { 
                chessStatus[i][j].matchCount++; 
                System.out.println("pos:"+i+" "+j+" up count++:"+(i-n)+" "+(j+n)+" count:"+chessStatus[i][j].matchCount); 
                if(chessStatus[i][j].matchCount==5) 
                { 
                  return true; 
                } 
              }else 
              { 
                break; 
              }   
            } 
          } 
          //   
          for(int n=1;n<=4;n++) 
          { 
            if((j-n>=0)&&(j-n)<=ROWS&&(i+n)>=0&&(i+n)<=ROWS) 
            { 
              if(chessStatus[i+n][j-n]!=null&&chessStatus[i+n][j-n].getPlaced()==true&&chessStatus[i+n][j-n].getColor()==matchColor) 
              { 
                chessStatus[i][j].matchCount++; 
                System.out.println("pos:"+i+" "+j+" "+"left count++:"+(i+n)+" "+(j-n)+" count:"+chessStatus[i][j].matchCount); 
                if(chessStatus[i][j].matchCount==5) 
                { 
                  return true; 
                } 
              }else 
              { 
                if(chessStatus[i+n][j-n]!=null) 
                { 
                  chessStatus[i][j].matchCount = 1; 
                } 
                break; 
              } 
            } 
          } 
          chessStatus[i][j].matchCount=1;//refresh count 
        } 
      } 
    }     
 
    return false;   
  } 
}
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기