我这里有五子棋的java程序,有源文件,也有弄好的,有谁要的,来吧就!!
我有时间给你传过去,还有一些别的小程序,贪吃蛇什么的
先复一部分吧,也不是很多!
看看吧,一共是800多行,呵呵
其中,代码可能有缺失,望大家在测试代码的时候,添加一下自己的思绪,自己整理,那样代码就属于你的了--哈哈
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
class Gobang extends JFrame implements Runnable, ActionListener
{
final static int Player=1;
final static int AI =-1;
ClassLoader cl = this.getClass().getClassLoader();
Toolkit tk = Toolkit.getDefaultToolkit();
int length=14, game_state, winner, check, step;
int grid[][] = new int[length][length];
int locX, locY , count , x, y, displace_x=0, displace_y=0 , direction;
ArrayList steps = new ArrayList();
JPopupMenu control_menu = new JPopupMenu();
JMenuItem[] command = new JMenuItem[4];
String[] command_str={"??囱", "?s郎", "弄郎", "???}"};
int[][] dir = { {-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1} };
boolean[] dir2 = new boolean[8];
boolean turn;
String message;
final JDialog dialog = new JDialog(this, "叫匡?l", true);
Font font=new Font("new_font", Font.BOLD, 20);
Grid grids[][] = new Grid[length][length];
Image white= tk.getImage(cl.getResource("res/white.png"));
Image black= tk.getImage(cl.getResource("res/black.png"));
Image title= tk.getImage(cl.getResource("res/title.png"));
Image temp;
JPanel boardPanel, bigpanel;
JRadioButton[] choice = new JRadioButton[2];
final static int Start =0;
final static int Select =1;
final static int Playing =2;
final static int End =3;
final static int nil=-1;
final static int oblique_1 =0;
final static int oblique_2 =1;
final static int horizontal =2;
final static int vertical=3;
Gobang()
{
super("き?l囱");
boardPanel = new JPanel();
boardPanel.setLayout(new GridLayout(length, length, 0, 0));
boardPanel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
for(int i=0; i<length; i++)
for(int j=0; j<length; j++)
{
grids[i][j] = new Grid(i, j);
boardPanel.add(grids[i][j]);
}
bigpanel = new JPanel();
bigpanel.add(boardPanel, BorderLayout.CENTER);
getContentPane().add(bigpanel, BorderLayout.SOUTH);
game_state=Start;
ThreadStart();
dialog.setSize(160, 100);
dialog.setResizable(false);
dialog.setLocationRelativeTo(null);
ButtonGroup choice_group = new ButtonGroup();
JPanel choice_menu = new JPanel();
choice[0] = new JRadioButton("堵?l", new ImageIcon(black), true);
choice[1] = new JRadioButton("フ?l", new ImageIcon(white));
for(int i=0; i<choice.length; i++)
{
choice_menu.add(choice[i]);
choice_group.add(choice[i]);
}
for(int i=0; i<command.length; i++)
{
command[i] =new JMenuItem(command_str[i]);
command[i].addActionListener(this);
control_menu.add(command[i]);
}
JButton select = new JButton("?T?w");
JPanel select_menu = new JPanel();
select_menu.add(select);
select.addActionListener(this);
dialog.getContentPane().add(choice_menu, BorderLayout.NORTH);
dialog.getContentPane().add(select_menu, BorderLayout.CENTER);
setIconImage(title);
setResizable(false);
setSize(300, 335);
setVisible(true);
setLocationRelativeTo(null);
}
public static void main(String[] arg)
{
Gobang application = new Gobang();