⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chessclient.java

📁 <Java编程精选集锦>随书源码
💻 JAVA
字号:
import java.awt.*;
import java.net.*;
import java.io.*;
import chessArray;

//
// chessClient
//
public class chessClient implements Runnable
{
	Thread thread;
	Socket socket;
	String name=null;
	OutputStream outS;
	InputStream inS;

	public chessClient(String st) 
	{
		name=st;
		thread=new Thread(this);
	}

	public synchronized void run() 
	{
		try{
			if(name==null)
				socket=new Socket(InetAddress.getLocalHost (),1666);
			else socket=new Socket(name,1666);
			chessArray.information("网络连接成功,正等待庄家走棋");
			System.out.println(name);
		}catch(IOException e){
			System.out.println(e);
			return ;
		}
		while(true){
			try{
				outS=socket.getOutputStream ();
				inS=socket.getInputStream ();
			}catch(IOException e){
				System.out.println(e);
				chessArray.information("网络连接有误,对家可能已退出");
			}
			while(true)
			try{
				if(chessArray.readyOut )
			    {
					outS.write (chessArray.changeCount1 );
					outS.write (chessArray.changeCount2 );
					if(chessArray.changeCount1 !=254){
						chessArray.information("等待对家走棋......");
					}else{
						chessArray.information("已告诉庄家,等待对家走棋......");
						chessArray.change=false;
					}
					chessArray.readyOut=false;
					chessArray.readyIn=true;
//					System.out.println("exit?");
				}else if(chessArray.readyIn )
				{
					chessArray.changeCount1=inS.read ();
					chessArray.changeCount2=inS.read();
					if(chessArray.changeCount1==254)
					{
						chessArray.information("庄家已选择重下,若继续,请等待");
						chessArray.startInf  ("走棋");
						chessArray.endInf  ("落子");
						chessArray.changeCount1=-1;
						chessArray.chA(chessArray.arrayBak);
						chessArray.readyOut=false;
						chessArray.repaint=true;
						chessArray.netChange =false;
						chessArray.change=false;
						chessArray.readyIn=true;
					}else
					{
						chessArray.netChange =true;
						chessArray.readyIn=false;
					}
				try{
					thread.sleep(1000);
				}catch(InterruptedException e)
				{		};
				}
			}catch(IOException e){
				chessArray.information("网络连接有误,对家可能已退出");
			}
		}
	}
	public void start()
	{
		thread.start();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -