提示: 下面给的代码有问题哦,可以自己去调试

可用版 http://pan.baidu.com/s/1i4XvawX(退出程序,端口并没有被关闭,可自行修改代码实现)

img

aaarticlea/gif;base64,R0lGODdhGAAYAPcAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwMDcwKbK8EAgAGAgAIAgAKAgAMAgAOAgAABAACBAAEBAAGBAAIBAAKBAAMBAAOBAAABgACBgAEBgAGBgAIBgAKBgAMBgAOBgAACAACCAAECAAGCAAICAAKCAAMCAAOCAAACgACCgAECgAGCgAICgAKCgAMCgAOCgAADAACDAAEDAAGDAAIDAAKDAAMDAAODAAADgACDgAEDgAGDgAIDgAKDgAMDgAODgAAAAQCAAQEAAQGAAQIAAQKAAQMAAQOAAQAAgQCAgQEAgQGAgQIAgQKAgQMAgQOAgQABAQCBAQEBAQGBAQIBAQKBAQMBAQOBAQABgQCBgQEBgQGBgQIBgQKBgQMBgQOBgQACAQCCAQECAQGCAQICAQKCAQMCAQOCAQACgQCCgQECgQGCgQICgQKCgQMCgQOCgQADAQCDAQEDAQGDAQIDAQKDAQMDAQODAQADgQCDgQEDgQGDgQIDgQKDgQMDgQODgQAAAgCAAgEAAgGAAgIAAgKAAgMAAgOAAgAAggCAggEAggGAggIAggKAggMAggOAggABAgCBAgEBAgGBAgIBAgKBAgMBAgOBAgABggCBggEBggGBggIBggKBggMBggOBggACAgCCAgECAgGCAgICAgKCAgMCAgOCAgACggCCggECggGCggICggKCggMCggOCggADAgCDAgEDAgGDAgIDAgKDAgMDAgODAgADggCDggEDggGDggIDggKDggMDggODggAAAwCAAwEAAwGAAwIAAwKAAwMAAwOAAwAAgwCAgwEAgwGAgwIAgwKAgwMAgwOAgwABAwCBAwEBAwGBAwIBAwKBAwMBAwOBAwABgwCBgwEBgwGBgwIBgwKBgwMBgwOBgwACAwCCAwECAwGCAwICAwKCAwMCAwOCAwACgwCCgwECgwGCgwICgwKCgwMCgwOCgwADAwCDAwEDAwGDAwIDAwKDAwP/78KCgpICAgP8AAAD/AP//AAAA//8A/wD//////yH5BAAAAAAALAAAAAAYABgAAAivAG8IHEhwIKmCCBPe2ESK1L17Bw4oTJhEyhaGDiEeQDBxIIAkFS1uYvhwY0cAKEFKWSnSYUSFIFOCnLlyi0uJBWei3Ckz5M2cMXkKrWjzIUEpOoUOtZhxoJQoQZXuVEnSKdIkUpdePHgDwMqoWT8S3XSj4VesYWWytJo0rUopVq+mnQry6FW0cwEUZNk2LUK+fcXOVAh4puHBE1nePZyko0DFkFc6tgt5suXLmAUGBAA7" alt="" />        aaarticlea/gif;base64,R0lGODdhGAAYAPcAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwMDcwKbK8EAgAGAgAIAgAKAgAMAgAOAgAABAACBAAEBAAGBAAIBAAKBAAMBAAOBAAABgACBgAEBgAGBgAIBgAKBgAMBgAOBgAACAACCAAECAAGCAAICAAKCAAMCAAOCAAACgACCgAECgAGCgAICgAKCgAMCgAOCgAADAACDAAEDAAGDAAIDAAKDAAMDAAODAAADgACDgAEDgAGDgAIDgAKDgAMDgAODgAAAAQCAAQEAAQGAAQIAAQKAAQMAAQOAAQAAgQCAgQEAgQGAgQIAgQKAgQMAgQOAgQABAQCBAQEBAQGBAQIBAQKBAQMBAQOBAQABgQCBgQEBgQGBgQIBgQKBgQMBgQOBgQACAQCCAQECAQGCAQICAQKCAQMCAQOCAQACgQCCgQECgQGCgQICgQKCgQMCgQOCgQADAQCDAQEDAQGDAQIDAQKDAQMDAQODAQADgQCDgQEDgQGDgQIDgQKDgQMDgQODgQAAAgCAAgEAAgGAAgIAAgKAAgMAAgOAAgAAggCAggEAggGAggIAggKAggMAggOAggABAgCBAgEBAgGBAgIBAgKBAgMBAgOBAgABggCBggEBggGBggIBggKBggMBggOBggACAgCCAgECAgGCAgICAgKCAgMCAgOCAgACggCCggECggGCggICggKCggMCggOCggADAgCDAgEDAgGDAgIDAgKDAgMDAgODAgADggCDggEDggGDggIDggKDggMDggODggAAAwCAAwEAAwGAAwIAAwKAAwMAAwOAAwAA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AggMAggOAggABAgCBAgEBAgGBAgIBAgKBAgMBAgOBAgABggCBggEBggGBggIBggKBggMBggOBggACAgCCAgECAgGCAgICAgKCAgMCAgOCAgACggCCggECggGCggICggKCggMCggOCggADAgCDAgEDAgGDAgIDAgKDAgMDAgODAgADggCDggEDggGDggIDggKDggMDggODggAAAwCAAwEAAwGAAwIAAwKAAwMAAwOAAwAAgwCAgwEAgwGAgwIAgwKAgwMAgwOAgwABAwCBAwEBAwGBAwIBAwKBAwMBAwOBAwABgwCBgwEBgwGBgwIBgwKBgwMBgwOBgwACAwCCAwECAwGCAwICAwKCAwMCAwOCAwACgwCCgwECgwGCgwICgwKCgwMCgwOCgwADAwCDAwEDAwGDAwIDAwKDAwP/78KCgpICAgP8AAAD/AP//AAAA//8A/wD//////yH5BAAAAAAALAAAAAC1AbgBAAj/AG8IHEiwoMGDCBMqXMiwocOHECNKnEixosWLGDNq3Mixo8ePIEOKHEmypMmTKFOqXMmypcuXMGPKnEmzps2bOHPq3Mmzp8+fQIMKHUq0qNGjSJMqXcq0qdOnUKNKnUq1qtWrWLNq3cq1q9evYMOKHUu2rNmzaNOqXcu2rdu3cOPKnUu3rt27ePPq3cu3L0IAgAMLHky4sOHDiBMrXsy4sePHkCNLnky5suXLmDNXJgmAlOfPoEOLHk26tOnTqFOrXs26tevXsGPLnk27tu3bs0d2vrjbYu+KvykGnzhcYvGIxyEmf7jcYfOGzxlGXzhdYfWE1/+S0r3dd3fg34WHrSc+3nh55OeVp2e+3nl76O+lx6c+33p97Pe1885Pfr9/7/+BF6B4A/YH4IECIkigggaGlN1BDxoUYUETElThQBcKlOENG3bIn4QfUhiihSNiWKKGJ3KY4obyFWiei+jBqJ6M7NHono3w4dgigy+K5KGO9AFpn5D4EakfjzEiOaOSNTKp0Y9O5hjljglWuaCVDV6pZZZc9oilR1B+maSYS5LZpJk3ThmkmkOyWaSb/1t6GeeYc5ZZ55l3pommlHtSmSeff2IUZqBr9lkooW0amiiibyraKKNHOgophCtWaiSll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bRc3Vwg1tOF3cbm3TT+3bvG3bKDzWu+3TmG3cqN3btTza0r3ccf3arv3cR03cx43b173Szp3c4d3V2g3e3w2N1p3e5f3T1M3e8M2j6z3dzA3b5UQ83vgd1qm9ydKpGf793wAe4AI+4ARe4AZ+4ATuuSCCGwze4A7+4BAe4RI+4RRe4RK+2ttN3vGN3cEd3dw93Cmj3NAN3Jn94R6u4fJ93iLe3Zs73xyO3vOK4i++4kbs4iM+20ms4u194gGq4xt+41Pt4/Rt3xne0JdN4kL+qzbO4jhu3iaO5E8uwksO4k1e40kO5FM+kjKO5Ve+zVvO5B0O5UNe5Pr93jGe30de5TzO1l9O5WGu5iG+42KO5pyd5XNe5vUNHwi+53ze537+54Ae6IKObSRh4YZ+6Iie6Iq+6Ize6KqC4ReQHumSPumUXumWfumYnumavumc3ume/umgHuqiPuqkXuqmfuqonuqqvuqs3uqu/uqwHuuyPuu0Xuu2fuu4nuu6vuu83uu+/uvAHuzCPuzEbhX/cOzInuzKvuzM3uzO/uzQHu3SPu3UXu3Wfu3Ynu3avu3c3u3e/u3gHu7ifuwBAQA7" alt="" />


src

        Server部分

Server_test.java

package 五子棋;

public class Server_test {

    /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Server_frame sf =new Server_frame();
} }

Server_frame.java

package 五子棋;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.net.ServerSocket;
import java.net.Socket; import javax.sound.midi.Receiver;
import javax.swing.AbstractAction;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke; public class Server_frame extends JFrame { public static boolean isstart = false;
public static Socket socket;
Server_panel_center_qipan qipan;
Server_panel_west_talk talk;
public static ServerSocket server;
public Server_frame() {
qipan = new Server_panel_center_qipan();
talk = new Server_panel_west_talk();
this.setSize(800, 600);
this.setTitle("五子棋_服务器");
this.add(qipan, BorderLayout.CENTER);
this.add(talk, BorderLayout.WEST);
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu gameMenu = new JMenu("游戏(G)"); // 创建游戏菜单
JMenu serMenu = new JMenu("帮助(H)"); // 创建游戏菜单
gameMenu.setMnemonic('G');
// 创建游戏子菜单及监听
JMenuItem connect_ser = new JMenuItem("开启服务器连接服务器", 'F');
connect_ser.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F,
InputEvent.CTRL_MASK));
connect_ser.addActionListener(new AbstractAction("开启服务器") {
public void actionPerformed(ActionEvent event) {
boolean flag = Serverstart();
if (flag == false) {
JOptionPane.showMessageDialog(null, "开启失败", "错误",
JOptionPane.ERROR_MESSAGE);
return;
} else { //服务器开启成功后开启线程
Recive_thred rth = new Recive_thred(socket,
Server_panel_west_talk.chantAear);
rth.start();
} }
}); JMenuItem exitItem = new JMenuItem("退出", 'E');
exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E,
InputEvent.CTRL_MASK));
exitItem.addActionListener(new AbstractAction("退出") {
public void actionPerformed(ActionEvent event) {
System.exit(0);
}
});
gameMenu.add(connect_ser);
gameMenu.addSeparator();
gameMenu.add(exitItem);
menuBar.add(gameMenu);
//客户端连接服务器后才打开线程
Recive_thred rth = new Recive_thred(socket,
Server_panel_west_talk.chantAear);
rth.start();
this.setVisible(true);
}
/*
* 开启服务器,并且等待客户端连接
*/
public static boolean Serverstart() {
try {
// 开启服务器
server = new ServerSocket(6666);
isstart = true; // 表示服务器开启了额
// 发送客户端用户基本信息(用户名和ip地址)
JOptionPane.showMessageDialog(null, "服务器开始于:"
+ server.getInetAddress().getLocalHost() + ":"
+ server.getLocalPort());
Server_panel_west_talk.chantAear.append("\n" + "服务器开始于:"
+ server.getInetAddress().getLocalHost() + ":"
+ server.getLocalPort() + "\n"); socket=server.accept(); // 等待客户端连接 return isstart;
} catch (Exception e) {
isstart = false;// 未连接上
return false;
}
} }

Server_panel_center_qipan.java

package 五子棋;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList; import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel; public class Server_panel_center_qipan extends JPanel{
Image board, black, white;
int hgex, hgey; // 棋子坐标的变量
int bgex, bgey; // 棋子坐标的变量
int cou = 0; // 表示连着棋子的数量
public static boolean isrenshu = false; // renshu=true表示自认输了
public static boolean ishuiqi = false; // huiqi=true表示自己悔棋了
public static boolean isok = false; // baiqi表示自己准备好了
public static boolean ischongxinkaishi = false; // 重新开始?
public static boolean ishei = false; // 黑棋下了???ishei=true表示下了
boolean isgamestart = false;// true游戏开始
private MouseEvent xiaqie;
ArrayList<String> h_list = new ArrayList<String>(); // 黑
ArrayList<String> b_list = new ArrayList<String>(); // 白
public Server_panel_center_qipan(){
this.setLayout(null); // 居中
JButton ks = new JButton("开始/暂停");
ks.setBounds(10, 460, 100, 25);
this.add(ks);
JButton rs = new JButton("认输");
rs.setBounds(115, 460, 80, 25);
this.add(rs);
JButton ht = new JButton("后退");
ht.setBounds(200, 460, 80, 25);
this.add(ht);
JButton cxks = new JButton("重新开始");
cxks.setBounds(290, 460, 100, 25);
this.add(cxks); hgex = 0;
hgey = 0;
bgex = 0;
bgey = 0;
try {
board = ImageIO.read(new File("img/board.gif"));
black = ImageIO.read(new File("img/black.gif"));
white = ImageIO.read(new File("img/white.gif"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 鼠标监听器,下棋位置
MouseAdapter mouse = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseClicked(e);
xiaqie=e; //把鼠标点的位置赋值给全局变量 }
};
// 鼠标监听器--------------开始/暂停
MouseAdapter start = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseClicked(e);
JOptionPane.showMessageDialog(null, "dianjile");
isok=true;
}
};
MouseAdapter renshu = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseClicked(e);
// System.out.println("renshu鼠标按下去了");
if (h_list.size() < 5)
JOptionPane.showMessageDialog(null,
"这都还没走五步就认输?不给,该谁了,请继续!!");
else {
isrenshu = true;
}
}
};
// 后退
MouseAdapter houtui = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseClicked(e);
if (h_list.size() == 0 || b_list.size() == 0)
JOptionPane.showMessageDialog(null, "你妹哦,这都没开始,哪来的让你毁");
else {
ishuiqi = true;
}
}
};
// 重新开始
MouseAdapter chongxinkaishi = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseClicked(e);
if (h_list.size() == 0 || b_list.size() == 0)
JOptionPane.showMessageDialog(null, "你妹哦,这都没开始,怎么会重新有病把");
else {
isrenshu=true; }
}
};
this.addMouseListener(mouse);
cxks.addMouseListener(chongxinkaishi);
ks.addMouseListener(start); // 开始按钮与鼠标相连
rs.addMouseListener(renshu); // 认输按钮与鼠标相连
ht.addMouseListener(houtui); // 后退按钮与鼠标相连 }
/*
*
* 获取鼠标位置 保存鼠标位置到数集里面
*/
public void getmouse(MouseEvent e) {
if (isgamestart ) {// !ishei表示黑棋没下,到白棋
int x = e.getX();
int y = e.getY();
// 减去边距,除以格子的宽度,取整,得到第几格子
hgex = (x - 18) / 25;
hgey = (y - 18) / 25;
if ((x - 18) % 25 > 12)
hgex = hgex + 1;
if ((y - 18) % 25 > 12)
hgey = hgey + 1;
// 把格子的x坐标和y坐标变成字符串用逗号连接,保存到list里面
if (!h_list.contains(hgex + "," + hgey)
&& !b_list.contains(hgex + "," + hgey)) {
h_list.add(hgex + "," + hgey);
ishei = true; //黑棋下了,
}
repaint();
if (h_list.size() >= 5) {
heipanduan();
} } }
/*
*
* 画棋盘*/
protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub
super.paintComponent(g);
g.drawImage(board, 0, 0, null);
// 黑棋获取鼠标点的位置,画黑棋
for (int i = 0; i < h_list.size(); i++) {
String s = h_list.get(i); // 获得集合里面的单个字符串
String[] a = s.split(",");
hgex = Integer.parseInt(a[0]);
hgey = Integer.parseInt(a[1]);
g.drawImage(black, hgex * 25 + 18 - 12, hgey * 25 + 18 - 12, null);
}
// 白棋获取鼠标点的位置,画白棋
for (int i = 0; i < b_list.size(); i++) {
String s = b_list.get(i); // 获得集合里面的单个字符串
String[] b = s.split(",");
bgex = Integer.parseInt(b[0]);
bgey = Integer.parseInt(b[1]);
g.drawImage(white, bgex * 25 + 18 - 12, bgey * 25 + 18 - 12, null);
}
} // 输赢判断的方法,黑判断
public void heipanduan() {
// if (h_list.size() > 5) {// 黑棋至少点了五次之后才执行
// f判断是白棋还是黑棋,true表示黑棋,false表示白棋
System.out.println("黑棋判断");
// 黑棋判断输赢
for (int i = 0; i < h_list.size(); i++) {
cou = 0; // 在判断每一个棋子的时候,都要给cou赋值为0
String s = h_list.get(i); // 获得集合里面的单个字符串
String[] a = s.split(",");
hgex = Integer.parseInt(a[0]);
int tempx = hgex;
hgey = Integer.parseInt(a[1]);
int tempy = hgey;
// 横向判断
// 黑棋的某个点x坐标+1,Y不变,表示横向判断有没有五子相连
for (int j = 0; j < 4; j++) {
hgex++;
if (h_list.contains(hgex + "," + hgey)) {
cou++;
}
}
System.out.println("黑棋横向判断有" + cou + "+1个");
// 纵向判断
if (cou < 4) {
hgex = tempx;
hgey = tempy;
cou = 0;
for (int j = 0; j < 4; j++) {
hgey++;
if (h_list.contains(hgex + "," + hgey))
cou++;
}
}
System.out.println("黑棋纵向判断有" + cou + "+1个");
// 右上方向判断
if (cou < 4) { // 小余4表示横向没有五子,就把cou值设为0,重新开始
cou = 0;
hgex = tempx;
hgey = tempy;
for (int j = 0; j < 4; j++) {
hgey--;
hgex++;
if (h_list.contains(hgex + "," + hgey))
cou++;
}
}
System.out.println("黑棋右上判断有" + cou + "+1个");
// 右下判断
if (cou < 4) {
cou = 0;
hgex = tempx;
hgey = tempy;
for (int j = 0; j < 4; j++) {
hgey++;
hgex++;
if (h_list.contains(hgex + "," + hgey))
cou++;
}
}
System.out.println("黑棋右下判断有" + cou + "+1个");
if (cou == 4) {
JOptionPane.showMessageDialog(null, "黑棋赢啦");
isgamestart = false;
}
}
}
}

Server_panel_west_talk.java

package 五子棋;

import java.awt.TextArea;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket; import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField; public class Server_panel_west_talk extends JPanel{
public static String who="服务器说:";
public static TextArea chantAear;
private JTextField txt_message;
private String message="ok"; // 要发送客户端的内容
public static Socket client;
Send_message sendmessage; //发送的方法
public Server_panel_west_talk(){
sendmessage = new Send_message(message, Server_frame.socket);
JButton jb_send = new JButton("发送");
txt_message = new JTextField("请输入你要发的内容");
chantAear = new TextArea("------------------\n", 15, 40);
MouseAdapter send = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseClicked(e);
send(); // 服务在自己的textarea输出信息
}
}; jb_send.addMouseListener(send);
this.add(chantAear);
this.add(txt_message);
this.add(jb_send);
} private void send() {
// TODO Auto-generated method stub
if (!Server_frame.isstart) {
JOptionPane.showMessageDialog(null, "服务器还未启动,不能发送消息!", "错误",
JOptionPane.ERROR_MESSAGE);
return;
} else {
String message = txt_message.getText();
if (message == null || message.equals("")) {
JOptionPane.showMessageDialog(null, "消息不能为空!", "错误",
JOptionPane.ERROR_MESSAGE);
return;
}
chantAear.append("\n服务器说:" + txt_message.getText() + "");
message = "CHANT" + "-" +who+ txt_message.getText() + "\n";
//System.out.println("服务器要发送的的message为"+message);
sendmessage.send(message, Server_frame.socket);
}
} }

        Client部分

Client_test.java

package 五子棋;

public class Client_test {
public static void main(String[] args) {
Client_frame cf=new Client_frame();
}
}

Client_frame.java

package 五子棋;

import java.awt.BorderLayout;
import java.awt.Frame; import javax.swing.JFrame; public class Client_frame extends JFrame{
Client_panel_center_qipan qipan;
Cilent_panel_west_talk talk;
public Client_frame(){
qipan=new Client_panel_center_qipan();
talk=new Cilent_panel_west_talk();
this.setSize(1000, 600);
//设置关闭
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//设置居中
// this.setLocationRelativeTo(null);
this.setTitle("五子棋_客户端");
this.add(qipan,BorderLayout.CENTER);
this.add(talk,BorderLayout.WEST); this.setVisible(true);
}
}

Client_panel_center_qipan.java

package 五子棋;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.ArrayList; import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel; public class Client_panel_center_qipan extends JPanel{ Image board, black, white;
int bgex, bgey; // 白棋子坐标的变量
int hgex, hgey; // 黑棋子坐标的变量
static boolean xiaqi = true; // xiaqu=true,黑棋下,否则不能下白棋下
int cou = 0; // 表示连着棋子的数量
static int c=1;
static boolean f = true; // 判断是白棋还是黑棋,true表示黑棋,false表示白棋
static boolean isgamestart = false;// true游戏开始
private static String message; //发送的消息
Send_message sendmessage; //发送的方法
public static boolean isrenshu = false; // renshu=true表示自认输了
public static boolean ishuiqi = false; // huiqi=true表示自己悔棋了
public static boolean isok = false; // baiqi表示自己准备好了
public static boolean ischongxinkaishi = false; // 重新开始?
public static boolean isbai = false; // 白棋下了??isbai=true
private MouseEvent xiaqie; //下白棋的时候,白棋点的鼠标位置的全局变量
ArrayList<String> h_list = new ArrayList<String>(); // 黑
ArrayList<String> b_list = new ArrayList<String>(); // 白 public Client_panel_center_qipan() {
sendmessage = new Send_message(message, Cilent_panel_west_talk.socket);
this.setLayout(null); // 居中
JButton ks = new JButton("开始/暂停");
ks.setBounds(10, 460, 100, 25);
this.add(ks);
JButton rs = new JButton("认输");
rs.setBounds(115, 460, 80, 25);
this.add(rs);
JButton ht = new JButton("后退");
ht.setBounds(200, 460, 80, 25);
this.add(ht);
JButton cxks = new JButton("重新开始");
cxks.setBounds(290, 460, 100, 25);
this.add(cxks); bgex = 0;
bgey = 0;
hgex = 0;
hgey = 0;
try {
board = ImageIO.read(new File("img/board.gif"));
black = ImageIO.read(new File("img/black.gif"));
white = ImageIO.read(new File("img/white.gif"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 鼠标监听器,下棋位置
MouseAdapter mouse = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseClicked(e);
// System.out.println("xiaqi鼠标按下去了");
if (isok && Server_panel_center_qipan.isok)
xiaqie=e; //将鼠标点的位置赋值给全局变量
getmouse(xiaqie);
} };
// 鼠标监听器--------------开始/暂停
MouseAdapter start = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseClicked(e);
// System.out.println("kaishi鼠标按下去了");
message="ANNIU"+"-"+"START";
sendmessage.send(message, Cilent_panel_west_talk.socket);
}
};
MouseAdapter renshu = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseClicked(e);
// System.out.println("renshu鼠标按下去了");
if (h_list.size() < 5)
JOptionPane.showMessageDialog(null,
"这都还没走五步就认输?不给,该谁了,请继续!!");
else {
if (h_list.size() < 5)
JOptionPane.showMessageDialog(null,
"这都还没走五步就认输?不给,该谁了,请继续!!");
else {
isrenshu = true;
}
}
}
};
// 后退
MouseAdapter houtui = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseClicked(e);
// int x=b_list.size();
if (h_list.size() == 0 || b_list.size() == 0)
JOptionPane.showMessageDialog(null, "你妹哦,这都没开始,哪来的让你毁");
else {
ishuiqi = false;
}
}
};
// 重新开始
MouseAdapter chongxinkaishi = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseClicked(e);
// int x=b_list.size();
if (h_list.size() == 0 || b_list.size() == 0)
JOptionPane.showMessageDialog(null, "你妹哦,这都没开始,怎么会重新有病把");
else {
isrenshu = true;
}
}
};
this.addMouseListener(mouse);
ks.addMouseListener(start); // 开始按钮与鼠标相连
rs.addMouseListener(renshu); // 认输按钮与鼠标相连
ht.addMouseListener(houtui); // 后退按钮与鼠标相连
cxks.addMouseListener(chongxinkaishi); }
public static boolean clientisok(){
if(c==2)
isok=true;
return isok;
}
/*
*
* 获取鼠标位置 保存鼠标位置到数集里面
*/
public void getmouse(MouseEvent e) {
if (isgamestart && !isbai && Server_panel_center_qipan.ishei) {// !ishei表示黑棋没下,到白棋
int x = e.getX();
int y = e.getY();
// 减去边距,除以格子的宽度,取整,得到第几格子
bgex = (x - 18) / 25;
bgey = (y - 18) / 25;
if ((x - 18) % 25 > 12)
bgex = bgex + 1;
if ((y - 18) % 25 > 12)
bgey = bgey + 1;
// 把格子的x坐标和y坐标变成字符串用逗号连接,保存到list里面
if (!b_list.contains(hgex + "," + hgey)
&& !b_list.contains(hgex + "," + hgey)) {
b_list.add(bgex + "," + bgey);
isbai = true;
Server_panel_center_qipan.ishei = false;
}
repaint();
if (h_list.size() >= 5) {
baipanduan();
} } } @Override
protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub
super.paintComponent(g);
g.drawImage(board, 0, 0, null);
// 画黑棋
for (int i = 0; i < h_list.size(); i++) {
String s = h_list.get(i); // 获得集合里面的单个字符串
String[] a = s.split(",");
hgex = Integer.parseInt(a[0]);
hgey = Integer.parseInt(a[1]);
g.drawImage(black, hgex * 25 + 18 - 12, hgey * 25 + 18 - 12, null);
}
// 画白棋
for (int i = 0; i < b_list.size(); i++) {
String s = b_list.get(i); // 获得集合里面的单个字符串
String[] b = s.split(",");
bgex = Integer.parseInt(b[0]);
bgey = Integer.parseInt(b[1]);
g.drawImage(white, bgex * 25 + 18 - 12, bgey * 25 + 18 - 12, null);
}
} /*
*
* 白棋判断输赢
*/
public void baipanduan() {
if (isgamestart == true) {
while (true) {
System.out.print("开始判断了"); System.out.println("f=false,白棋下了"); // if (h_list.size() > 5) {// 白棋至少点了五次之后才执行
// f判断是白棋还是黑棋,true表示黑棋,false表示白棋
System.out.println("白棋判断");
// 白棋判断输赢
for (int i = 0; i < b_list.size(); i++) {
cou = 0; // 在判断每一个棋子的时候,都要给cou赋值为0
String s = b_list.get(i); // 获得集合里面的单个字符串
String[] a = s.split(",");
bgex = Integer.parseInt(a[0]);
int tempx = bgex;
bgey = Integer.parseInt(a[1]);
int tempy = bgey;
// 横向判断
// 黑棋的某个点x坐标+1,Y不变,表示横向判断有没有五子相连
for (int j = 0; j < 4; j++) {
bgex++;
if (b_list.contains(bgex + "," + bgey)) {
cou++;
}
}
System.out.println("白棋横向判断有" + cou + "+1个");
// 纵向判断
if (cou < 4) {
bgex = tempx;
bgey = tempy;
cou = 0;
for (int j = 0; j < 4; j++) {
bgey++;
if (b_list.contains(bgex + "," + bgey))
cou++; }
}
System.out.println("白棋纵向判断有" + cou + "+1个");
// 右上方向判断
if (cou < 4) { // 小余4表示横向没有五子,就把cou值设为0,重新开始
cou = 0;
bgex = tempx;
bgey = tempy;
for (int j = 0; j < 4; j++) {
bgey--;
bgex++;
if (b_list.contains(bgex + "," + bgey))
cou++; }
}
System.out.println("白棋右上判断有" + cou + "+1个");
// 右下判断
// 右下判断
if (cou < 4) {
cou = 0;
bgex = tempx;
bgey = tempy;
for (int j = 0; j < 4; j++) {
bgey++;
bgex++;
if (b_list.contains(bgex + "," + bgey))
cou++; }
}
System.out.println("白棋右下判断有" + cou + "+1个");
if (cou == 4) {
JOptionPane.showMessageDialog(null, "白棋赢啦");
isgamestart = false;
return;
} } } }
}
}

Cilent_panel_west_talk.java

package 五子棋;

import java.awt.TextArea;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException; import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField; public class Cilent_panel_west_talk extends JPanel { public static boolean connect = false; // 给出连接服务器的boolean,true表示连接成功了
static TextArea chatAear; // 所有消息内容区域
public static Socket socket; // 连接服务器的socket = new
// Socket(serverip.getText(), 5555);
private String message="ok"; // 要发送给服务器的内容
Send_message sendmessage; //发送的方法
private String who = "客户端说:";
private JTextField txt_message; // 将要发送给服务器的内容
private JTextField serverip; // 服务器的IP地址 public Cilent_panel_west_talk() {
sendmessage = new Send_message(message, socket);
chatAear = new TextArea("----------------------\n", 15, 40);
txt_message = new JTextField("请输入你要发送的消息");
JButton jb_connectserver = new JButton("连接服务器");
serverip = new JTextField("127.0.0.1");
JButton jb_send = new JButton("发送");
MouseAdapter connect = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseClicked(e);
if (connectserver()) { JOptionPane.showMessageDialog(null, "我成功连接!!!!");
message = "CHANT" + "-" + "我是客户端,我已经连接成功了" + "\n";
System.out.println("客户端的message为"+message);
//客户端连接服务器后才打开线程
Recive_thred rth = new Recive_thred(socket,
chatAear);
rth.start();
sendmessage.send(message, socket);
}
} };
// 给服务器发送消息按钮
MouseAdapter send = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseClicked(e);
chatAear.append("\n客户端说"+txt_message.getText());
message = "CHANT" + "-" + who + txt_message.getText() + "\n";
System.out.println("客户端要发送的的message为"+message);
sendmessage.send(message, socket);
}
};
this.add(serverip);
jb_connectserver.addMouseListener(connect);
this.add(jb_connectserver); jb_send.addMouseListener(send);
this.add(chatAear);
this.add(txt_message);
this.add(jb_send); } public boolean connectserver() {
try {
// 获取输入的IP地址,并且进行连接
socket = new Socket(serverip.getText(), 6666);
connect = true;
return connect;
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
chatAear.append("\n连接失败");
}
return false;
}
}

      公共部分

Recive_thred.java

package 五子棋;

import java.awt.TextArea;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket; import javax.swing.JTextField; public class Recive_thred extends Thread {
private Socket socket;
TextArea chantAear; public Recive_thred(Socket socket, TextArea chantAear) {
this.socket = socket;
this.chantAear = chantAear; } @Override
public void run() {
// TODO Auto-generated method stub
super.run();
InputStream is;
try {
is = socket.getInputStream();
BufferedReader reader = new BufferedReader(
new InputStreamReader(is));
while (true) {
String msg = reader.readLine();
System.out.println("recive线程类接受到的信息" + msg);
String[] split = msg.split("-");
System.out.println("split[0]==" + split[0] + "==");
System.out.println("split[1]==" + split[1] + "==");
if (split[0] == "ANNIU") {
// 按钮控制
if (split[1].equals("START")) {
// 对方按下开始按钮
System.out.println("客户端按下开始了");
} else if (split[1].equals("TOUXIANG")) {
// 按下认输按钮
} else if (split[1].equals("HUIQI")) {
// 按下悔棋按钮
} else if (split[1].equals("CHONGXINLAI")) {
// 按下重新来按钮
}
}
if (split[0].equals("CHANT")) {
// 聊天控制
System.out.println(split[1]);
// chantAear.append(split[1]);
chantAear.append("\n"+split[1]);
}
if (split[0] == "XIAQI")// a==2
{
// 下棋控制
}
// System.out.println("recive类接受错误");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } }

Send_message.java

package 五子棋;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.Scanner; public class Send_message {
Socket socket;
String message; public Send_message(String message, Socket socket) {
this.message = message;
this.socket = socket;
} public void send(String message, Socket socket) {
OutputStream os;
try {
os = socket.getOutputStream();
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
System.out.println("send类里面要发送给对方的消息是"+message);
//用输出流把它给输出去
bw.write(message);
//令起一行
bw.newLine();
bw.flush(); // 清空缓存
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

[Java]局域网五子棋的更多相关文章

  1. Java的五子棋实现

    Java 五子棋 注:除机器人算法外其余借鉴于MLDN. package MyFiveChess; import robot.*; import java.awt.*; import javax.sw ...

  2. Java局域网对战游戏、天气预报项目

    功能 1.天气预报 2.局域网对战 展示  java学习群669823128   部分源码 package game.weather; import java.util.HashMap; public ...

  3. Java控制台五子棋(纯算法)

    Java五子棋小游戏 本方案是基于控制台写的一个代码 没有花里胡哨的界面,只为研究算法 仅仅用了200行代码 下面是的是运行结果 游戏运行结果 这里我就很简单的复制了一个结果 第9回合,下子方:玩家2 ...

  4. Java 判断五子棋五子相连

    #开始 最近在忙着做一个基于酷Q的QQ机器人,想到了做游戏,第一个想到的霸气点的游戏就是五子棋啊  ` _>` 因为没有图形界面的原因 所有核心就是判断是否在棋盘上出现了五个棋子连在一起的情况 ...

  5. Java实现五子棋

    代码: package com.hotusm.datastructure.list; import com.hotusm.datastructure.Log; /** * @author luqiba ...

  6. JAVA上百实例源码以及开源项目

    简介 笔者当初为了学习JAVA,收集了很多经典源码,源码难易程度分为初级.中级.高级等,详情看源码列表,需要的可以直接下载! 这些源码反映了那时那景笔者对未来的盲目,对代码的热情.执着,对IT的憧憬. ...

  7. 158个JAVA免豆精品资料汇总

    附件完整版下载地址: http://down.51cto.com/data/431561 附件部分预览~ java中国移动收费系统[源代码] http://down.51cto.com/data/70 ...

  8. 【转】【JAVA资料免费下载】158个JAVA免豆精品资料汇总——下载目录

    附件完整版下载地址: http://down.51cto.com/data/431561 附件部分预览~ java中国移动收费系统[源代码] http://down.51cto.com/data/70 ...

  9. JAVA上百实例源码网站

    JAVA源码包1JAVA源码包2JAVA源码包3JAVA源码包4 JAVA开源包1 JAVA开源包2 JAVA开源包3 JAVA开源包4 JAVA开源包5 JAVA开源包6 JAVA开源包7 JAVA ...

随机推荐

  1. 【jsp/servlet】 javaweb中的一些简单问题整理

    1 jsp工作原理 答: 动态网页技术标准blabla...jsp程序的工作方式为请求/响应模式,客户端发出http请求,jsp程序收到请求后进行处理,并返回处理的结果. jsp程序需要运行在特定的w ...

  2. apache php 配置 CI 框架

    声明:配置域名需要用到  httpd.conf  httpd_vhosts.conf  (apache) 中两个文件 和   hosts (C:\Windows\System32\drivers\et ...

  3. angular项目——小小记事本1

    这次的项目是制作一个记事本,有点类似于手机qq聊天信息. 内容:在一个input当中输入一行数据,之后提交,这个数据便会记录在下面.随着提交的增加,数据会以列表形式排列下来. 列表中,前面有一个组件, ...

  4. FlashDevelop调试Air出错

    按下F5调试命令行窗口出现错误: Starting AIR Debug Launcher... invalid application descriptor: Unknown namespace: h ...

  5. Activity not started, its current task has been brought to the front的解决办法

    删除bin目录下所有文件,重新启动在试试

  6. 【转】Build Your own Simplified AngularJS in 200 Lines of JavaScript

    原文:http://blog.mgechev.com/2015/03/09/build-learn-your-own-light-lightweight-angularjs/ Build Your o ...

  7. check_partition_aft_merge.sql

    spool ./05_check_partition_aft_merge.log @/tmp/rda/chk_freets set echo on feedback on set pagesize 4 ...

  8. 【贪心】时空定位II

    [贪心]时空定位II 题目描述 有一块空间,横向长w,纵向长为h,在它的横向中心线上不同位置处装有n(n≤10000)个点状的定位装置,每个定位装置i定位的效果是让以它为中心半径为Ri的圆都被覆盖.请 ...

  9. 素数个数的位数<Math>

    小明是一个聪明的孩子,对数论有着很浓烈的兴趣.他发现求1到正整数10^n (10的n次方)之间有多少个素数是一个很难的问题,该问题的难点在于决定于10^n 值的大小. 告诉你n的值,并且用ans表示小 ...

  10. 贝塞尔曲线 & CAShapeLayer & Stroke 动画 浅谈

    转载自:http://46aae4d1e2371e4aa769798941cef698.devproxy.yunshipei.com/qiaoqiaoqiao2014/article/details/ ...