当前位置:首页 > 代码 > 正文

网络斗地主java源代码(斗地主开源)

admin 发布:2022-12-19 11:04 87


本篇文章给大家谈谈网络斗地主java源代码,以及斗地主开源对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

求JAVA斗地主源代码

你可以试试哈~我这边正常运行

jdk1.6+eclipse正常运行,编码是gbk

求用java编写的斗地主程序就,要求可以在局域网内实现两桌以上同时玩。

客户端:

import java.io.*;

import java.net.*;

import java.awt.*;

import java.awt.event.*;

public class ChatClient extends Frame

{

TextArea ta = new TextArea();

TextField tf = new TextField();

public void launchFrame() throws Exception

{

this.add(ta, BorderLayout.CENTER);

this.add(tf, BorderLayout.SOUTH);

tf.addActionListener(

new ActionListener()

{

public void actionPerformed(ActionEvent ae)

{

try {

String sSend = tf.getText();

if(sSend.trim().length() == 0) return;

ChatClient.this.send(sSend);

tf.setText("");

ta.append(sSend + "\n");

}

catch (Exception e)

}

}

);

this.addWindowListener(

new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

}

);

setBounds(300,300,300,400);

setVisible(true);

tf.requestFocus();

}

Socket s = null;

public ChatClient() throws Exception

{

s = new Socket("127.0.0.1", 8888);

launchFrame();

(new Thread(new ReceiveThread())).start();

}

public void send(String str) throws Exception

{

DataOutputStream dos = new DataOutputStream(s.getOutputStream());

dos.writeUTF(str);

}

public void disconnect() throws Exception

{

s.close();

}

public static void main(String[] args) throws Exception

{

BufferedReader br = new BufferedReader (

new InputStreamReader(System.in));

ChatClient cc = new ChatClient();

String str = br.readLine();

while(str != null str.length() != 0)

{

cc.send(str);

str = br.readLine();

}

cc.disconnect();

}

class ReceiveThread implements Runnable

{

public void run()

{

if(s == null) return;

try {

DataInputStream dis = new DataInputStream(s.getInputStream());

String str = dis.readUTF();

while (str != null str.length() != 0)

{

//System.out.println(str);

ChatClient.this.ta.append(str + "\n");

str = dis.readUTF();

}

}

catch (Exception e)

{

e.printStackTrace();

}

}

}

}

服务器:

import java.net.*;

import java.util.*;

import java.io.*;

import java.awt.*;

import java.awt.event.*;

public class ChatServer extends Frame

{

TextArea ta = new TextArea();

public void launchFrame()

{

add(ta, BorderLayout.CENTER);

setBounds(0,0,200,300);

this.addWindowListener(

new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

}

);

setVisible(true);

}

ServerSocket server = null;

Collection cClient = new ArrayList();

public ChatServer(int port) throws Exception

{

server = new ServerSocket(port);

launchFrame();

}

public void startServer() throws Exception

{

while(true)

{

Socket s = server.accept();

cClient.add( new ClientConn(s) );

ta.append("NEW-CLIENT " + s.getInetAddress() + ":" + s.getPort());

ta.append("\n" + "CLIENTS-COUNT: " + cClient.size() + "\n\n");

}

}

class ClientConn implements Runnable

{

Socket s = null;

public ClientConn(Socket s)

{

this.s = s;

(new Thread(this)).start();

}

public void send(String str) throws IOException

{

DataOutputStream dos = new DataOutputStream(s.getOutputStream());

dos.writeUTF(str);

}

public void dispose()

{

try {

if (s != null) s.close();

cClient.remove(this);

ta.append("A client out! \n");

ta.append("CLIENT-COUNT: " + cClient.size() + "\n\n");

}

catch (Exception e)

{

e.printStackTrace();

}

}

public void run()

{

try {

DataInputStream dis = new DataInputStream(s.getInputStream());

String str = dis.readUTF();

while(str != null str.length() !=0)

{

System.out.println(str);

for(Iterator it = cClient.iterator(); it.hasNext(); )

{

ClientConn cc = (ClientConn)it.next();

if(this != cc)

{

cc.send(str);

}

}

str = dis.readUTF();

//send(str);

}

this.dispose();

}

catch (Exception e)

{

System.out.println("client quit");

this.dispose();

}

}

}

public static void main(String[] args) throws Exception

{

ChatServer cs = new ChatServer(8888);

cs.startServer();

}

}

(来自BJSXT)

java斗地主发牌程序

DeckOfCards()构造函数里面,注释掉的

//deck[count]=new Card(faces[count%13],suits[count/13]);

是对的,下面那行除17是错的

另外,没有把大小王赋值到数组里

最后main函数里,打印方法错了。应该为,原本少了一个%-20s

System.out.printf("%-20s%-20s%-20s\n", myDeckOfCards.dealCard(), myDeckOfCards.dealCard(), myDeckOfCards.dealCard());

发牌完成以后剩下的3张牌就是保留的底牌

关于网络斗地主java源代码和斗地主开源的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/7108.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载