java实现单人版五子棋游戏实现单人版五子棋游戏
主要介绍了java实现五子棋小游戏的相关资料,十分简单实用,有不错的参考借鉴价值,,推荐给大家,需要的朋
友可以参考下
本文实例讲述了java实现的五子棋游戏代码,分享给大家供大家参考,具体代码如下
package gyb.exam;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
public class MainFrame extends JFrame{
private static int BIG=15;
private static final int ONE=25;
private static final int START=10;
private static int X=BIG*START/2;
private static int Y=BIG*START/2;
private int HL=BIG*ONE+START;
private static boolean isBlack;
CanvasFrame canvas=new CanvasFrame();
CanvasFrame can;
Graphics g;
public MainFrame(){
init();
}
private Point point;
private ArrayList<Point> blacklist=new ArrayList<Point>();
private ArrayList<Point> whitelist=new ArrayList<Point>();
private void init() {
JMenuBar bar=new JMenuBar();
setJMenuBar(bar);
setSize(600,600);
setTitle("五子棋");
JMenu menu=new JMenu("game");
bar.add(menu);
JMenuItem start=new JMenuItem("start");
JMenuItem end=new JMenuItem("棋盘大小");
end.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
JMenuItem renew=new JMenuItem("重新开始");
JMenuItem exit=new JMenuItem("退出");
exit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
renew.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
blacklist.clear();
whitelist.clear();
}
});
menu.add(start);
menu.add(renew);