資源簡介
此小游戲基于java開發而來,雖然目前只是實現了文件上傳,下載,開始游戲等。但是還是很適合想我這樣的新手來練練手還是可以的啦。利用深度優先算法進行迷宮路徑的設置與查找。有背景音樂,可自行設置迷宮難度。
代碼片段和文件信息
package?com.game.migong;
//迷宮界面
import?java.awt.*;
import?java.awt.event.*;
import?java.io.File;
import?java.io.RandomAccessFile;
import?javax.swing.*;
@SuppressWarnings(“serial“)
public?class?map?extends?Jframe?implements?ActionListener?KeyListener?Runnable?{
??static?int?m?n;
??static?wrmPane[][]?tp?=?null;????????//顯示動畫同一包內類均可訪問
??//時間限制
??static?Thread?timeThread;????????????????//時間控制線程
??static?int?timelimit?remaintime;
??static?JPanel?timePanel?=?new?JPanel()?{?????//剩余時間顯示面板
??????public?void?paintComponent(Graphics?g)?{
??????????super.paintComponent(g);
??????????String?rt;
??????????if?(timelimit?==?0)?{
??????????????rt?=?“無限制“;
??????????????setForeground(Color.GREEN);????//青色表示無時間限制
??????????}?else?{
??????????????rt?=?remaintime?/?3600?+?“?:?“?+?(remaintime?-?(remaintime?/?3600)?*?3600)?/?60?+?“?:?“?+?remaintime?%?60;
??????????????if?(remaintime?>?10)
??????????????????setForeground(Color.BLUE);??????//剩余時間充足時為綠色
??????????????else
??????????????????setForeground(Color.RED);??????//剩余時間很少時為紅色
??????????}
??????????g.drawString(“剩余時間:??“?+?rt?220?16);
??????}
??};
??//?菜單項
??private?JMenuItem?m_start?=?new?JMenuItem(“開始新游戲(S)“);
??private?JMenuItem?m_time?=?new?JMenuItem(“游戲時間限制(L)“);
??private?JMenuItem?m_return?=?new?JMenuItem(“返回主界面(R)“);
??private?JMenuItem?m_exit?=?new?JMenuItem(“退出游戲(Q)“);
??private?JMenuItem?m_savefile?=?new?JMenuItem(“保存迷宮結構(W)“);
??private?JMenuItem?m_importfile?=?new?JMenuItem(“導入迷宮結構(I)“);
??private?JMenuItem?m_selfconfig?=?new?JMenuItem(“編輯當前迷宮(E)“);
??private?JMenuItem?m_randommake?=?new?JMenuItem(“隨機生成迷宮(Z)“);
??private?JMenuItem?m_sortpath?=?new?JMenuItem(“顯示最短路徑(T)“);
??private?JMenuItem?m_DFSpath?=?new?JMenuItem(“隨意顯示一個路徑(K)“);
??private?JMenuItem?m_help?=?new?JMenuItem(“游戲使用說明(H)“);
??private?JMenuItem?m_about?=?new?JMenuItem(“關于迷宮游戲(A)“);
??private?JButton?btn_4?=?new?JButton(“音樂(F)“);
??@SuppressWarnings(“deprecation“)
??map(int?x?int?y)?{
??????m?=?x;
??????n?=?y;
??????tp?=?new?wrmPane[m][n];
??????timelimit?=?remaintime?=?0;????????????????//初始化時,時間為0,代表沒有時間限制
??????timeThread?=?new?Thread(this);
??????timeThread.start();
??????timeThread.suspend();
??????//菜單
??????JMenu?game?=?new?JMenu(“游戲選項“);
??????JMenu?file?=?new?JMenu(“文件“);
??????JMenu?edit?=?new?JMenu(“編輯“);
??????JMenu?tip?=?new?JMenu(“提示“);
??????JMenu?help?=?new?JMenu(“幫助“);
??????game.add(m_start);
??????game.add(m_time);
??????game.add(m_return);
??????game.add(m_exit);
??????file.add(m_savefile);
??????file.add(m_importfile);
??????edit.add(m_selfconfig);
??????edit.add(m_randommake);
??????tip.add(m_sortpath);
??????tip.add(m_DFSpath);
??????help.add(m_help);
??????help.add(m_about);
??????
??????//菜單欄
??????JMenuBar?menu?=?new?JMenuBar();
??????menu.add(game);
??????menu.add(file);
??????menu.add(edit);
??????menu.add(tip);
??????menu.add(help);
??????//初始化迷宮組件并生成隨機路徑
??????for?(int?i?=?0;?i???????????for
評論
共有 條評論