本文实例讲述了java基于swing实现的五子棋游戏代码。分享给大家供大家参考。
主要功能代码如下:
import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Main extends JFrame implements ActionListener{ private static final long serialVersionUID = 1L; JButton[][] point=new JButton[40][40]; int[][] state=new int[40][40]; int[][] value=new int[40][40]; int[] place=new int[2]; public Main(){ this.setTitle("五子棋"); this.setBounds(100,10,1000,1000); this.setLayout(new GridLayout(30,30)); int i,j; for(i=0;i<=39;i++){ for(j=0;j<=39;j++){ state[i][j]=0; value[i][j]=0; } } for(i=5;i<=34;i++){ for (j=5;j<=34;j++){ point[i][j]=new JButton(""); this.add(point[i][j]); point[i][j].addActionListener(this); } } this.setVisible(true); } public void actionPerformed(ActionEvent e) { int i,j; for(i=5;i<=34;i++){ for(j=5;j<=34;j++){ if(e.getSource()==point[i][j]){ point[i][j].setBackground(Color.RED); state[i][j]=1; point[i][j].setEnabled(false); value[i][j]=0; } } } for(i=5;i<=34;i++){ for(j=5;j<=34;j++){ value[i][j]=value(i,j); if(((state[i][j]==1)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==1)&&(state[i][j+4]==1))|| ((state[i][j]==1)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==1)&&(state[i+4][j]==1))|| ((state[i][j]==1)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==1)&&(state[i-4][j+4]==1))|| ((state[i][j]==1)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==1)&&(state[i+4][j+4]==1))){ JOptionPane.showMessageDialog(null,"你太厉害了吧,我打不过你"); }} } place=largestValue(value); point[place[0]][place[1]].setBackground(Color.blue); state[place[0]][place[1]]=2; value[place[0]][place[1]]=0; for(i=5;i<=34;i++){ for(j=5;j<=34;j++){ if(((state[i][j]==2)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==2)&&(state[i][j+4]==2))|| ((state[i][j]==2)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==2)&&(state[i+4][j]==2))|| ((state[i][j]==2)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2)&&(state[i-3][j+3]==2)&&(state[i-4][j+4]==2))|| ((state[i][j]==2)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==2)&&(state[i+4][j+4]==2))){ JOptionPane.showMessageDialog(null,"还是没我厉害吧"); } } }
}
public static void main(String[] args)throws NullPointerException{ new Main(); } public int value(int i,int j){
if(((state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==1)&&(state[i][j+4]==1)&&(state[i][j+5]==0))|| ((state[i][j]==0)&&(state[i][j-1]==1)&&(state[i][j-2]==1)&&(state[i][j-3]==1)&&(state[i][j-4]==1)&&(state[i][j-5]==0))|| ((state[i][j]==0)&&(state[i-1][j]==1)&&(state[i-2][j]==1)&&(state[i-3][j]==1)&&(state[i-4][j]==1)&&(state[i-5][j]==0))|| ((state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==1)&&(state[i+4][j]==1)&&(state[i+5][j]==0))|| ((state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==1)&&(state[i+4][j+4]==1)&&(state[i+5][j+5]==0))|| //空红红红红空型 ((state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==1)&&(state[i-4][j+4]==1)&&(state[i-5][j+5]==0))|| ((state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1)&&(state[i+3][j-3]==1)&&(state[i+4][j-4]==1)&&(state[i+5][j-5]==0))|| ((state[i][j]==0)&&(state[i-1][j-1]==1)&&(state[i-2][j-2]==1)&&(state[i-3][j-3]==1)&&(state[i-4][j-4]==1)&&(state[i-5][j-5]==0))){ value[i][j]=8; return value[i][j]; } else if(((state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==2)&&(state[i][j+4]==2)&&(state[i][j+5]==0))|| ((state[i][j]==0)&&(state[i][j-1]==2)&&(state[i][j-2]==2)&&(state[i][j-3]==2)&&(state[i][j-4]==2)&&(state[i][j-5]==0))|| ((state[i][j]==0)&&(state[i-1][j]==2)&&(state[i-2][j]==2)&&(state[i-3][j]==2)&&(state[i-4][j]==2)&&(state[i-5][j]==0))|| //空红红红红空型 ((state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==2)&&(state[i+4][j]==2)&&(state[i+5][j]==0))|| ((state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==2)&&(state[i+4][j+4]==2)&&(state[i+5][j+5]==0))|| ((state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2)&&(state[i-3][j+3]==2)&&(state[i-4][j+4]==2)&&(state[i-5][j+5]==0))|| ((state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2)&&(state[i+3][j-3]==2)&&(state[i+4][j-4]==2)&&(state[i+5][j-5]==0))|| ((state[i][j]==0)&&(state[i-1][j-1]==2)&&(state[i-2][j-2]==2)&&(state[i-3][j-3]==2)&&(state[i-4][j-4]==2)&&(state[i-5][j-5]==0))){ value[i][j]=7; return value[i][j]; } else if(((state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==1)&&(state[i][j+4]==0))|| ((state[i][j]==0)&&(state[i][j-1]==1)&&(state[i][j-2]==1)&&(state[i][j-3]==1)&&(state[i][j-4]==0))|| ((state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==1)&&(state[i+4][j]==0))|| ((state[i][j]==0)&&(state[i-1][j]==1)&&(state[i-2][j]==1)&&(state[i-3][j]==1)&&(state[i-4][j]==0))|| //空红红红空型 ((state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==1)&&(state[i+4][j+4]==0))|| ((state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1)&&(state[i+3][j-3]==1)&&(state[i+4][j-4]==0))|| ((state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==1)&&(state[i-4][j+4]==0))|| ((state[i][j]==0)&&(state[i-1][j-1]==1)&&(state[i-2][j-2]==1)&&(state[i-3][j-3]==1)&&(state[i-4][j-4]==0))||
((state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==0)&&(state[i][j+3]==1)&&(state[i][j+4]==1)&&(state[i][j+5]==0))|| ((state[i][j]==0)&&(state[i][j-1]==1)&&(state[i][j-2]==0)&&(state[i][j-3]==1)&&(state[i][j-4]==1)&&(state[i][j-5]==0))|| ((state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==0)&&(state[i+3][j]==1)&&(state[i+4][j]==1)&&(state[i+5][j]==0))|| ((state[i][j]==0)&&(state[i-1][j]==1)&&(state[i-2][j]==0)&&(state[i-3][j]==1)&&(state[i-4][j]==1)&&(state[i-5][j]==0))|| //空红空红红空 ((state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==0)&&(state[i+3][j+3]==1)&&(state[i+4][j+4]==1)&&(state[i+5][j+5]==0))|| ((state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==0)&&(state[i+3][j-3]==1)&&(state[i+4][j-4]==1)&&(state[i+5][j-5]==0))|| ((state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==0)&&(state[i-3][j+3]==1)&&(state[i-4][j+4]==1)&&(state[i-5][j+5]==0))|| ((state[i][j]==0)&&(state[i-1][j-1]==1)&&(state[i-2][j-2]==0)&&(state[i-3][j-3]==1)&&(state[i-4][j-4]==1)&&(state[i-5][j-5]==0))||
((state[i][j-2]==1)&&(state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1))|| ((state[i-2][j]==1)&&(state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1))|| ((state[i+2][j-2]==1)&&(state[i+1][j-1]==1)&&(state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1))|| ((state[i-2][j+2]==1)&&(state[i-1][j+1]==1)&&(state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1))|| //红红空红红型
((state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==1))|| ((state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==1))|| ((state[i][j-3]==1)&&(state[i][j-2]==1)&&(state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1))|| ((state[i-3][j]==1)&&(state[i-2][j]==1)&&(state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1))|| //红空红红红型 ((state[i-1][j-1]==1)&&(state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==1))|| ((state[i-3][j-3]==1)&&(state[i-2][j-2]==1)&&(state[i-1][j-1]==1)&&(state[i][j]==0)&&(state[i+1][j+1]==1))|| ((state[i-1][j+1]==1)&&(state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1)&&(state[i+3][j-3]==1))|| ((state[i+1][j-1]==1)&&(state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==1))||
((state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==1)&&(state[i][j+4]==1)&&(state[i][j+5]==2))|| ((state[i][j]==0)&&(state[i][j-1]==1)&&(state[i][j-2]==1)&&(state[i][j-3]==1)&&(state[i][j-4]==1)&&(state[i][j-5]==2))|| ((state[i][j]==0)&&(state[i-1][j]==1)&&(state[i-2][j]==1)&&(state[i-3][j]==1)&&(state[i-4][j]==1)&&(state[i-5][j]==2))|| //空红红红红蓝型 ((state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==1)&&(state[i+4][j]==1)&&(state[i+5][j]==2))|| ((state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==1)&&(state[i+4][j+4]==1)&&(state[i+5][j+5]==2))|| ((state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==1)&&(state[i-4][j+4]==1)&&(state[i-5][j+5]==2))|| ((state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1)&&(state[i+3][j-3]==1)&&(state[i+4][j-4]==1)&&(state[i+5][j-5]==2))|| ((state[i][j]==0)&&(state[i-1][j-1]==1)&&(state[i-2][j-2]==1)&&(state[i-3][j-3]==1)&&(state[i-4][j-4]==1)&&(state[i-5][j-5]==2))||
((state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==1)&&(state[i][j+4]==2))|| ((state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==1)&&(state[i+4][j]==2))|| ((state[i][j-4]==2)&&(state[i][j-3]==1)&&(state[i][j-2]==1)&&(state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1))|| ((state[i][j-4]==2)&&(state[i-3][j]==1)&&(state[i-2][j]==1)&&(state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1))|| //红空红红红蓝 ((state[i-1][j-1]==1)&&(state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==1)&&(state[i+4][j+4]==2))|| ((state[i-4][j-4]==2)&&(state[i-3][j-3]==1)&&(state[i-2][j-2]==1)&&(state[i-1][j-1]==1)&&(state[i][j]==0)&&(state[i+1][j+1]==1))|| ((state[i-1][j+1]==1)&&(state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1)&&(state[i+3][j-3]==1)&&(state[i+4][j-4]==2))|| ((state[i+1][j-1]==1)&&(state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==1)&&(state[i-4][j+4]==2))||
((state[i][j-2]==2)&&(state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==1))|| ((state[i-2][j]==2)&&(state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==1))|| ((state[i][j-3]==1)&&(state[i][j-2]==1)&&(state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==2))|| ((state[i-3][j]==1)&&(state[i-2][j]==1)&&(state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==2))|| //红红红空红蓝型 ((state[i-2][j-2]==2)&&(state[i-1][j-1]==1)&&(state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==1))|| ((state[i-3][j-3]==1)&&(state[i-2][j-2]==1)&&(state[i-1][j-1]==1)&&(state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==2))|| ((state[i-2][j+2]==2)&&(state[i-1][j+1]==1)&&(state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1)&&(state[i+3][j-3]==1))|| ((state[i+2][j-2]==2)&&(state[i+1][j-1]==1)&&(state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==1))||
((state[i][j-3]==2)&&(state[i][j-2]==1)&&(state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1))|| ((state[i-3][j]==2)&&(state[i-2][j]==1)&&(state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1))|| ((state[i+3][j-3]==2)&&(state[i+2][j-2]==1)&&(state[i+1][j-1]==1)&&(state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1))|| ((state[i-3][j+3]==2)&&(state[i-2][j+2]==1)&&(state[i-1][j+1]==1)&&(state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1))|| ((state[i][j-2]==1)&&(state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==2))|| //红红空红红蓝型 ((state[i-2][j]==1)&&(state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==2))|| ((state[i-3][j-3]==2)&&(state[i-2][j-2]==1)&&(state[i-1][j-1]==1)&&(state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1))|| ((state[i+3][j+3]==2)&&(state[i+2][j+2]==1)&&(state[i+1][j+1]==1)&&(state[i][j]==0)&&(state[i-1][j-1]==1)&&(state[i-2][j-2]==1))||
((state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==1)&&(state[i][j+4]==1))|| ((state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==1)&&(state[i+2][j]==1)&&(state[i+3][j]==1)&&(state[i+4][j]==1))|| ((state[i-1][j-1]==2)&&(state[i][j]==0)&&(state[i+1][j+1]==1)&&(state[i+2][j+2]==1)&&(state[i+3][j+3]==1)&&(state[i+4][j+4]==1))|| ((state[i+1][j+1]==2)&&(state[i][j]==0)&&(state[i-1][j-1]==1)&&(state[i-2][j-2]==1)&&(state[i-3][j-3]==1)&&(state[i-4][j-4]==1))|| ((state[i][j+1]==2)&&(state[i][j]==0)&&(state[i][j+1]==1)&&(state[i][j+2]==1)&&(state[i][j+3]==1)&&(state[i][j+4]==1))|| //红红红红空蓝型 ((state[i+1][j]==2)&&(state[i][j]==0)&&(state[i-1][j]==1)&&(state[i-2][j]==1)&&(state[i-3][j]==1)&&(state[i-4][j]==1))|| ((state[i-1][j+1]==2)&&(state[i][j]==0)&&(state[i+1][j-1]==1)&&(state[i+2][j-2]==1)&&(state[i+3][j-3]==1)&&(state[i+4][j-4]==1))|| ((state[i+1][j-1]==2)&&(state[i][j]==0)&&(state[i-1][j+1]==1)&&(state[i-2][j+2]==1)&&(state[i-3][j+3]==1)&&(state[i-4][j+4]==1))){ value[i][j]=6; return value[i][j]; } else if(((state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==2)&&(state[i][j+4]==0))|| ((state[i][j]==0)&&(state[i][j-1]==2)&&(state[i][j-2]==2)&&(state[i][j-3]==2)&&(state[i][j-4]==0))|| ((state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==2)&&(state[i+4][j]==0))|| ((state[i][j]==0)&&(state[i-1][j]==2)&&(state[i-2][j]==2)&&(state[i-3][j]==2)&&(state[i-4][j]==0))|| ((state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==2)&&(state[i+4][j+4]==0))|| ((state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2)&&(state[i+3][j-3]==2)&&(state[i+4][j-4]==0))|| ((state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2)&&(state[i-3][j+3]==2)&&(state[i-4][j+4]==0))|| ((state[i][j]==0)&&(state[i-1][j-1]==2)&&(state[i-2][j-2]==2)&&(state[i-3][j-3]==2)&&(state[i-4][j-4]==0))||
((state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==0)&&(state[i][j+3]==2)&&(state[i][j+4]==2)&&(state[i][j+5]==0))|| ((state[i][j]==0)&&(state[i][j-1]==2)&&(state[i][j-2]==0)&&(state[i][j-3]==2)&&(state[i][j-4]==2)&&(state[i][j-5]==0))|| ((state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==0)&&(state[i+3][j]==2)&&(state[i+4][j]==2)&&(state[i+5][j]==0))|| ((state[i][j]==0)&&(state[i-1][j]==2)&&(state[i-2][j]==0)&&(state[i-3][j]==2)&&(state[i-4][j]==2)&&(state[i-5][j]==0))|| ((state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==0)&&(state[i+3][j+3]==2)&&(state[i+4][j+4]==2)&&(state[i+5][j+5]==0))|| ((state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==0)&&(state[i+3][j-3]==2)&&(state[i+4][j-4]==2)&&(state[i+5][j-5]==0))|| ((state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==0)&&(state[i-3][j+3]==2)&&(state[i-4][j+4]==2)&&(state[i-5][j+5]==0))|| ((state[i][j]==0)&&(state[i-1][j-1]==2)&&(state[i-2][j-2]==0)&&(state[i-3][j-3]==2)&&(state[i-4][j-4]==2)&&(state[i-5][j-5]==0))||
((state[i][j-2]==2)&&(state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2))|| ((state[i-2][j]==2)&&(state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2))|| ((state[i+2][j-2]==2)&&(state[i+1][j-1]==2)&&(state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2))|| ((state[i-2][j+2]==2)&&(state[i-1][j+1]==2)&&(state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2))||
((state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==2))|| ((state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==2))|| ((state[i][j-3]==2)&&(state[i][j-2]==2)&&(state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2))|| ((state[i-3][j]==2)&&(state[i-2][j]==2)&&(state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2))|| ((state[i-1][j-1]==2)&&(state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==2))|| ((state[i-3][j-3]==2)&&(state[i-2][j-2]==2)&&(state[i-1][j-1]==2)&&(state[i][j]==0)&&(state[i+1][j+1]==2))|| ((state[i-1][j+1]==2)&&(state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2)&&(state[i+3][j-3]==2))|| ((state[i+1][j-1]==2)&&(state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2)&&(state[i-3][j+3]==2))||
((state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==2)&&(state[i][j+4]==2)&&(state[i][j+5]==1))|| ((state[i][j]==0)&&(state[i][j-1]==2)&&(state[i][j-2]==2)&&(state[i][j-3]==2)&&(state[i][j-4]==2)&&(state[i][j-5]==1))|| ((state[i][j]==0)&&(state[i-1][j]==2)&&(state[i-2][j]==2)&&(state[i-3][j]==2)&&(state[i-4][j]==2)&&(state[i-5][j]==1))|| ((state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==2)&&(state[i+4][j]==2)&&(state[i+5][j]==1))|| ((state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==2)&&(state[i+4][j+4]==2)&&(state[i+5][j+5]==1))|| ((state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2)&&(state[i-3][j+3]==2)&&(state[i-4][j+4]==2)&&(state[i-5][j+5]==1))|| ((state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2)&&(state[i+3][j-3]==2)&&(state[i+4][j-4]==2)&&(state[i+5][j-5]==1))|| ((state[i][j]==0)&&(state[i-1][j-1]==2)&&(state[i-2][j-2]==2)&&(state[i-3][j-3]==2)&&(state[i-4][j-4]==2)&&(state[i-5][j-5]==1))||
((state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==2)&&(state[i][j+4]==1))|| ((state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==2)&&(state[i+4][j]==1))|| ((state[i][j-4]==1)&&(state[i][j-3]==2)&&(state[i][j-2]==2)&&(state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2))|| ((state[i][j-4]==1)&&(state[i-3][j]==2)&&(state[i-2][j]==2)&&(state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2))|| ((state[i-1][j-1]==2)&&(state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==2)&&(state[i+4][j+4]==1))|| ((state[i-4][j-4]==1)&&(state[i-3][j-3]==2)&&(state[i-2][j-2]==2)&&(state[i-1][j-1]==2)&&(state[i][j]==0)&&(state[i+1][j+1]==2))|| ((state[i-1][j+1]==2)&&(state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2)&&(state[i+3][j-3]==2)&&(state[i+4][j-4]==1))|| ((state[i+1][j-1]==2)&&(state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2)&&(state[i-3][j+3]==2)&&(state[i-4][j+4]==1))||
((state[i][j-2]==1)&&(state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==2))|| ((state[i-2][j]==1)&&(state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==2))|| ((state[i][j-3]==2)&&(state[i][j-2]==2)&&(state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==1))|| ((state[i-3][j]==2)&&(state[i-2][j]==2)&&(state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==1))|| ((state[i-2][j-2]==1)&&(state[i-1][j-1]==2)&&(state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==2))|| ((state[i-3][j-3]==2)&&(state[i-2][j-2]==2)&&(state[i-1][j-1]==2)&&(state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==1))|| ((state[i-2][j+2]==1)&&(state[i-1][j+1]==2)&&(state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2)&&(state[i+3][j-3]==2))|| ((state[i+2][j-2]==1)&&(state[i+1][j-1]==2)&&(state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2)&&(state[i-3][j+3]==2))||
((state[i][j-3]==1)&&(state[i][j-2]==2)&&(state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2))|| ((state[i-3][j]==1)&&(state[i-2][j]==2)&&(state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2))|| ((state[i+3][j-3]==1)&&(state[i+2][j-2]==2)&&(state[i+1][j-1]==2)&&(state[i][j]==0)&&(state[i-1][j+1]==2)&&(state[i-2][j+2]==2))|| ((state[i-3][j+3]==1)&&(state[i-2][j+2]==2)&&(state[i-1][j+1]==2)&&(state[i][j]==0)&&(state[i+1][j-1]==2)&&(state[i+2][j-2]==2))|| ((state[i][j-2]==2)&&(state[i][j-1]==2)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==1))|| ((state[i-2][j]==2)&&(state[i-1][j]==2)&&(state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==1))|| ((state[i-3][j-3]==1)&&(state[i-2][j-2]==2)&&(state[i-1][j-1]==2)&&(state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2))|| ((state[i+3][j+3]==1)&&(state[i+2][j+2]==2)&&(state[i+1][j+1]==2)&&(state[i][j]==0)&&(state[i-1][j-1]==2)&&(state[i-2][j-2]==2))||
((state[i][j-1]==1)&&(state[i][j]==0)&&(state[i][j+1]==2)&&(state[i][j+2]==2)&&(state[i][j+3]==2)&&(state[i][j+4]==2))|| ((state[i-1][j]==1)&&(state[i][j]==0)&&(state[i+1][j]==2)&&(state[i+2][j]==2)&&(state[i+3][j]==2)&&(state[i+4][j]==2))|| ((state[i-1][j-1]==1)&&(state[i][j]==0)&&(state[i+1][j+1]==2)&&(state[i+2][j+2]==2)&&(state[i+3][j+3]==2)&&(state[i+4][j+4]==2))||
本文向大家介绍java Swing实现五子棋游戏,包括了java Swing实现五子棋游戏的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家分享了java实现五子棋项目,供大家参考,具体内容如下 运行结果 视频经过压缩画质略显粗糙。 标题 1)绘制网格棋盘: 重写JPanel的paint(Graphics g)方法,绘制16*16网格。 如图: 2)代码如下(仅包含部分代码): 具体运行效果
本文向大家介绍基于javascript canvas实现五子棋游戏,包括了基于javascript canvas实现五子棋游戏的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家分享了基于canvas的五子棋的具体代码,供大家参考,具体内容如下 第一部分:核心类Gobang 属性: 方法: 第二部分:源代码 Gobang.js 五子棋.html 更多有趣的经典小游戏实现专题,分享给大家: C+
本文向大家介绍java实现五子棋小游戏,包括了java实现五子棋小游戏的使用技巧和注意事项,需要的朋友参考一下 java实现五子棋小游戏 演示图: 以上所述就是本文的全部内容了,希望能够对大家熟练掌握java有所帮助。
本文向大家介绍java GUI实现五子棋游戏,包括了java GUI实现五子棋游戏的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家分享了java实现五子棋游戏GUI,供大家参考,具体内容如下 引用包 前期预设 设置背景板 主要框架段落 判断是否满了 判断是否赢了 和八皇后有点像,可以考虑那种数组优化四个方向,这里比较懒 设置棋子 导入图片 游戏结束的锁定与弹窗 其他棋子信息 图片显示 以上
本文向大家介绍javafx实现五子棋游戏,包括了javafx实现五子棋游戏的使用技巧和注意事项,需要的朋友参考一下 需求描述 一个五子棋游戏,能实现双方黑白对决,当一方获胜时给出提示信息,利用GUI界面实现 项目结构如下图 一、实体 FiveChess类 提供五子棋实体包含的所有信息 判断游戏是否结束 play方法改变chess[][]棋盘中的数据 二、视图 ChessPane类继承Pane类实现
本文向大家介绍python实现五子棋游戏,包括了python实现五子棋游戏的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家分享了python实现五子棋游戏的具体代码,供大家参考,具体内容如下 话不多说,直接上代码: 全部工程文件,在GitHub:五子棋 效果预览: 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持呐喊教程。