📄 netchessthread.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 + -