project.zip
大小:691.1KB
价格:10积分
下载量:0
评分:
5.0
上传者:2402_82740483
更新日期:2025-09-22

高级开发简单游戏制作,期末项目答辩小组作业

资源文件列表(大概)

文件名
大小
project/
-
project/.idea/
-
project/.idea/.gitignore
50B
project/.idea/misc.xml
206B
project/.idea/modules.xml
273B
project/.idea/project.iml
429B
project/.idea/uiDesigner.xml
8.71KB
project/.idea/workspace.xml
1.89KB
project/Explosion.java
1.31KB
project/explosion.PNG
100.09KB
project/game_log.html
-
project/game_log.html.1
-
project/grasses.gif
106.86KB
project/MainApp.java
8KB
project/out/
-
project/out/production/
-
project/out/production/project/
-
project/out/production/project/.idea/
-
project/out/production/project/.idea/.gitignore
50B
project/out/production/project/.idea/misc.xml
206B
project/out/production/project/.idea/modules.xml
273B
project/out/production/project/.idea/project.iml
429B
project/out/production/project/.idea/workspace.xml
1.91KB
project/out/production/project/Explosion.class
1.61KB
project/out/production/project/explosion.PNG
100.09KB
project/out/production/project/game_log.html
-
project/out/production/project/game_log.html.1
-
project/out/production/project/grasses.gif
106.86KB
project/out/production/project/MainApp$1.class
1.25KB
project/out/production/project/MainApp.class
8.1KB
project/out/production/project/Professor.class
2.56KB
project/out/production/project/professor.png
25.63KB
project/out/production/project/splash.png
74.44KB
project/out/production/project/Student1.class
3.05KB
project/out/production/project/student1.png
11.56KB
project/out/production/project/Student2.class
2.93KB
project/out/production/project/student2.png
12.24KB
project/out/production/project/Students.class
257B
project/out/production/project/util/
-
project/out/production/project/util/Direction.class
1.07KB
project/out/production/project/util/LoggerUtil.class
1.78KB
project/Professor.java
2.44KB
project/professor.png
25.63KB
project/splash.png
74.44KB
project/Student1.java
2.3KB
project/student1.png
11.56KB
project/Student2.java
3.13KB
project/student2.png
12.24KB
project/Students.java
300B
project/util/
-
project/util/Direction.java
73B
project/util/LoggerUtil.java
1.09KB

资源内容介绍

期末项目答辩
import javax.imageio.ImageIO;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.Random;import java.util.logging.FileHandler;import java.util.logging.Level;import java.util.logging.Logger;import java.util.logging.SimpleFormatter;public class MainApp extends JPanel { private ArrayList<Students> students; private List<Explosion> explosions; private Professor professor; private BufferedImage splashImage; // splash.png 初始背景图片 private BufferedImage gameBackground; // grasses.gif 游戏背景图片 private Random random; private int score; private int timeLeft; private boolean showSplash; private boolean gameStarted; private Logger logger; public MainApp() { students = new ArrayList<>(); explosions = new ArrayList<>(); random = new Random(); score = 0; timeLeft = 60; showSplash = true; gameStarted = false; setupLogger(); try { splashImage = ImageIO.read(new File("splash.png")); // 初始背景图片 gameBackground = ImageIO.read(new File("grasses.gif")); // 游戏背景图片 } catch (IOException e) { e.printStackTrace(); } professor = new Professor("professor.png", 100, 100); setFocusable(true); requestFocusInWindow(); addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE) { if (showSplash) { showSplash = false; // 停止显示 splash.png repaint(); } else if (!gameStarted) { gameStarted = true; // 开始游戏 generateRandomStudents(); repaint(); } } else if (gameStarted) { switch (e.getKeyCode()) { case KeyEvent.VK_UP: professor.moveUp(getHeight()); break; case KeyEvent.VK_DOWN: professor.moveDown(getHeight()); break; case KeyEvent.VK_LEFT: professor.moveLeft(getWidth()); break; case KeyEvent.VK_RIGHT: professor.moveRight(getWidth()); break; } repaint(); checkCollisions(); } } }); // 计时器,用于显示初始背景 3 秒后切换到 grasses.gif Timer splashTimer = new Timer(3000, e -> { if (showSplash) { showSplash = false; repaint(); } }); splashTimer.setRepeats(false); splashTimer.start(); new Timer(1000, e -> { if (gameStarted) { timeLeft--; if (timeLeft <= 0) { endGame(); } } repaint(); }).start(); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); if (showSplash) { g.drawImage(splashImage, 0, 0, getWidth(), getHeight(), null); // 显示初始背景 } else if (!gameStarted) { g.drawImage(gameBackground, 0, 0, getWidth(), getHeight(), null); // 显示游戏背景 g.setColor(Color.WHITE); g.setFont(new Font("Arial", Font.BOLD, 30)); g.drawString("Press SPACE to start the game", getWidth() / 4, getHeight() / 2); } else { g.drawImage(gameBackground, 0, 0, getWidth(), getHeight(), null); professor.draw(g); // 绘制教授 for (Students student : students) { student.draw(g); // 绘制学生 } for (Explosion explosion : explosions) { explosion.draw(g); // 绘制爆炸效果 } // 显示时间倒计时在左上方 g.setColor(Color.BLUE); g.fillRect(10, 10, 150, 30); g.setColor(Color.RED); g.drawString("Time: " + timeLeft, 20, 30); // 显示积分在右上方 g.setColor(Color.GREEN); g.fillRect(getWidth() - 160, 10, 150, 30); g.setColor(Color.BLACK); g.drawString("Score: " + score, getWidth() - 150, 30); } } private void generateRandomStudents() { students.clear(); int panelWidth = getWidth(); int panelHeight = getHeight(); if (panelWidth <= 0 || panelHeight <= 0) { System.err.println("Error: Invalid game window size."); return; } int studentType = random.nextInt(2); int x = random.nextInt(panelWidth - 64); int y = random.nextInt(panelHeight - 64); if (studentType == 0) { Student1 student1 = new Student1("student1.png", x, y); students.add(student1); } else { Student2 student2 = new Student2("student2.png", x, y); students.add(student2); } } private void checkCollisions() { Iterator<Students> iterator = students.iterator(); while (iterator.hasNext()) { Students student = iterator.next(); if (professor.getBounds().intersects(student.getBounds())) { handleCollision(student.getX(), student.getY()); iterator.remove(); score+=random.nextInt(9); } } if (students.isEmpty()) { generateRandomStudents(); } } private void handleCollision(int x, int y) { explosions.add(new Explosion("explosion.png", x, y)); Timer explosionTimer = new Timer(500, e -> explosions.remove(0)); explosionTimer.setRepeats(false); explosionTimer.start(); } private void endGame() { gameStarted = false; String message = "Game Over! Your score: " + score; int option = JOptionPane.showConfirmDialog(this, message + "\nDo you want to play again?", "Game Over", JOptionPane.YES_NO_OPTION); if (option == JOptionPane.YES_OPTION) { resetGame(); } else { System.exit(0); } } private void resetGame() { score = 0; timeLeft = 60; students.clear(); explosions.clear(); professor.setPosition(100, 100); showSplash = true; gameStarted = false; repaint(); // 重启初始背景计时器 Timer splashTimer = new Timer(3000, e -> { if (showSplash) { showSplash = false; repaint(); } }); splashTimer.setRepeats(false); splashTimer.start(); } private void setupLogger() { logger = Logger.getLogger("GameLogger"); try { FileHandler fileHandler = new FileHandler("game_log.html"); fileHandler.setFormatter(new SimpleFormatter()); logger.addHandler(fileHandler); } catch (IOException e) { e.printStackTrace(); } logger.setLevel(Level.INFO); } public static void main(String[] args) { JFrame frame = new JFrame("Zhu Haoyuan-20232099 and Zhou Sian-20232036"); Mai

用户评论 (0)

发表评论

captcha

相关资源

电机控制器,谐波电流注入 为解决汽车NvH而开发,旨在消除转矩谐波,降低运行噪声……已成功应用于某项目

电机控制器,谐波电流注入 为解决汽车NvH而开发,旨在消除转矩谐波,降低运行噪声……已成功应用于某项目

527.94KB16积分

MATLAB代码:基于小生境粒子群算法的配电网有功-无功协调优化关键词:配电网优化 有功-无功优化 小升境粒子群 光伏波动性 DG配电网 参考文档:模型部分参考:基于粒子群算法的含光伏电站的配

MATLAB代码:基于小生境粒子群算法的配电网有功-无功协调优化关键词:配电网优化 有功-无功优化 小升境粒子群 光伏波动性 DG配电网 参考文档:模型部分参考:《基于粒子群算法的含光伏电站的配电网无功优化_孙卓新》算法部分参考:《分布式光伏接入的配电网无功优化研究_武晓朦》仿真平台:MATLAB主要内容:代码主要做的是考虑光伏出力波动性的配电网有功无功协调优化,在调度模型中考虑了光伏并网的波动性,并考虑用储能对其进行平抑,配电网调度模型中含有的设备主要包括:光伏逆变器、变压器、电容等设备,目标函数包括调压总成本、电压稳定性、网损等等,采用改进多目标粒子群算法,即小生境粒子群算法对其进行高效求解。此方法更加具有创新性,代码非常精品,注释保姆级

631.66KB11积分

基于储能的直驱风电机组并网仿真模型直驱风电机组,先整流后逆变,不控整流器?pwm控制逆变器,出口电压380v,蓄电池储能经dcdc变器接入直流母线,可控制充放电,直流母线接有直流负载,可做加减负载突

基于储能的直驱风电机组并网仿真模型直驱风电机组,先整流后逆变,不控整流器?pwm控制逆变器,出口电压380v,蓄电池储能经dcdc变器接入直流母线,可控制充放电,直流母线接有直流负载,可做加减负载突变测试蓄电池充放电反应,后经并网逆变器并入交流电网。可做故障穿越,蓄电池充放电,负载投切,并网电压电流谐波分析等实验。

1.8MB11积分

MATLAB代码:用于平抑可再生能源功率波动的储能电站建模及评价关键词:储能电站 功率波动 并网 平抑可再生能源参考文档:《用于平抑可再生能源功率波动的储能电站建模及评价》仅参考光伏发电容量可

MATLAB代码:用于平抑可再生能源功率波动的储能电站建模及评价关键词:储能电站 功率波动 并网 平抑可再生能源参考文档:《用于平抑可再生能源功率波动的储能电站建模及评价》仅参考《光伏发电容量可信度评估》参考风电与负荷一致性问题思路仿真平台:MATLAB yalmip主要内容:代码主要做的是一个通过储能电站平抑可再生能源波动的问题,通过储能电站平抑可再生能源的波动,建立了两种不同的储能平抑策略,使得风电功率曲线以及光伏曲线变得光滑,从而可以减少并网功率波动;此外,还研究了如何通过储能电站使得风光曲线与负荷曲线趋于一致,从而更好的将分布式能源用于供负荷。实现效果良好,具体看图。代码非常精品,注释保姆级

383.84KB38积分