導航:首頁 > 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鬥地主伺服器相關的知識