zoukankan      html  css  js  c++  java
  • java——棋牌类游戏斗地主(webddz1.0)之二

    package com.ddz;
    import java.io.ObjectInputStream;
    import java.net.DatagramSocket;
    
    /***************************************************************************
     * TODO
     * <br>Created on 2013-7-3 上午11:19:29<br>
     * @author daicy
     ***************************************************************************/
    public interface Msg {
    	
    
    	  
    	/**
    	 * 该你叫地主
    	 */
    	public static final int CALL = 1;
    	
    	/**
    	 * 开始游戏了
    	 */
    	public static final int NEWGAME = 2;
    	
    	
    	/**
    	 * 出牌
    	 */
    	public static final int SENDEDPOKER = 3;
    	
    	
    	/**
    	 * 出牌
    	 */
    	public static final int RESTART = 4;
    	
    	
    	/**
    	 * 地主是
    	 */
    	public static final int LORDIS = 5;
    	
    	/**
    	 * 该你出牌
    	 */
    	public static final int YOURTURN = 6;
    	
    	/**
    	 * 该你出牌
    	 */
    	public static final int WIN = 7;
    	
    	/**
    	 * 发送数据
    	 * @param ds
    	 * @param IP
    	 * @param udpPort
    	 */
    	public void send(DatagramSocket ds, String IP, int udpPort);
    	
    	/**
    	 * 接收并处理数据
    	 * @param dis
    	 */
    	public void parse(ObjectInputStream dis);
    }
    
    package com.ddz;
    
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.net.DatagramPacket;
    import java.net.DatagramSocket;
    import java.net.InetSocketAddress;
    import java.net.SocketException;
    
    import com.GamePanel;
    import common.NetClient;
    
    
    /***************************************************************************
     * TODO
     * <br>Created on 2013-7-3 上午11:19:17<br>
     * @author daicy
     ***************************************************************************/
    public class LordIsMsg implements Msg {
    	protected int msgType = Msg.LORDIS;
    
    	protected int playerId ;
    
    	private GamePanel tc;
    	
    	private NetClient thread;
    	
    	
    	/**
    	 * 根据tank的信息构建消息
    	 * @param tank
    	 */
    	public LordIsMsg(int playerId) {
    		this.playerId = playerId;
    	}
    	
    	/**
    	 * 根据消息产生的场所构建新的消息
    	 * @param tc
    	 */
    	public LordIsMsg(GamePanel tc,NetClient thread) {
    		this.tc = tc;
    		this.thread = thread;
    	}
    	
    	
    	
    	public int getMsgType() {
    		return msgType;
    	}
    
    	public void setMsgType(int msgType) {
    		this.msgType = msgType;
    	}
    
    	public int getPlayerId() {
    		return playerId;
    	}
    
    	public void setPlayerId(int playerId) {
    		this.playerId = playerId;
    	}
    
    	public GamePanel getTc() {
    		return tc;
    	}
    
    	public void setTc(GamePanel tc) {
    		this.tc = tc;
    	}
    
    	/**
    	 * 发送相关的消息
    	 * @param ds 通过该socket发送数据
    	 * @param IP 数据的目标IP
    	 * @param udpPort 数据的目标端口
    	 */
    	public void send(DatagramSocket ds, String IP, int udpPort) {
    		ByteArrayOutputStream baos = new ByteArrayOutputStream();
    		ObjectOutputStream dos;
    		try {
    			dos = new ObjectOutputStream(baos);
    			dos.writeObject(getMsgType());
    			dos.writeObject(playerId);
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		byte[] buf = baos.toByteArray();
    		try {
    			DatagramPacket dp = new DatagramPacket(buf, buf.length,
    					new InetSocketAddress(IP, udpPort));
    			ds.send(dp);
    		} catch (SocketException e) {
    			e.printStackTrace();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    
    	}
    	/**
    	 * 分析接收到的消息数据
    	 * @param dis 接收到的消息数据的输入流
    	 */
    	public void parse(ObjectInputStream dis) {
    		try {
    			int id = (Integer) dis.readObject();
    			
    			thread.setlord(id);
    			tc.gameState = 2;
    			if(id==tc.id){
    				tc.reButtonVisible(true);
    			}
    			tc.reButtonName();
    			
    		} catch (IOException e) {
    			e.printStackTrace();
    		} catch (ClassNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    
    	}
    
    }
    

    package com.ddz;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.net.DatagramPacket;
    import java.net.DatagramSocket;
    import java.net.InetSocketAddress;
    import java.net.SocketException;
    
    import com.GamePanel;
    import com.SocketData;
    
    /***************************************************************************
     * TODO
     * <br>Created on 2013-7-3 上午11:19:36<br>
     * @author daicy
     ***************************************************************************/
    public class NewGameMsg implements Msg {
    	protected int msgType = Msg.NEWGAME;
    
    	protected SocketData socketData ;
    
    	private GamePanel tc;
    	
    	/**
    	 * 根据tank的信息构建消息
    	 * @param tank
    	 */
    	public NewGameMsg(SocketData socketData) {
    		this.socketData = socketData;
    	}
    	
    	/**
    	 * 根据消息产生的场所构建新的消息
    	 * @param tc
    	 */
    	public NewGameMsg(GamePanel tc) {
    		this.tc = tc;
    	}
    	
    	
    	
    	public int getMsgType() {
    		return msgType;
    	}
    
    	public void setMsgType(int msgType) {
    		this.msgType = msgType;
    	}
    
    
    	public GamePanel getTc() {
    		return tc;
    	}
    
    	public void setTc(GamePanel tc) {
    		this.tc = tc;
    	}
    
    	/**
    	 * 发送相关的消息
    	 * @param ds 通过该socket发送数据
    	 * @param IP 数据的目标IP
    	 * @param udpPort 数据的目标端口
    	 */
    	public void send(DatagramSocket ds, String IP, int udpPort) {
    		ByteArrayOutputStream baos = new ByteArrayOutputStream();
    		ObjectOutputStream dos ;
    		try {
    			dos = new ObjectOutputStream(baos);
    			dos.writeObject(getMsgType());
    			dos.writeObject(socketData);
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		byte[] buf = baos.toByteArray();
    		try {
    			DatagramPacket dp = new DatagramPacket(buf, buf.length,
    					new InetSocketAddress(IP, udpPort));
    			ds.send(dp);
    		} catch (SocketException e) {
    			e.printStackTrace();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    
    	}
    	/**
    	 * 分析接收到的消息数据
    	 * @param dis 接收到的消息数据的输入流
    	 */
    	public void parse(ObjectInputStream dis) {
    		try {
    			socketData = (SocketData) dis.readObject();
    			//socketData.reverse(tc);
    			socketData.initData(tc);
    			tc.reStart();
    			//tc.InitData(socketData.getCards());
    		} catch (IOException e) {
    			e.printStackTrace();
    		} catch (ClassNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    
    	}
    
    }
    

    package com.ddz;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.net.DatagramPacket;
    import java.net.DatagramSocket;
    import java.net.InetSocketAddress;
    import java.net.SocketException;
    import java.util.List;
    
    import com.GamePanel;
    
    /***************************************************************************
     * TODO
     * <br>Created on 2013-7-3 上午11:20:04<br>
     * @author daicy
     ***************************************************************************/
    public class SendPorkerMsg implements Msg {
    	int msgType = Msg.SENDEDPOKER;
    
    	int playerId ;
    	
    	List<String> sendList;
    
    	GamePanel tc;
    	
    	/**
    	 * 根据tank的信息构建消息
    	 * @param tank
    	 */
    	public SendPorkerMsg(int playerId,List<String> sendList) {
    		this.playerId = playerId;
    		this.sendList = sendList;
    	}
    	
    	/**
    	 * 根据消息产生的场所构建新的消息
    	 * @param tc
    	 */
    	public SendPorkerMsg(GamePanel tc) {
    		this.tc = tc;
    	}
    	
    	/**
    	 * 发送相关的消息
    	 * @param ds 通过该socket发送数据
    	 * @param IP 数据的目标IP
    	 * @param udpPort 数据的目标端口
    	 */
    	public void send(DatagramSocket ds, String IP, int udpPort) {
    		ByteArrayOutputStream baos = new ByteArrayOutputStream();
    		ObjectOutputStream dos ;
    		try {
    			dos = new ObjectOutputStream(baos);
    			dos.writeObject(msgType);
    			dos.writeObject(playerId);
    			dos.writeObject(sendList);
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		byte[] buf = baos.toByteArray();
    		try {
    			DatagramPacket dp = new DatagramPacket(buf, buf.length,
    					new InetSocketAddress(IP, udpPort));
    			ds.send(dp);
    		} catch (SocketException e) {
    			e.printStackTrace();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    
    	}
    	/**
    	 * 分析接收到的消息数据
    	 * @param dis 接收到的消息数据的输入流
    	 */
    	public void parse(ObjectInputStream dis) {
    		try {
    			int id = (Integer) dis.readObject();
    			sendList = (List<String>) dis.readObject();
    			this.tc.sendCards(id, sendList);
    
    		} catch (IOException e) {
    			e.printStackTrace();
    		} catch (ClassNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    
    	}
    
    }
    

    package com.ddz;
    
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.net.DatagramPacket;
    import java.net.DatagramSocket;
    import java.net.InetSocketAddress;
    import java.net.SocketException;
    
    import com.GamePanel;
    import common.NetClient;
    
    
    /***************************************************************************
     * TODO
     * <br>Created on 2013-7-3 上午11:19:17<br>
     * @author daicy
     ***************************************************************************/
    public class WinMsg implements Msg {
    	protected int msgType = Msg.WIN;
    
    	protected int playerId ;
    
    	private GamePanel tc;
    	
    	private NetClient thread;
    	
    	
    	/**
    	 * 根据tank的信息构建消息
    	 * @param tank
    	 */
    	public WinMsg(int playerId) {
    		this.playerId = playerId;
    	}
    	
    	/**
    	 * 根据消息产生的场所构建新的消息
    	 * @param tc
    	 */
    	public WinMsg(GamePanel tc,NetClient thread) {
    		this.tc = tc;
    		this.thread = thread;
    	}
    	
    	
    	
    	public int getMsgType() {
    		return msgType;
    	}
    
    	public void setMsgType(int msgType) {
    		this.msgType = msgType;
    	}
    
    	public int getPlayerId() {
    		return playerId;
    	}
    
    	public void setPlayerId(int playerId) {
    		this.playerId = playerId;
    	}
    
    	public GamePanel getTc() {
    		return tc;
    	}
    
    	public void setTc(GamePanel tc) {
    		this.tc = tc;
    	}
    
    	/**
    	 * 发送相关的消息
    	 * @param ds 通过该socket发送数据
    	 * @param IP 数据的目标IP
    	 * @param udpPort 数据的目标端口
    	 */
    	public void send(DatagramSocket ds, String IP, int udpPort) {
    		ByteArrayOutputStream baos = new ByteArrayOutputStream();
    		ObjectOutputStream dos;
    		try {
    			dos = new ObjectOutputStream(baos);
    			dos.writeObject(getMsgType());
    			dos.writeObject(playerId);
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		byte[] buf = baos.toByteArray();
    		try {
    			DatagramPacket dp = new DatagramPacket(buf, buf.length,
    					new InetSocketAddress(IP, udpPort));
    			ds.send(dp);
    		} catch (SocketException e) {
    			e.printStackTrace();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    
    	}
    	/**
    	 * 分析接收到的消息数据
    	 * @param dis 接收到的消息数据的输入流
    	 */
    	public void parse(ObjectInputStream dis) {
    		try {
    			int id = (Integer) dis.readObject();
    			tc.setWinById(id);
    			
    		} catch (IOException e) {
    			e.printStackTrace();
    		} catch (ClassNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    
    	}
    
    }
    

    package com.ddz;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.net.DatagramPacket;
    import java.net.DatagramSocket;
    import java.net.InetSocketAddress;
    import java.net.SocketException;
    
    import com.GamePanel;
    
    /***************************************************************************
     * TODO
     * <br>Created on 2013-7-3 上午11:19:44<br>
     * @author daicy
     ***************************************************************************/
    public class YourTurnMsg implements Msg {
    	protected int msgType = Msg.YOURTURN;
    
    	protected int playerId ;
    
    	private GamePanel tc;
    	
    	
    	/**
    	 * 根据tank的信息构建消息
    	 * @param tank
    	 */
    	public YourTurnMsg(int playerId) {
    		this.playerId = playerId;
    	}
    	
    	/**
    	 * 根据消息产生的场所构建新的消息
    	 * @param tc
    	 */
    	public YourTurnMsg(GamePanel tc) {
    		this.tc = tc;
    	}
    	
    	
    	
    	public int getMsgType() {
    		return msgType;
    	}
    
    	public void setMsgType(int msgType) {
    		this.msgType = msgType;
    	}
    
    	public int getPlayerId() {
    		return playerId;
    	}
    
    	public void setPlayerId(int playerId) {
    		this.playerId = playerId;
    	}
    
    	public GamePanel getTc() {
    		return tc;
    	}
    
    	public void setTc(GamePanel tc) {
    		this.tc = tc;
    	}
    
    	/**
    	 * 发送相关的消息
    	 * @param ds 通过该socket发送数据
    	 * @param IP 数据的目标IP
    	 * @param udpPort 数据的目标端口
    	 */
    	public void send(DatagramSocket ds, String IP, int udpPort) {
    		ByteArrayOutputStream baos = new ByteArrayOutputStream();
    		ObjectOutputStream dos;
    		try {
    			dos = new ObjectOutputStream(baos);
    			dos.writeObject(getMsgType());
    			dos.writeObject(playerId);
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		byte[] buf = baos.toByteArray();
    		try {
    			DatagramPacket dp = new DatagramPacket(buf, buf.length,
    					new InetSocketAddress(IP, udpPort));
    			ds.send(dp);
    		} catch (SocketException e) {
    			e.printStackTrace();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    
    	}
    	/**
    	 * 分析接收到的消息数据
    	 * @param dis 接收到的消息数据的输入流
    	 */
    	public void parse(ObjectInputStream dis) {
    		try {
    			int id = (Integer) dis.readObject();
    			if (getTc().id == id) {
    				getTc().turnIndex = id;
    				getTc().reButtonVisible(true);
    				if(this.getTc().gameState == 1){
    					
    				}
    			}
    			
    		} catch (IOException e) {
    			e.printStackTrace();
    		} catch (ClassNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    
    	}
    
    }
    


  • 相关阅读:
    [转]Oracle 语法之 OVER (PARTITION BY ..) 及开窗函数
    oracle本月、上月、去年
    Oracle 物理视图刷新报错ORA-00942
    [转]Oracle trunc()函数的用法
    [转]物化视图创建 及 刷新机制修改
    [转]oracle制定定时任务(dbms_jobs)
    【转】Windows平台下的Subversion安装配置新手指南
    【转】数字签名与数字证书
    [转]SQL 常用函数及示例
    【转】视图、索引、存储过程 、触发器、游标及事务
  • 原文地址:https://www.cnblogs.com/daichangya/p/12959566.html
Copyright © 2011-2022 走看看