软件体系结构五子棋.docx
- 文档编号:13085248
- 上传时间:2023-06-10
- 格式:DOCX
- 页数:21
- 大小:1.14MB
软件体系结构五子棋.docx
《软件体系结构五子棋.docx》由会员分享,可在线阅读,更多相关《软件体系结构五子棋.docx(21页珍藏版)》请在冰点文库上搜索。
软件体系结构五子棋
河南工业大学实验报告
(2015~2016学年-第2学期)
课程名称:
软件体系结构 课程编号:
51610192 地点:
6313/6316/6308/6320
专业班级
软件1
学号
姓名
实验项目名称
实验1:
五子棋系统C/S风格客户端软件体系结构设计
实验日期
2015.05.15
成绩评定
教师签名:
日期:
一、实验目的:
验证C/S风格的工作机制。
二、实验内容:
针对某个应用系统,选用C/S风格作为这个系统的软件体系结构风格。
熟悉C/S风格的工作机制,对所考察的系统进行C/S风格客户端软件体系结构设计的验证。
(针对不同的特定应用系统具体表述)。
三.编程环境
Windows7
VisualStudio|Dev-C++
Eclipse
四.实验代码
packagegame;
importjava.awt.Color;
importjava.awt.Graphics;
importjava.io.IOException;
importjava.io.InputStream;
importjava.io.OutputStream;
import.InetAddress;
import.Socket;
importjavax.swing.JFrame;
importjavax.swing.JOptionPane;
importpanel.Config;
importpanel.MyListener;
publicclassGameClientimplementsRunnable{
privateSocketclient;
privateintport;
privateStringip;
privateJFrameframe;
privateInputStreamin;
privateOutputStreamout;
privateStringname;
privatebooleanflag=false;
publicGameClient(JFrameframe){
this.frame=frame;
init();
}
/**
*判断是否建立了连接
*/
privatebooleanconfirm()throwsIOException{
byte[]buf=newbyte[64];
intn=in.read(buf);
name=newString(buf,0,n);
return(name.length()>0)?
true:
false;
}
/**
*接收初始化信息
*
*@throwsIOException
*/
privatevoidresetUI()throwsIOException{
bytebuf[]=newbyte[64];
intn=in.read(buf);
//System.out.println(s);
String[]numberStrs=newString(buf,0,n).split("#");
//System.out.println(numberStrs.toString());
Config.SIZE=Integer.parseInt(numberStrs[0]);
Config.ROW=Integer.parseInt(numberStrs[1]);
Config.CLOUNM=Integer.parseInt(numberStrs[2]);
frame.setSize(2*Config.STARTX+Config.CLOUNM*Config.SIZE,
Config.STARTY+Config.SIZE*(Config.ROW+1));
Config.resetChess(newbyte[Config.ROW+1][Config.CLOUNM+1]);
frame.paint(frame.getGraphics());
}
publicvoidrun(){
try{
InetAddressaddress=InetAddress.getByName(ip);
client=newSocket(address,port);
in=client.getInputStream();
out=client.getOutputStream();
if(!
confirm()){
newMyDialog(frame,"连接服务器失败",true).setVisible(true);
return;
}
resetUI();
frame.setTitle("五子棋"+"已连接:
"+name+"的游戏:
本机端口号:
"
+client.getLocalPort());
//1,设置棋子颜色
Config.setColor(Color.WHITE);
//2,交替下棋
MyListenerpolice=newMyListener();
while(true){
if(flag){
frame.addMouseListener(police);
while(Config.getX()==-1){
Thread.sleep(20);
}
intx=Config.getX();
inty=Config.getY();
Config.clearNotify();
Graphicsg=frame.getGraphics();
g.setColor(Config.getColor());
g.fillOval(x-(Config.SIZE/2),y-(Config.SIZE/2),
Config.SIZE-5,Config.SIZE-5);
//将位置转换为坐标并发送给服务器端
x=(x-Config.STARTX)/Config.SIZE;
y=(y-Config.STARTY)/Config.SIZE;
bytebuf[]=newbyte[2];
buf[0]=(byte)x;
buf[1]=(byte)y;
out.write(buf);
if(Config.isWin(Color.BLACK)){
newMyDialog(frame,Color.BLACK).setVisible(true);
}elseif(Config.isWin(Color.WHITE)){
newMyDialog(frame,Color.WHITE).setVisible(true);
}
flag=!
flag;
frame.removeMouseListener(police);
}else{
byte[][]buf=newbyte[Config.ROW+1][Config.CLOUNM+1];
for(inti=0;i<=Config.ROW;i++){
in.read(buf[i]);
}
Config.resetChess(buf);
frame.paint(frame.getGraphics());
if(Config.isWin(Color.BLACK)){
newMyDialog(frame,Color.BLACK).setVisible(true);
}elseif(Config.isWin(Color.WHITE)){
newMyDialog(frame,Color.WHITE).setVisible(true);
}
flag=true;
}
}
}catch(Exceptione){
e.printStackTrace();
newMyDialog(frame,"连接服务器失败",true).setVisible(true);
return;
}
}
publicvoidthreadDestory()throwsException{
in.close();
out.close();
client.close();
}
privatevoidinit(){
String[][]initValue=newString[][]{{"IP地址:
","127.0.0.1"},
{"端口:
","7777"}};
//创建创建账号的对话框
MyDialoginitDialog=newMyDialog(frame,"请输入对方地址",true,initValue);
initDialog.setVisible(true);
//获得输入数据
String[]nameAndPort=initDialog.getValue();
if(nameAndPort==null){
return;
}
this.ip=nameAndPort[0];
try{
this.port=Integer.valueOf(nameAndPort[1]);
//判断端口号是否正确
if(port<=0||port>65536){
StringerrMsg="错误的端口号"+nameAndPort[1]+"。
端口号必须在0和65536之间";
JOptionPane.showMessageDialog(frame,errMsg,"错误的端口号",
JOptionPane.ERROR_MESSAGE);
return;
}
}catch(NumberFormatExceptionex){
JOptionPane.showMessageDialog(frame,"输入的端口号不是数字。
","错误的端口号",
JOptionPane.ERROR_MESSAGE);
return;
}
Config.setPort(port);
Config.clearChess();
frame.paint(frame.getGraphics());
}
}
五.实验结果
图1
河南工业大学实验报告
(2015~2016学年-第2学期)
课程名称:
软件体系结构 课程编号:
51610192 地点:
6313/6316/6308/6320
专业班级
学号
姓名
实验项目名称
实验2:
五子棋系统C/S风格服务器软件体系结构设计
实验日期
2015.05.15
成绩评定
教师签名:
日期:
一、实验目的:
验证C/S风格的工作机制。
二、实验内容:
针对某个应用系统,选用C/S风格作为这个系统的软件体系结构风格。
熟悉C/S风格的工作机制,对所考察的系统进行C/S风格服务器软件体系结构设计的验证。
(针对不同的特定应用系统具体表述)。
三.编程环境
Windows7
VisualStudio|Dev-C++
Eclipse
四.实验代码
packagegame;
importjava.awt.Color;
importjava.awt.Graphics;
importjava.io.IOException;
importjava.io.InputStream;
importjava.io.OutputStream;
import.ServerSocket;
import.Socket;
importjavax.swing.JFrame;
importjavax.swing.JOptionPane;
importpanel.Config;
importpanel.MyListener;
publicclassGameServerimplementsRunnable{
privateServerSocketserver;
privateSocketclient;
privateJFrameframe;
privateintport;
privateStringname;
privateInputStreamin;
privateOutputStreamout;
privatebooleanflag=true;
publicGameServer(JFrameframe){
this.frame=frame;
}
publicvoidthreadDestory()throwsException{
in.close();
out.close();
client.close();
server.close();
}
/**
*确认连接
*/
privatevoidconfirm()throwsIOException{
out.write(name.getBytes());
}
privatevoidsendUI()throwsIOException{
Strings=newString(Config.SIZE+"#"+Config.ROW+"#"+Config.CLOUNM);
out.write(s.getBytes());
}
publicvoidrun(){
init();
try{
server=newServerSocket(Config.getPort());
client=server.accept();
in=client.getInputStream();
out=client.getOutputStream();
confirm();
sendUI();
//设置棋子颜色
Config.setColor(Color.BLACK);
//交替下棋
MyListenerpolice=newMyListener();
Graphicsg=frame.getGraphics();
while(true){
if(flag){
frame.addMouseListener(police);
while(Config.getX()==-1){
Thread.sleep(20);
}
intx=Config.getX();
inty=Config.getY();
Config.clearNotify();
g.setColor(Config.getColor());
g.fillOval(x-(Config.SIZE/2),y-(Config.SIZE/2),
Config.SIZE-5,Config.SIZE-5);
//发送棋盘给客户端
byte[][]chess=Config.getChess();
for(inti=0;i<=Config.ROW;i++){
out.write(chess[i]);
}
if(Config.isWin(Color.BLACK)){
newMyDialog(frame,Color.BLACK).setVisible(true);
}elseif(Config.isWin(Color.WHITE)){
newMyDialog(frame,Color.WHITE).setVisible(true);
}
flag=!
flag;
frame.removeMouseListener(police);
}else{
byte[]buf=newbyte[2];
in.read(buf);
Config.isChessMan(buf[0],buf[1],
(Config.getColor()==Color.BLACK)?
Color.WHITE
:
Color.BLACK);
frame.paint(g);
if(Config.isWin(Color.BLACK)){
newMyDialog(frame,Color.BLACK).setVisible(true);
}elseif(Config.isWin(Color.WHITE)){
newMyDialog(frame,Color.WHITE).setVisible(true);
}
flag=true;
}
}
}catch(Exceptione){
e.printStackTrace();
newMyDialog(frame,"客户端已下线",true).setVisible(true);
return;
}
}
privatevoidinit(){
String[][]initValue=newString[][]{{"用户名:
","CJN"},
{"端口:
","7777"}};
MyDialoginitDialog=newMyDialog(frame,"请输入用户名和端口",true,initValue);
initDialog.setVisible(true);
String[]nameAndPort=initDialog.getValue();
if(nameAndPort==null){
return;
}
this.name=nameAndPort[0];
try{
this.port=Integer.valueOf(nameAndPort[1]);
//判断端口号是否正确
if(port<=0||port>65536){
StringerrMsg="错误的端口号"+nameAndPort[1]+"。
端口号必须在0和65536之间";
JOptionPane.showMessageDialog(frame,errMsg,"错误的端口号",
JOptionPane.ERROR_MESSAGE);
return;
}
}catch(NumberFormatExceptionex){
JOptionPane.showMessageDialog(frame,"输入的端口号不是数字。
","错误的端口号",
JOptionPane.ERROR_MESSAGE);
return;
}
Config.setPort(port);
frame.setTitle("五子棋"+"玩家:
"+name+"端口号:
"+port);
Config.clearChess();
frame.paint(frame.getGraphics());
}
}
五.实验结果
图1
河南工业大学实验报告
(2015~2016学年-第2学期)
课程名称:
软件体系结构 课程编号:
51610192 地点:
6313/6316/6308/6320
专业班级
学号
姓名
实验项目名称
实验3:
五子棋系统UML建模
实验日期
2015.05.15
成绩评定
教师签名:
日期:
一、实验目的:
深入理解UML建模的思想,熟悉UML建模方法。
二、实验内容:
作为实际应用前的一种演练,深入理解UML建模的思想,熟悉UML建模方法,锻炼和培养分析问题、解决问题的能力。
针对某个选定的应用系统,对其进行GUI原型建模、域模型建模、用例图及用例文本建模、鲁棒性图建模(可选)方面的验证。
三.编程环境
Windows7
StarUML
四.实验建模结果
用例图:
图1
动态交互图;
图2
包图:
图3
静态类图:
图4
河南工业大学实验报告
(2015~2016学年-第2学期)
课程名称:
软件体系结构 课程编号:
51610192 地点:
6313/6316/6308/6320
专业班级
学号
姓名
实验项目名称
实验4:
五子棋系统详细设计
实验日期
2015.05.15
成绩评定
教师签名:
日期:
一、实验目的:
深入理解UML建模的思想,熟悉UML建模方法。
细化前期设计的有关结果,做出软件的详细规格说明。
二、实验内容:
针对某个选定的应用系统,对其进行时序图建模和详细设计级类图建模方面的验证。
详细设计是软件设计的具体模块设计阶段,是在作为软件开发前期设计的体系结构设计和总体设计的基础上进行的。
目的是要细化前期设计的有关结果,做出软件的详细规格说明。
要求具体地验证设计目标系统给定模块的实现过程。
三.编程环境
Windows7
StarUML
四.实验建模结果
时序图:
图1
详细运行图:
图2
图3
图4
图5
图6
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 软件 体系结构 五子棋
![提示](https://static.bingdoc.com/images/bang_tan.gif)