import java.awt.Toolkit;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.StringTokenizer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.swtdesigner.SWTResourceManager;
import java.io.*;
import java.net.*;
public class GamePad {
final Display display = Display.getDefault();
private Text sendtext;
private Text textstatus;
private List userList;
protected Shell shell;
protected Socket socket;
protected String username;
protected String role;
protected String playwith;
DataInputStream in;
DataOutputStream out;
protected Image gamepad = new Image(display, "images/gamepad.JPG");
protected Image white = new Image(display, "images/white.bmp");
protected Image black = new Image(display, "images/black.bmp");
protected Image chess = new Image(display, "images/chess.JPG");
int port=9186;
boolean isMouseEnabled=false;
PlayAndCheck check = new PlayAndCheck();
Rectangle rect =new Rectangle(15,43,525,525);
Canvas canvasBlack[]= new Canvas[200];
int canvasBlackNum = 0;
Canvas canvasWhite[]=new Canvas[200];
int canvasWhiteNum = 0;
String result ="";
Cursor ccc = new Cursor(display,SWT.CURSOR_WAIT);
Cursor cc1 = new Cursor(display,SWT.CURSOR_ARROW);
/**
* Launch the application
* @param args
*/
public static void main(String[] args) {
try {
GamePad window = new GamePad();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window
*/
public void open() {
createContents();
centerShell(shell);
shell.open();
shell.layout();
final Button GameButton = new Button(shell, SWT.NONE);
final Button cancelGameButton = new Button(shell, SWT.NONE);
final Button btnBack = new Button(shell, SWT.NONE);
btnBack.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if(role.equals("creater")){
try{
out =new DataOutputStream(socket.getOutputStream());
out.writeUTF("/"+playwith+" /BlackBack");
}
catch(IOException eea){
MessageBox dialog=new MessageBox(shell,SWT.OK|SWT.ICON_INFORMATION);
dialog.setText("错误");
dialog.setMessage("服务器无法连接");
dialog.open();
System.exit(0);
}
}
else{
try{
out =new DataOutputStream(socket.getOutputStream());
out.writeUTF("/"+playwith+" /WhiteBack");
}
catch(IOException eea){
MessageBox dialog=new MessageBox(shell,SWT.OK|SWT.ICON_INFORMATION);
dialog.setText("错误");
dialog.setMessage("服务器无法连接");
dialog.open();
System.exit(0);
}
}
}
});
GameButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if(userList.getItemCount()==1){
messagedialog2("提示","等待其他玩家");
}
else{
for(int ii=0;ii<=1;ii++){
if(!userList.getItem(ii).equals(username)){
playwith=userList.getItem(ii);
}
}
if(role.equals("creater")){
try{
out = new DataOutputStream(socket.getOutputStream());
out.writeUTF("/serverReady");
GameButton.setEnabled(false);
cancelGameButton.setEnabled(true);
btnBack.setEnabled(true);
}
catch(IOException eeas){
messagedialog2("错误","服务器无法连接");
System.exit(0);
}
}
else{
try{
out = new DataOutputStream(socket.getOutputStream());
out.writeUTF("/clientReady");
GameButton.setEnabled(false);
GameButton.setEnabled(false);
cancelGameButton.setEnabled(true);
btnBack.setEnabled(true);
}
catch(IOException eeas){
messagedialog2("错误","服务器无法连接");
System.exit(0);
}
}
}
}
}
);
GameButton.setText("开始游戏 ");
GameButton.setBounds(55, 580, 60, 27);
cancelGameButton.setEnabled(false);
cancelGameButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if(role.equals("creater")){
try{
out =new DataOutputStream(socket.getOutputStream());
out.writeUTF("/WhiteWin");
}
catch(IOException eea){
MessageBox dialog=new MessageBox(shell,SWT.OK|SWT.ICON_INFORMATION);
dialog.setText("错误");
dialog.setMessage("服务器无法连接");
dialog.open();
System.exit(0);
}
}
else{
try{
out =new DataOutputStream(socket.getOutputStream());
out.writeUTF("/BlackWin");
}
catch(IOException eea){
MessageBox dialog=new MessageBox(shell,SWT.OK|SWT.ICON_INFORMATION);
dialog.setText("错误");
dialog.setMessage("服务器无法连接");
dialog.open();
System.exit(0);
}
}
}
});
cancelGameButton.setText("认输");
cancelGameButton.setBounds(155, 580, 60, 27);
btnBack.setEnabled(false);
btnBack.setText("悔棋");
btnBack.setBounds(255, 580, 60, 27);
final Button exitGameButton = new Button(shell, SWT.NONE);
exitGameButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if(role.equals("creater")){
try{
out =new DataOutputStream(socket.getOutputStream());
out.writeUTF("/serveroff");
}
catch(IOException eea){
MessageBox dialog=new MessageBox(shell,SWT.OK|SWT.ICON_INFORMATION);
dialog.setText("错误");
dialog.setMessage("服务器无法连接");
dialog.open();
System.exit(0);
}
}
else{
try{
out =new DataOutputStream(socket.getOutputStream());
out.writeUTF("/clientoff");
}
catch(IOException eea){
MessageBox dialog=new MessageBox(shell,SWT.OK|SWT.ICON_INFORMATION);
dialog.setText("错误");
dialog.setMessage("服务器无法连接");
dialog.open();
System.exit(0);
}
}
System.exit(0);
}
});
exitGameButton.setText("退出游戏");
exitGameButton.setBounds(350, 580, 60, 27);
userList = new List(shell, SWT.V_SCROLL | SWT.BORDER);
userList.setEnabled(false);
userList.setToolTipText("用户列表");
userList.setBounds(581, 45, 178, 230);
textstatus = new Text(shell, SWT.WRAP | SWT.V_SCROLL | SWT.BORDER);
textstatus.setBounds(581, 306, 178, 230);
sendtext = new Text(shell, SWT.BORDER);
sendtext.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if(e.keyCode==SWT.CR){
if(sendtext.getText().startsWith("/")){
MessageBox dialog1 = new MessageBox(shell,SWT.OK|SWT.ICON_INFORMATION);
dialog1.setMessage("无效命令");
dialog1.setText("错误");
dialog1.open();
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录





































































































共 101 条
- 1
- 2


格式:pdf 资源大小:352.0KB 页数:8

























Agentleman
- 粉丝: 3
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 技术转移机构如何利用AI+数智应用优化技术供需匹配?.docx
- 技术转移机构如何利用AI+数智应用应对市场竞争加剧和服务升级压力?.docx
- 技术转移机构如何通过AI+数智应用打造差异化竞争力?.docx
- 技术转移机构如何通过AI+数智应用实现服务效率与质量的双重提升?.docx
- 技术转移机构如何通过AI+数智应用手段拓展客户群体并实现业务增长?.docx
- 技术转移机构如何通过AI+数智应用转型提升专业服务能力?.docx
- 技术转移机构数字化转型挑战重重,如何通过AI+数智应用快速提升服务效率和质量?.docx
- 技术转移机构想提升品牌价值并拓展客户,有哪些基于AI+数智应用的可行方法?.docx
- 技术转移机构业务AI+数智应用转型有哪些有效途径?.docx
- 技术转移机构在AI+时代如何高效应对市场竞争与服务升级挑战?.docx
- 技术转移机构在AI+时代如何提升服务效率和质量?.docx
- 技术转移机构在AI+时代如何突破传统服务瓶颈实现业务升级?.docx
- 技术转移机构在AI+时代如何应对市场竞争与服务升级的双重压力?.docx
- 技术转移机构在AI+数智应用转型中常遇哪些难题?.docx
- 技术转移机构在AI+数智应用转型中面临哪些核心挑战?如何快速构建智能服务体系?.docx
- 技术转移机构在AI+数智应用转型中面临哪些挑战?如何解决?.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

评论0