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

📄 netchessthread.java

📁 Java五子棋 支持本地游戏
💻 JAVA
字号:
import java.net.*;
import java.io.*;

/**
 * 
 * this class creates a thread, it listens on chess port and receives game information from the other player
 *
 */
class NetChessThread extends Thread
{
	Player netPlayer;
	ChessGame game;
	
	NetChessThread(ChessGame game)
	{
		this.game = game;
		this.netPlayer = game.notLocalPlayer;
	}
	
	public void run()
	{
		//loop until game is over
		while(game.status != GameStatus.Over)
		{
			//if it is not net player's turn, just ignores the operation
			if(this.netPlayer != game.activePlayer)
				continue;
			
			try{
				int x, y;
				
				//System.out.println("Begin listening on the other side!");
				//receives the x and y position of chess
		    	x = game.sock.getInputStream().read();
		    	y = game.sock.getInputStream().read();
				
				//System.out.println("Received data" + "x:" + x + " " + "y:" + y);
		    	game.playChess(x, y);
			}
			catch(IOException ex)
			{
	    		System.out.println("Connection Error!");
			}
		}
	}
}

⌨️ 快捷键说明

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