JAVA连连看课程设计报告文档格式.docx
《JAVA连连看课程设计报告文档格式.docx》由会员分享,可在线阅读,更多相关《JAVA连连看课程设计报告文档格式.docx(30页珍藏版)》请在冰豆网上搜索。
【程序输出结果】:
游戏开始
提示功能
消除功能
游戏结束
关于
【总结自己的体会和收获】:
通过这次课程设计我学到了不少东西,也发现了大量的问题,同时在设计的过程中也发现了自己的不足之处,对以前学过的知识理解的不够深刻。
对JAVA运用图片的调用和设置是否可见有了新的了解。
但在部分功能的实现上还是有所不足,老师和同学都给予了很多帮助。
让我懂得了JAVA的重要性和如何应用到实践后上。
【程序代码另附】:
ImageFactory
packagenicholas.game.kyodai;
importjavax.swing.ImageIcon;
import.*;
publicclassImageFactory{
privatestaticImageFactoryimagefactory;
privatestaticImageIconimages[];
privateImageFactory(){
images=newImageIcon[54];
URLClassLoaderloader=(URLClassLoader)getClass().getClassLoader();
for(inti=0;
i<
39;
i++){
images[i]=newImageIcon(getClass().getResource("
images/"
+i+"
.gif"
));
}
images[39]=newImageIcon(getClass().getResource("
images/dots.gif"
images[40]=newImageIcon(getClass().getResource("
images/ico.gif"
images[41]=newImageIcon(getClass().getResource("
images/topbar.gif"
images[42]=newImageIcon(getClass().getResource("
images/splash.gif"
images[43]=newImageIcon(getClass().getResource("
images/sico.gif"
publicImageIcongetImageicon(inti){
returnimages[i];
publicstaticsynchronizedImageFactorygetInstance(){
if(imagefactory!
=null){
returnimagefactory;
}else{
imagefactory=newImageFactory();
}
KyodaiGrid
importjava.awt.*;
importjavax.swing.*;
publicclassKyodaiGridextendsJLabel{
privateintxpos;
privateintypos;
publicKyodaiGrid(intx,inty){
xpos=x;
ypos=y;
this.setHorizontalAlignment(SwingConstants.CENTER);
publicintgetXpos(){
returnxpos;
publicintgetYpos(){
returnypos;
publicbooleanisPassable(){
return!
isVisible();
LevelInfo
importjava.io.Serializable;
publicclassLevelInfoimplementsSerializable{//xBound为行号,yBound为列号
privateintxBound;
privateintyBound;
publicLevelInfo(){
xBound=16;
yBound=9;
publicLevelInfo(intx,inty){
xBound=x;
yBound=y;
publicintgetXBound(){
returnxBound;
publicintgetYBound(){
returnyBound;
MainFrame.java
importjava.awt.event.*;
importjava.io.*;
importnicholas.swing.AboutDialog;
importnicholas.swing.JSplashWindow;
publicclassMainFrameextendsJFrameimplementsActionListener{
privateJMenuItemaboutItem;
//菜单栏
privateJMenuItemexitItem;
privateJMenuItemstartItem;
privateJMenuItemoptionItem;
privateJMenuItemtipItem;
privateJMenuItemrefreshItem;
privateJMenuItemlogItem;
privateJMenuItembombItem;
privateJMenuItempauseItem;
privateMainPanelmainPanel;
//完成主要功能
privateLevelInfolevelInfo;
publicMainFrame(){
super("
连连看"
);
levelInfo=newLevelInfo();
//设定游戏大小
setMenuBar();
//设置菜单
setUI();
setIconImage(ImageFactory.getInstance().getImageicon(43).getImage());
setSize(650,520);
Dimensionscreen=getToolkit().getScreenSize();
setLocation((screen.width-getSize().width)/2,(screen.height-getSize().height)/2);
this.setVisible(true);
addWindowListener(
newWindowAdapter(){
publicvoidwindowClosing(WindowEvente){
System.exit(0);
}
}
);
privatevoidsetMenuBar(){
JMenufileMenu=newJMenu("
游戏(G)"
JMenuhelpMenu=newJMenu("
帮助(H)"
JMenucontMenu=newJMenu("
辅助(C)"
fileMenu.setMnemonic('
G'
helpMenu.setMnemonic('
H'
contMenu.setMnemonic('
C'
startItem=newJMenuItem("
开局(N)"
startItem.setMnemonic('
N'
startItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2,0));
pauseItem=newJMenuItem("
暂停(P)"
pauseItem.setMnemonic('
P'
pauseItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PAUSE,0));
refreshItem=newJMenuItem("
刷新(R)"
refreshItem.setMnemonic('
R'
refreshItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3,0));
tipItem=newJMenuItem("
提示(T)"
tipItem.setMnemonic('
T'
tipItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5,0));
optionItem=newJMenuItem("
选项(O)..."
optionItem.setMnemonic('
O'
logItem=newJMenuItem("
排行榜(B)..."
logItem.setMnemonic('
B'
exitItem=newJMenuItem("
退出(X)"
exitItem.setMnemonic('
X'
aboutItem=newJMenuItem("
关于(A)..."
aboutItem.setMnemonic('
A'
aboutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1,0));
bombItem=newJMenuItem("
炸弹(M)"
bombItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4,0));
bombItem.setMnemonic('
M'
startItem.addActionListener(this);
pauseItem.addActionListener(this);
refreshItem.addActionListener(this);
tipItem.addActionListener(this);
optionItem.addActionListener(this);
logItem.addActionListener(this);
exitItem.addActionListener(this);
aboutItem.addActionListener(this);
bombItem.addActionListener(this);
fileMenu.add(startItem);
fileMenu.add(pauseItem);
contMenu.add(refreshItem);
contMenu.add(bombItem);
contMenu.add(tipItem);
fileMenu.addSeparator();
fileMenu.add(exitItem);
helpMenu.add(aboutItem);
helpMenu.add(contMenu);
JMenuBarbar=newJMenuBar();
bar.add(fileMenu);
bar.add(helpMenu);
setJMenuBar(bar);
privatevoidsetUI(){
mainPanel=newMainPanel(levelInfo);
getContentPane().add(mainPanel,BorderLayout.CENTER);
publicstaticvoidmain(Stringargs[]){
MainFrameapplication=newMainFrame();
privatevoidshowAboutDialog(){
Strings1="
作者:
曲一鸣"
;
Strings2="
邮箱:
421992774@"
Strings3="
HaveFun!
!
"
TextAreata=newTextArea();
ta.setText(s1+"
\n"
+"
+s2+"
+s3);
ta.setEditable(false);
JFramef=newJFrame("
关于"
f.setLocation(300,300);
f.setSize(200,200);
f.add(ta);
f.setBackground(newColor(200,120,150));
f.setResizable(false);
f.setVisible(true);
publicvoidactionPerformed(ActionEventae){
if(ae.getSource()==startItem){
mainPanel.restart();
}elseif(ae.getSource()==pauseItem){
mainPanel.setPaused(!
mainPanel.isPaused());
}elseif(ae.getSource()==exitItem){
System.exit(0);
}elseif(ae.getSource()==aboutItem){
showAboutDialog();
}elseif(ae.getSource()==bombItem){
mainPanel.useBomb();
}elseif(ae.getSource()==refreshItem){
mainPanel.refresh();
}elseif(ae.getSource()==tipItem){
mainPanel.showNext();
}
MainPanel.java
importjava.util.Vector;
importjavax.swing.border.Border;
importnicholas.game.kyodai.*;
publicclassMainPanelextendsJPanel{
privateintBOMB=5;
privateintBOMBP=200;
privateintREFRESH=4;
privateintREFRP=250;
privateintTIP=7;
privateintTIPP=120;
privateintPROGRESS=1200;
privateintpcount;
privateintscore;
privateintrefreshcount;
privateintbombcount;
privateinttipcount;
privateGridMouseAdaptergma;
privateKyodaiGridgrid[][];
privateKyodaiGridnexts,nexte;
privateBorderselectedBorder;
privateBorderopaqueBorder;
privateBordertipBorder;
privateVectorpath[];
privateThreadpthread;
privateJProgressBarprogress;
privateJLabelscoreLabel;
privateJLabelrefreshLabel;
privateJLabelbombLabel;
privateJLabeltipLabel;
privateJPanelgridPanel;
privatebooleanwingame;
publicMainPanel(LevelInfoli){
super(newBorderLayout());
levelInfo=li;
path=newVector[3];
path[0]=newVector();
path[1]=newVector();
path[2]=newVector();
setBackground(Color.black);
gma=newGridMouseAdapter();
opaqueBorder=BorderFactory.createLineBorder(getBackground());
//selectedBorder=BorderFactory.createLineBorder(Color.red);
selectedBorder=BorderFactory.createLineBorder(Color.red);
tipBorder=BorderFactory.createLineBorder(Color.green);
setGridPanel();
setStatusPanel();
/**
*设置状态面板
*/
privatevoidsetStatusPanel(){
wingame=false;
JPanelpanel=newJPanel();
panel.setBackground(Color.black);
JLabellabel=newJLabel("
剩余时间:
label.setForeground(Color.white);
panel.add(label);
progress=newJProgressBar(0,PROGRESS);
//时间条显示
progress.setValue(PROGRESS);
progress.setPreferredSize(newDimension(400,20));
progress.setForeground(Color.blue);
progress.setBorderPainted(false);
panel.add(progress);
score=0;
scoreLabel=newJLabel("
+score);
scoreLabel.setForeground(Color.yellow);
scoreLabel.setFont(newFont("
Dialog"
Font.BOLD,25));
scoreLabel.setHorizontalAlignment(SwingConstants.RIGHT);
scoreLabel.setPreferredSize(newDimension(100,20));
panel.add(scoreLabel);
add(panel,BorderLayout.NORTH);
panel=newJPanel();
label=newJLabel("
剩余提示:
label.setForeground(Color.yellow);
tipcount=TIP;
tipLabel=newJLabel("
+tipcount);
tip