軟件測(cè)試項(xiàng)目方案設(shè)計(jì).doc_第1頁
軟件測(cè)試項(xiàng)目方案設(shè)計(jì).doc_第2頁
軟件測(cè)試項(xiàng)目方案設(shè)計(jì).doc_第3頁
軟件測(cè)試項(xiàng)目方案設(shè)計(jì).doc_第4頁
軟件測(cè)試項(xiàng)目方案設(shè)計(jì).doc_第5頁
已閱讀5頁,還剩69頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

俄羅斯方塊Java語言設(shè)計(jì)項(xiàng)目方案設(shè)計(jì)報(bào)告 2009 2010 學(xué)年 第 1 學(xué)期教 學(xué) 單 位 計(jì)算機(jī)工程系 課 程 名 稱 Java語言課程設(shè)計(jì) 課程設(shè)計(jì)題目 俄羅斯斯方塊Java語言設(shè)計(jì) 指 導(dǎo) 教 師 熊偉平老師 學(xué)生姓名和學(xué)號(hào): 關(guān)健駒(20094054034) 何偉添(20094054037) 鄒杰霖(20094054032) 專 業(yè) 名 稱 計(jì)算機(jī)應(yīng)用技術(shù) 俄羅斯方塊Java語言設(shè)計(jì)與實(shí)現(xiàn)一、 項(xiàng)目需求分析:主要是緩解學(xué)習(xí)壓力過大的一個(gè)小游戲,非常益智,對(duì)小朋友的左腦開發(fā)具有很大的幫助。二、 實(shí)驗(yàn)環(huán)境和要求:系統(tǒng):Microsoft Windows XP Professional計(jì)算機(jī):Intel(R) Core(TM) Duo COU E4600 2.40GHz 2.39GHz ,1.00GB的內(nèi)存物理地址擴(kuò)展軟件:JCreator Pro和JDK1.6要求:1) 面向?qū)ο蟪绦蛟O(shè)計(jì)的思想及編程方法的認(rèn)識(shí)和掌握。2) 熟悉java的編程環(huán)境J2SDK,掌握Application 和Applet的程序結(jié)構(gòu),并能熟練編寫和調(diào)試兩類程序。3) 理解和掌握各種修飾符的用法。4) 引入包,應(yīng)用定時(shí)器,可變長(zhǎng)數(shù)組,隨機(jī)類,。5) 熟練使用各種常用類庫。6) 理解JDK的事件處理機(jī)制,掌握java.awt 、javax.swing,javax.swing.event中的GUI標(biāo)準(zhǔn)組件的用法,學(xué)會(huì)合理運(yùn)用布局策略、綜合運(yùn)用各種界面元素,編程構(gòu)造滿足應(yīng)用需要的圖形工作界面。三、 程序設(shè)計(jì)和分析:1、設(shè)計(jì):俄羅斯游戲的顯示模塊和控制模塊由關(guān)健駒負(fù)責(zé),框架結(jié)構(gòu)由何偉添負(fù)責(zé),代碼輸入、程序修改、測(cè)試和論文由鄒杰霖負(fù)責(zé)完成。2、分析:主界面:各個(gè)按鈕的功能畫面:已進(jìn)入游戲界面:游戲程序代碼:/*按鈕及鍵盤控制響應(yīng)*/import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border.*;public class ControlPanel extends JPanel private TipBlockPanel tipBlockPanel; private JPanel tipPanel,InfoPanel,buttonPanel; private final JTextField levelField,scoreField; private JButton playButton,pauseButton,stopButton, turnHarderButton,turnEasilyButton; private EtchedBorder border=new EtchedBorder(EtchedBorder.RAISED,Color.WHITE, new Color(148, 145, 140) ; private RussiaBlocksGame game; private Timer timer; public ControlPanel(final RussiaBlocksGame game) this.game = game; /* *圖形界面部分 */ setLayout(new GridLayout(3,1,0,4); tipBlockPanel = new TipBlockPanel(); tipPanel = new JPanel( new BorderLayout() ); tipPanel.add( new JLabel(下一個(gè)方塊:) , BorderLayout.NORTH ); tipPanel.add( tipBlockPanel , BorderLayout.CENTER ); tipPanel.setBorder(border); InfoPanel = new JPanel( new GridLayout(4,1,0,0) ); levelField = new JTextField(+RussiaBlocksGame.DEFAULT_LEVEL); levelField.setEditable(false); scoreField = new JTextField(0); scoreField.setEditable(false); InfoPanel.add(new JLabel(難度:); InfoPanel.add(levelField); InfoPanel.add(new JLabel(分?jǐn)?shù):); InfoPanel.add(scoreField); InfoPanel.setBorder(border); buttonPanel = new JPanel(new GridLayout(5,1,0,0); playButton = new JButton(開始); pauseButton = new JButton(暫停); stopButton = new JButton(停止); turnHarderButton = new JButton(更難); turnEasilyButton = new JButton(更易); buttonPanel.add(playButton); buttonPanel.add(pauseButton); buttonPanel.add(stopButton); buttonPanel.add(turnHarderButton); buttonPanel.add(turnEasilyButton); buttonPanel.setBorder(border); addKeyListener(new ControlKeyListener();/添加 add(tipPanel); add(InfoPanel); add(buttonPanel); /* *添加事件監(jiān)聽器 */ playButton.addActionListener( new ActionListener() public void actionPerformed(ActionEvent event) game.playGame(); requestFocus();/讓ControlPanel重新獲得焦點(diǎn)以響應(yīng)鍵盤事件 ); pauseButton.addActionListener( new ActionListener() public void actionPerformed(ActionEvent event) if(pauseButton.getText().equals(暫停) game.pauseGame(); else game.resumeGame(); requestFocus();/讓ControlPanel重新獲得焦點(diǎn)以響應(yīng)鍵盤事件 ); stopButton.addActionListener( new ActionListener() public void actionPerformed(ActionEvent event) game.stopGame(); requestFocus();/讓ControlPanel重新獲得焦點(diǎn)以響應(yīng)鍵盤事件 ); turnHarderButton.addActionListener( new ActionListener() public void actionPerformed(ActionEvent event) int level = 0; try level = Integer.parseInt(levelField.getText(); setLevel(level + 1); catch(NumberFormatException e) e.printStackTrace(); requestFocus();/讓ControlPanel重新獲得焦點(diǎn)以響應(yīng)鍵盤事件 ); turnEasilyButton.addActionListener( new ActionListener() public void actionPerformed(ActionEvent event) int level = 0; try level = Integer.parseInt(levelField.getText(); setLevel(level - 1); catch(NumberFormatException e) e.printStackTrace(); requestFocus();/讓ControlPanel重新獲得焦點(diǎn)以響應(yīng)鍵盤事件 ); /* * 時(shí)間驅(qū)動(dòng)程序,每格500毫秒對(duì)level,score值進(jìn)行更新 */ timer = new Timer(500, new ActionListener() public void actionPerformed(ActionEvent event) scoreField.setText(+game.getScore(); game.levelUpdate(); ); timer.start(); /* * 設(shè)置預(yù)顯方塊的樣式 */ public void setBlockStyle(int style) tipBlockPanel.setStyle(style); tipBlockPanel.repaint(); /* * 重置,將所有數(shù)據(jù)恢復(fù)到最初值 */ public void reset() levelField.setText(+RussiaBlocksGame.DEFAULT_LEVEL); scoreField.setText(0); setPlayButtonEnabled(true); setPauseButtonLabel(true); tipBlockPanel.setStyle(0); /* *設(shè)置playButton是否可用 */ public void setPlayButtonEnabled(boolean enable) playButton.setEnabled(enable); /* *設(shè)置pauseButton的文本 */ public void setPauseButtonLabel(boolean pause) pauseButton.setText( pause ? 暫停 : 繼續(xù) ); /* *設(shè)置方塊的大小,改變窗體大小時(shí)調(diào)用可自動(dòng)調(diào)整方塊到合適的尺寸 */ public void fanning() tipBlockPanel.fanning(); /* *根據(jù)level文本域的值返回當(dāng)前的級(jí)別 */ public int getLevel() int level = 0; try level=Integer.parseInt(levelField.getText(); catch(NumberFormatException e) e.printStackTrace(); return level; /* * 設(shè)置level文本域的值 */ public void setLevel(int level) if(level 0 & level = RussiaBlocksGame.MAX_LEVEL) levelField.setText( + level); /* * 內(nèi)部類 為預(yù)顯方塊的顯示區(qū)域 */ private class TipBlockPanel extends JPanel private Color bgColor = Color.darkGray, blockColor = Color.lightGray; private RussiaBox boxes = new RussiaBoxRussiaBlock.ROWSRussiaBlock.COLS; private int boxWidth, boxHeight,style; private boolean isTiled = false; /* * 構(gòu)造函數(shù) */ public TipBlockPanel() for(int i = 0; i boxes.length; i +) for(int j = 0; j boxesi.length; j +) boxesij=new RussiaBox(false); style = 0x0000; /* * 構(gòu)造函數(shù) */ public TipBlockPanel(Color bgColor, Color blockColor) this(); this.bgColor = bgColor; this.blockColor = blockColor; /* * 設(shè)置方塊的風(fēng)格 */ public void setStyle(int style) this.style = style; repaint(); /* * 繪制預(yù)顯方塊 */ public void paintComponent(Graphics g) super.paintComponent(g); int key = 0x8000; if(!isTiled) fanning(); for(int i = 0; i boxes.length; i +) for(int j = 0; j=1; /* *設(shè)置方塊的大小,改變窗體大小時(shí)調(diào)用可自動(dòng)調(diào)整方塊到合適的尺寸 */ public void fanning() boxWidth = getSize().width / RussiaBlock.COLS; boxHeight = getSize().height /RussiaBlock.ROWS; isTiled=true; /* *內(nèi)部類 鍵盤鍵聽器,響應(yīng)鍵盤事件 */ class ControlKeyListener extends KeyAdapter public void keyPressed(KeyEvent ke) if (!game.isPlaying() return; RussiaBlock block = game.getCurBlock(); switch (ke.getKeyCode() case KeyEvent.VK_DOWN: block.moveDown(); break; case KeyEvent.VK_LEFT: block.moveLeft(); break; case KeyEvent.VK_RIGHT: block.moveRight(); break; case KeyEvent.VK_UP: block.turnNext(); break; case KeyEvent.VK_SPACE:/一鍵到底 while(block.moveDown() break; default: break; /*虛擬的單個(gè)方格類,控制方格的顏色*/public class RussiaBox implements Cloneable private boolean isColor; public RussiaBox(boolean isColor) this.isColor = isColor; /* *設(shè)置顏色 */ public void setColor(boolean isColor) this.isColor=isColor; /* *返回顏色 */ public boolean isColorBox() return isColor; /* * see java.lang.Object#clone() */ public Object clone() Object o = null; try o=super.clone(); catch(CloneNotSupportedException e) e.printStackTrace(); return o; /* 主游戲類 */import java.awt.*;import java.awt.event.*;import javax.swing.*;public class RussiaBlocksGame extends JFrame public final static int PER_LINE_SCORE = 100;/消去一行得分 public final static int PER_LEVEL_SCORE = PER_LINE_SCORE*20;/升一級(jí)需要的分?jǐn)?shù) public final static int DEFAULT_LEVEL = 5;/默認(rèn)級(jí)別 public final static int MAX_LEVEL = 10;/最高級(jí)別 private int score=0,curLevelScore = 0;/總分和本級(jí)得分 private GameCanvas canvas; private ControlPanel controlPanel; private RussiaBlock block; private int style = 0; boolean playing = false; private JMenuBar bar; private JMenu gameMenu,controlMenu,windowStyleMenu,informationMenu; private JMenuItem newGameItem,setBlockColorItem,setBgColorItem, turnHardItem,turnEasyItem,exitItem; private JMenuItem playItem,pauseItem,resumeItem,stopItem; private JRadioButtonMenuItem windowsRadioItem,motifRadioItem,metalRadioItem; private JMenuItem authorItem,helpItem; private ButtonGroup buttonGroup; /* * 構(gòu)造函數(shù) */ public RussiaBlocksGame(String title) super(title); setSize(300,400); Dimension scrSize=Toolkit.getDefaultToolkit().getScreenSize(); setLocation(scrSize.width-getSize().width)/2,(scrSize.height-getSize().height)/2); createMenu(); Container container=getContentPane(); container.setLayout(new BorderLayout(); canvas = GameCanvas.getCanvasInstance(); controlPanel = new ControlPanel(this); container.add(canvas,BorderLayout.CENTER); container.add(controlPanel,BorderLayout.EAST); addWindowListener( new WindowAdapter() public void windowClosing(WindowEvent event) stopGame(); System.exit(0); ); addComponentListener( new ComponentAdapter() public void componentResized(ComponentEvent event) canvas.fanning(); ); canvas.fanning(); setVisible(true); /* * 判斷游戲是否正在進(jìn)行 */ public boolean isPlaying() return playing; /* * 開始游戲并設(shè)置按鈕和菜單項(xiàng)的可用性 */ public void playGame() play(); controlPanel.setPlayButtonEnabled(false); playItem.setEnabled(false); /* * 暫停游戲 */ public void pauseGame() if(block != null) block.pauseMove(); controlPanel.setPauseButtonLabel(false); pauseItem.setEnabled(false); resumeItem.setEnabled(true); /* * 從暫停中恢復(fù)游戲 */ public void resumeGame() if(block != null) block.resumeMove(); controlPanel.setPauseButtonLabel(true); pauseItem.setEnabled(true); resumeItem.setEnabled(false); /* * 停止游戲 */ public void stopGame() if(block != null) block.stopMove(); playing = false; controlPanel.setPlayButtonEnabled(true); controlPanel.setPauseButtonLabel(true); playItem.setEnabled(true); /* * 得到當(dāng)前級(jí)別 */ public int getLevel() return controlPanel.getLevel(); /* * 設(shè)置當(dāng)前級(jí)別,并更新控制面板的顯示 */ public void setLevel(int level) if(level0&level11) controlPanel.setLevel(level); /* * 得到當(dāng)前總分?jǐn)?shù) */ public int getScore() if(canvas != null) return score; return 0; /* * 得到本級(jí)得分 */ public int getCurLevelScore() if(canvas != null) return curLevelScore; return 0; /* * 更新等級(jí) */ public void levelUpdate() int curLevel = getLevel(); if(curLevel = PER_LEVEL_SCORE) setLevel(curLevel + 1); curLevelScore -= PER_LEVEL_SCORE; /* * 獲得當(dāng)前得方塊 */ public RussiaBlock getCurBlock() return block; /* * 開始游戲 */ private void play() playing=true; Thread thread = new Thread(new Game(); thread.start(); reset(); /* * 重置 */ private void reset() controlPanel.reset(); canvas.reset(); score = 0; curLevelScore = 0; /* * 宣告游戲結(jié)束 */ private void reportGameOver() JOptionPane.showMessageDialog(this,Game over!); /* * 創(chuàng)建菜單 */ private void createMenu() gameMenu = new JMenu(游戲); newGameItem = new JMenuItem(新游戲); setBlockColorItem = new JMenuItem(設(shè)置方塊顏色.); setBgColorItem = new JMenuItem(設(shè)置背景顏色.); turnHardItem = new JMenuItem(提高難度); turnEasyItem = new JMenuItem(降低難度); exitItem = new JMenuItem(退出); gameMenu.add(newGameItem); gameMenu.add(setBlockColorItem); gameMenu.add(setBgColorItem); gameMenu.add(turnHardItem); gameMenu.add(turnEasyItem); gameMenu.add(exitItem); controlMenu = new JMenu(游戲控制); playItem = new JMenuItem(開始); pauseItem = new JMenuItem(暫停); resumeItem = new JMenuItem(繼續(xù)); stopItem = new JMenuItem(停止); controlMenu.add(playItem); controlMenu.add(pauseItem); controlMenu.add(resumeItem); controlMenu.add(stopItem); windowStyleMenu = new JMenu(窗口風(fēng)格); buttonGroup = new ButtonGroup(); windowsRadioItem = new JRadioButtonMenuItem(Windows); motifRadioItem = new JRadioButtonMenuItem(Motif); metalRadioItem = new JRadioButtonMenuItem(Mentel,true); windowStyleMenu.add(windowsRadioItem); buttonGroup.add(windowsRadioItem); windowStyleMenu.add(motifRadioItem); buttonGroup.add(motifRadioItem); windowStyleMenu.add(metalRadioItem); buttonGroup.add(metalRadioItem); /*informationMenu = new JMenu(信息); authorItem = new JMenuItem(Author:Fuliang); helpItem = new JMenuItem(Help); informationMenu.add(authorItem); informationMenu.add(helpItem); */ bar = new JMenuBar(); bar.add(gameMenu); bar.add(controlMenu); bar.add(windowStyleMenu); /bar.add(informationMenu); addActionListenerToMenu(); setJMenuBar(bar); /* * 添加菜單響應(yīng) */ private void addActionListenerToMenu() newGameItem.addActionListener(new ActionListener() public void actionPerformed(ActionEvent ae) stopGame(); reset(); setLevel(DEFAULT_LEVEL); ); setBlockColorItem.addActionListener(new ActionListener() public void actionPerformed(ActionEvent ae) Color newBlockColor = JColorChooser.showDialog(RussiaBlocksGame.this, Set color for block, canvas.getBlockColor(); if (newBlockColor != null) canvas.setBlockColor(newBlockColor); ); setBgColorItem.addActionListener(new ActionListener() public void actionPerformed(ActionEvent ae) Color newBgColor = JColorChooser.showDialog(RussiaBlocksGame.this,Set color for block, canvas.getBgColor(); if (newBgColor != null) canvas.setBgColor(newBgColor); ); turnHardItem.addActionListener(new ActionListener() public void actionPerformed(ActionEvent ae) int curLevel = getLevel(); if (curLevel 1) setLevel(curLevel - 1); ); exitItem.addActionListener(new ActionListener() public void actionPerformed(ActionEvent ae) System.exit(0); ); playItem.addActionListener(new ActionListener() public void actionPerformed(ActionEvent ae) playGame(); ); pauseItem.addActionListener(new ActionListener() public void actionPerformed(ActionEvent ae) pauseGame(); ); resumeItem.addActionListener(new ActionListener() public void actionPerformed(ActionEvent ae) resumeGame(); ); stopItem.addActionListener(new ActionListener() public void actionPerformed(ActionEvent ae) stopGame(); ); windowsRadioItem.addActionListener(new ActionListener() public void actionPerformed(ActionEvent ae) String plaf = com.sun.java.swing.plaf.windows.WindowsLookAndFeel; setWindowStyle(plaf); canvas.fanning(); controlPanel.fanning(); ); motifRadioItem.addActionListener(new ActionListener() public void actionPerformed(ActionEvent ae) String plaf = com.sun.java.swing.plaf.motif.MotifLookAndFeel; setWindowStyle(plaf); canvas.fanning(); controlPanel.fanning(); ); metalRadioItem.addActionListener(new ActionListener() public void actionPerformed(ActionEvent ae) String plaf = javax.swing.plaf.metal.MetalLookAndFeel; setWindowStyle(plaf); canvas.fanning(); controlPanel.fanning(); ); /* * 設(shè)定窗口

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論