五子棋java课设Word文档格式.docx
《五子棋java课设Word文档格式.docx》由会员分享,可在线阅读,更多相关《五子棋java课设Word文档格式.docx(31页珍藏版)》请在冰点文库上搜索。
20分。
5)参考文献:
[1]丁振凡Java语言实用教程.北京邮电大学出版社,2005年8月第一版第2次印刷
[2]叶核亚陈道蕾.《java2程序设计实用教程》,电子工业出版社2007年1月第二版
[3]陈家兴陈凤朱国鸿.《Java图形用户界面设计与案例》,冶金工业出版社2004年1月第一版第1次印刷
[4](美)BruceEckel
《java编程思想》,机械工业出版社,2007年6月第4版
6)课程设计进度安排
内容天数 地点
构思及收集资料1 图书馆
编码与调试2.5 实验室
撰写论文1.5 图书馆、实验室
学生签名:
2009年6月15日
课程设计(论文)评审意见
(1)完成基本算法(20分):
优( )、良( )、中( )、一般( )、差( );
(2)完成调试 (20分):
(3)创新设计 (20分):
(4)设计分析 (20分):
(5)回答问题 (20分):
(6)格式规范性及考勤是否降等级:
是()、否( )
评阅人:
职称:
2009年6月21日
目录
一课程设计题目及设计目标……………………………………………4
二设计思想………………………………………………………………5
三类及对象设计…………………………………………………………6
四具体实现(程序源代码)……………………………………………7
五运行调试与分析讨论…………………………………………………18
六设计体会与小结………………………………………………………24
七参考文献………………………………………………………………25
一课程设计题目及设计目标
设计一个15╳15围棋棋盘,由两玩家交替进行对战,并可以实现以下功能:
1.选择落子的先后顺序
2.重置棋盘
3.刷新重新开始
4.退出提示
并且规定退出者判为负,但退出过程中要有提示。
以防不小心点错了。
最后判断某一方是否为五子连珠。
二设计思想
做一个Applet程序,并在开始设定合适的窗口,布局简单,美观,实用。
在左侧先画出一个15×
15的棋盘,在右侧设置特定大小位置的按钮,其有不同的作用可以实现重置游戏,选择黑白,选择先后开始游戏,及退出。
最后通过横扫描、竖扫描、左斜扫描与右斜扫描
publicbooleanGame_win_1(intx,inty)、
publicbooleanGame_win_2(intx,inty)、
publicbooleanGame_win_4(intx,inty)、
publicbooleanGame_win_3(intx,inty)
四次扫描及根据选择退出者判断玩家输赢,并实现特定区域显示“XX胜利!
”。
并且,有防错提示框,无意中点错退出按钮后,实现提示。
游戏程序为人与人对战程序,不支持人机对战。
三类及对象设计
publicvoidinit()/////////////////////////////////程序初始化
publicvoidactionPerformed(ActionEvente)///////按钮实现作用
publicvoidqipan(GraphicsG)/////////////////画棋盘15*15
publicvoidGame_btn_enable(booleane////////设置组件初始状态
publicvoidstart()///////////////////////////游戏开始初始化
publicvoidGame_start()///////////////////////////游戏开始
publicvoidmouseClicked(MouseEvente)//////////////鼠标点击
publicvoidset_Qizi(intx,inty)/////////////////////落子
publicvoiditemStateChanged(ItemEvente)////////判断落子顺序
publicStringGet_qizi_color(intx)//////////////返回棋子颜色
publicvoidGame_re()///////////////////////////游戏重新开始
publicvoidGame_stop()/////////////////////////////退出游戏
classMyFrameextendsFrameimplementsActionListener
//////////////////////////////////////////////弹出对话框并判断退出者为负
publicbooleanGame_win_1(intx,inty)//////////判断输赢横
publicbooleanGame_win_2(intx,inty)//////////判断输赢竖
publicbooleanGame_win_3(intx,inty)//////////判断输赢左斜
publicbooleanGame_win_4(intx,inty)//////////判断输赢右斜
四具体实现(程序源代码)
packagewuziqi1;
importjava.applet.*;
importjava.applet.Applet;
importjava.awt.*;
importjava.awt.Color;
importjava.awt.event.*;
publicclasswuziqiextendsAppletimplementsActionListener,MouseListener,
MouseMotionListener,ItemListener
{
intcolor_Qizi=0;
/////////////////////////////旗子的颜色标识0:
白子1:
黑子
intgamestart=0;
///////////////////////////////游戏开始标志0未开始1游戏中
intgamebody[][]=newint[16][16];
////设置棋盘棋子状态0无子1白子2黑子
Buttonb1=newButton("
游戏开始"
);
Buttonb2=newButton("
重置游戏"
Buttonb3=newButton("
退出游戏"
LabellblWin=newLabel("
"
////////////////////状态标签
CheckboxckbHB[]=newCheckbox[2];
/////////////起始复选框
CheckboxGroupckgHB=newCheckboxGroup();
////////复选框组
publicvoidinit()
{
resize(420,360);
setLayout(null);
addMouseListener(this);
add(b1);
b1.setBounds(330,100,70,30);
b1.addActionListener(this);
add(b2);
b2.setBounds(330,140,70,30);
b2.addActionListener(this);
add(b3);
b3.setBounds(330,180,70,30);
b3.addActionListener(this);
ckbHB[0]=newCheckbox("
白子先"
ckgHB,false);
ckbHB[0].setBounds(330,30,70,30);
ckbHB[1]=newCheckbox("
黑子先"
ckbHB[1].setBounds(330,60,70,30);
add(ckbHB[0]);
add(ckbHB[1]);
ckbHB[0].addItemListener(this);
ckbHB[1].addItemListener(this);
add(lblWin);
lblWin.setBounds(330,280,70,30);
setBackground(Color.gray);
setBounds(100,100,320,280);
setVisible(true);
start();
}
publicvoiditemStateChanged(ItemEvente)
if(ckbHB[0].getState())////////////////////////判断黑子先还是白子先
color_Qizi=0;
else
color_Qizi=1;
}
publicvoidactionPerformed(ActionEvente)
if(e.getSource()==b1)/////////////////////////////////开始游戏
Game_start();
elseif(e.getSource()==b3)/////////////////////////////退出游戏
Game_stop();
else////e.getSource()==b2//////////////////////////////重新开始
Game_re();
publicvoidmouseClicked(MouseEvente)
intx1,y1;
x1=e.getX();
y1=e.getY();
if(e.getX()<
20||e.getX()>
300||e.getY()<
20||e.getY()>
300)
return;
if(x1%20>
10)
x1+=20;
if(y1%20>
y1+=20;
x1=x1/20*20;
y1=y1/20*20;
set_Qizi(x1,y1);
publicvoidmousePressed(MouseEvente){}
publicvoidmouseEntered(MouseEvente){}
publicvoidmouseExited(MouseEvente){}
publicvoidmouseReleased(MouseEvente){}
publicvoidmouseDragged(MouseEvente){}
publicvoidmouseMoved(MouseEvente){}
publicvoidpaint(Graphicsg)
qipan(g);
publicvoidset_Qizi(intx,inty)/////////////////////////////落子
if(gamestart==0)///////////////////////////////////判断游戏是否开始
if(gamebody[x/20][y/20]!
=0)
Graphicsg=getGraphics();
if(color_Qizi==1)///////////////////////////////////判断黑子还是白子
g.setColor(Color.black);
g.setColor(Color.white);
g.fillOval(x-10,y-10,20,20);
gamebody[x/20][y/20]=color_Qizi+1;
if(Game_win_1(x/20,y/20))////////////////////////////////判断输赢1横向
lblWin.setText(Get_qizi_color(color_Qizi)+"
赢了!
gamestart=0;
if(Game_win_2(x/20,y/20))////////////////////////////////判断输赢2竖向
if(Game_win_3(x/20,y/20))////////////////////////////////判断输赢3左斜
if(Game_win_4(x/20,y/20))////////////////////////////////判断输赢4右斜
publicStringGet_qizi_color(intx)///////////////////////返回棋子颜色
if(x==0)
return"
黑子"
;
白子"
publicvoidqipan(GraphicsG)///////////////////////////画棋盘15*15
G.setColor(Color.gray);
G.fill3DRect(10,10,300,300,true);
G.setColor(Color.black);
for(inti=1;
i<
16;
i++)
G.drawLine(20,20*i,300,20*i);
G.drawLine(20*i,20,20*i,300);
publicvoidGame_btn_enable(booleane)/////////////////设置组件初始状态
b1.setEnabled(e);
b2.setEnabled(e);
b3.setEnabled(e);
ckbHB[0].setEnabled(e);
ckbHB[1].setEnabled(e);
publicvoidstart()/////////////////////////////////////游戏开始初始化
Game_btn_enable(true);
b2.setEnabled(false);
b3.setEnabled(false);
ckbHB[0].setState(true);
for(inti=0;
16;
i++)
for(intj=0;
j<
j++)
gamebody[i][j]=0;
lblWin.setText("
胜负状态"
publicvoidGame_start()/////////////////////////////////////游戏开始
gamestart=1;
Game_btn_enable(false);
b2.setEnabled(true);
b3.setEnabled(true);
publicvoidGame_re()////////////////////////////////////游戏重新开始
repaint();
publicvoidGame_stop()//////////////////////////////////////退出游戏
newMyFrame();
classMyFrameextendsFrameimplementsActionListener
Buttonb4,b5,b6;
MyFrame()
super("
MYWINDOWS"
b4=newButton("
\"
退出\"
将被判为\"
输\"
是否继续游戏?
setLayout(newFlowLayout());
add(b4);
b4.addActionListener(this);
b5=newButton("
是"
add(b5);
b5.addActionListener(this);
b6=newButton("
否"
add(b6);
b6.addActionListener(this);
addWindowListener(newcloseWin());
setSize(220,100);
setVisible(true);
if(e.getActionCommand()=="
关闭"
)
{
dispose();
}
if(e.getSource()==b5)
elseif(e.getSource()==b6)
lblWin.setText(Get_qizi_color(color_Qizi)+"
else
return;
classcloseWinextendsWindowAdapter
publicvoidwindowClosing(WindowEvente)
Windoww=e.getWindow();
w.dispose();
publicbooleanGame_win_1(intx,inty)/////////////////////////判断输赢横
intx1,y1,t=1;
x1=x;
y1=y;
for(inti=1;
5;
if(x1>
15)
break;
if(gamebody[x1+i][y1]==gamebody[x][y])
t+=1;
if(x1<
1)
if(gamebody[x1-i][y1]==gamebody[x][y])
if(t>
4)
returntrue;
returnfalse;
publicbooleanGame_win_2(intx,inty)/////////////////////////判断输赢竖
if(gamebody[x1][y1+i]==gamebody[x][y])
if(gamebody[x1][y1-i]==gamebody[x][y])
publicbooleanGame_win_3(intx,inty)////////////////////判断输赢左