• 大小: 9.36 KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-09-16
  • 语言: Java
  • 标签: Chess  

资源简介

可多人同时联机对弈的五子棋哦!

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;

class chessThread extends Thread
{
chessPad chesspad;

chessThread(chessPad chesspad)
{
this.chesspad=chesspad;
}

public void sendMessage(String sndMessage)
{
try
{
chesspad.outData.writeUTF(sndMessage);
}
catch(Exception ea)
{
System.out.println("chessThread.sendMessage:"+ea);
}
}
***********************************

资源截图

代码片段和文件信息

import java.awt.*; 
import java.awt.event.*; 
import java.io.*; 
import java.net.*; 
import java.util.*; 


class clientThread extends Thread 

chessClient chessclient; 

clientThread(chessClient chessclient) 

this.chessclient=chessclient; 


public void acceptMessage(String recMessage) 

if(recMessage.startsWith(“/userlist “)) 

StringTokenizer userToken=new StringTokenizer(recMessage“ “); 
int userNumber=0; 

chessclient.userpad.userList.removeAll(); 
chessclient.inputpad.userChoice.removeAll(); 
chessclient.inputpad.userChoice.addItem(“所有人“); 
while(userToken.hasMoreTokens()) 

String user=(String)userToken.nextToken(“ “); 
if(userNumber>0 && !user.startsWith(“[inchess]“)) 

chessclient.userpad.userList.add(user); 
chessclient.inputpad.userChoice.addItem(user); 


userNumber++; 

chessclient.inputpad.userChoice.select(“所有人“); 

else if(recMessage.startsWith(“/yourname “)) 

chessclient.chessClientName=recMessage.substring(10); 
chessclient.settitle(“Java五子棋客户端 “+“用户名:“+chessclient.chessClientName); 

else if(recMessage.equals(“/reject“)) 

try 

chessclient.chesspad.statusText.setText(“不能加入游戏“); 
chessclient.controlpad.cancelGameButton.setEnabled(false); 
chessclient.controlpad.joinGameButton.setEnabled(true); 
chessclient.controlpad.creatGameButton.setEnabled(true); 

catch(Exception ef) 

chessclient.chatpad.chatLineArea.setText(“chessclient.chesspad.chessSocket.close无法关闭“); 

chessclient.controlpad.joinGameButton.setEnabled(true); 

else if(recMessage.startsWith(“/peer “)) 

chessclient.chesspad.chessPeerName=recMessage.substring(6); 
if(chessclient.isServer) 

chessclient.chesspad.chessColor=1; 
chessclient.chesspad.isMouseEnabled=true; 
chessclient.chesspad.statusText.setText(“请黑棋下子“); 

else if(chessclient.isClient) 

chessclient.chesspad.chessColor=-1; 
chessclient.chesspad.statusText.setText(“已加入游戏,等待对方下子...“); 



else if(recMessage.equals(“/youwin“)) 

chessclient.isOnChess=false; 
chessclient.chesspad.chessVictory(chessclient.chesspad.chessColor); 
chessclient.chesspad.statusText.setText(“对方退出,请点放弃游戏退出连接“); 
chessclient.chesspad.isMouseEnabled=false; 

else if(recMessage.equals(“/OK“)) 

chessclient.chesspad.statusText.setText(“创建游戏成功,等待别人加入...“); 

else if(recMessage.equals(“/error“)) 

chessclient.chatpad.chatLineArea.append(“传输错误:请退出程序,重新加入 \n“); 

else 

chessclient.chatpad.chatLineArea.append(recMessage+“\n“); 
chessclient.chatpad.chatLineArea.setCaretPosition( 
chessclient.chatpad.chatLineArea.getText().length()); 




public void run() 

String message=““; 
try 

while(true) 

message=chessclient.in.readUTF(); 
acceptMessage(message); 


catch(IOException es) 











public class chessClient extends frame implements ActionListenerKeyListener 

userPad userpad=new userPad(); 
chatPad chatpad=new chatPad(); 
cont

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      10884  2008-10-30 15:44  wapChess\chessClient.java

     文件       1508  2008-10-30 15:45  wapChess\chessInteface.java

     文件      17694  2008-10-30 15:54  wapChess\chessPad.java

     文件      16059  2008-10-30 15:53  wapChess\chessServer.java

     目录          0  2008-10-30 16:18  wapChess

----------- ---------  ---------- -----  ----

                46145                    5


评论

共有 条评论