导航:首页 > IDC知识 > java斗地主服务器

java斗地主服务器

发布时间:2020-10-16 06:07:52

1、要用java做一个局域网的斗地主游戏

你不是就做一个局域网的斗地主吗? 需要用到多线程同步处理。牌的张数固定,一人一张牌即可。每个人一个线程,需要3个现成控制。

2、如何用Java编写斗地主的游戏

这是一个java实现的斗地主,发牌结果的程序,实现3个人十三张牌,然后底牌3张。
*/
import java.util.Arrays;
public class pokerDemo{
public static void main(String[] args) {
/*生成一副牌的数字,简称牌库*/
int[]pkCode=new int[54];
for(int i=0;i<54;i++){
pkCode[i]=i;

3、求JAVA斗地主源代码

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

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

4、怎么用java写一个斗地主的游戏

打牌的规则可以用一个线程,毕竟打牌是顺序的,按步骤的,一个一个出牌。如果有聊天,那么聊天内容就是一个人一个线程了。

5、Java 斗地主代码 怎样运行

你到eclipse 里点击 file ->import ->Existing Projects into Workspace
然后选择你的文件夹,导入,就好了
导入好了以后,找到,你要运行的主文件,点run 就可以运行了

6、求一段用JAVA写的斗地主或者其他牌类的代码 。谢谢了!

你太抠了,连分都不给。算了,我还是给你代码吧
package bag;

import java.util.*;

public class Dou {

/*
* 生成扑克牌
*/
public String[] puke() {
String[] s1 = { "黑桃", "红桃", "梅花", "方片" };
String[] s2 = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J",
"Q", "K" };
String[] s3 = { "小王", "大王" };
String[] s4 = new String[54];
s4[52] = s3[0];
s4[53] = s3[1];

for (int i = 0; i < 52; i++) {
s4[i] = s1[i % 4] + s2[i / 4];
}
return s4;
}

/*
* 洗牌
*/
public String[] wash(String[] s2) {
// Dou dou = new Dou();
// String s2[] = dou.puke();
for (int i = 0; i < 100; i++) {
String k;
Random ran = new Random();
int ran1 = ran.nextInt(54);
int ran2 = ran.nextInt(54);
// 随机两张牌交换实现洗牌
k = s2[ran1];
s2[ran1] = s2[ran2];
s2[ran2] = k;
}
return s2;
}
/*
* 斗地主发牌
*/
public String[] check(String[] s1) {
// Dou dou = new Dou();
// String s1[] = dou.wash();
for (int i = 0; i < 54; i++) {
if (i % 17 == 0) {
System.out.println("");
int k = i / 17 + 1;
if (k == 4)
System.out.print("底牌:" + "\t");
else
System.out.print("玩家" + k + ":" + "\t");
}
System.out.print(s1[i] + "\t");
}
return s1;
}

/*
*
* @main
*/
public static void main(String[] args) {
Dou dou = new Dou();
//String[] s1= dou.check();
dou.check(dou.wash(dou.puke()));//相当于下面三句
// String[] s1=dou.puke();
// String[] s2= dou.wash(s1);
// dou.check(s2);
}
}

7、用JAVA编写单机版斗地主需要哪些知识?

觉得斗地主挺多东西的,发牌出牌什么的都好办,两家NPC的人工智能逻辑不好写。。。 刚学java建议先从五子棋写起

8、java斗地主人机对战如何开发,请大虾给个思路。谢谢

我可以开发的呀,咱们做的非常好的,专业开发斗地主游戏

9、求用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)

10、JAVA斗地主如何实现发牌和出牌功能

用随机的方式生成来54张牌(即数字或者其自他方式),按顺时针方向,依次给每个人一个数字。直到剩最后三张。

出牌:先判断出牌方选中的牌是否符合规则。是的话。则该人的数值列表中去掉相应的牌。桌面上显示它出示的牌。出完牌还得判断游戏是否结束。如果他的牌下完了。游戏就结束了

与java斗地主服务器相关的知识