MinesweeperApp.java
import javax.swing.SwingUtilities;import javax.swing.UIManager;import javax.swing.plaf.metal.MetalLookAndFeel;/**程序入口设置系统外观并启动扫雷界面*/public class MinesweeperApp {public static void main(String[] args) {try {UIManager.setLookAndFeel(new MetalLookAndFeel());} catch (Exception e) {e.printStackTrace();}SwingUtilities.invokeLater(() - new MinesweeperUI().setVisible(true));}}三、项目三星际射击游戏3.1 需求分析在扫雷的回合制基础上升级为 实时动作游戏玩家控制飞船自动/手动发射子弹消灭下落的敌人支持粒子爆炸特效、暂停、难度梯度。3.2 架构设计采用 双 Timer 架构逻辑 Timer16ms更新实体位置、碰撞检测、生成敌人渲染 Timer16ms触发 repaint()与逻辑解耦实体采用 抽象基类 匿名内部类 实现多态绘制。3.3 程序界面屏幕截图 2026-07-02 230114屏幕截图 2026-07-02 230027屏幕截图 2026-07-02 2300123.4 完整代码GameEntity.javaimport java.awt.*;import java.io.Serializable;/**游戏实体基类玩家、敌人、子弹都继承此类*/public abstract class GameEntity implements Serializable {private static final long serialVersionUID 1L;protected double x, y;protected int width, height;protected double speedX, speedY;protected boolean alive true;protected Color color;protected String type;public GameEntity(double x, double y, int width, int height, double speedX, double speedY, Color color, String type) {this.x x;this.y y;this.width width;this.height height;this.speedX speedX;this.speedY speedY;this.color color;this.type type;}public void update() {x speedX;y speedY;}public Rectangle getBounds() {return new Rectangle((int)x, (int)y, width, height);}public boolean intersects(GameEntity other) {return getBounds().intersects(other.getBounds());}public abstract void draw(Graphics2D g2d);public double getX() { return x; }public double getY() { return y; }public int getWidth() { return width; }public int getHeight() { return height; }public boolean isAlive() { return alive; }public void setAlive(boolean alive) { this.alive alive; }public String getType() { return type; }public void setX(double x) { this.x x; }public void setY(double y) { this.y y; }public void setSpeedX(double speedX) { this.speedX speedX; }public void setSpeedY(double speedY) { this.speedY speedY; }}ShootingGame.javaimport java.awt.*;import java.io.Serializable;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.Random;/**射击游戏核心管理所有实体、碰撞检测、分数、难度、存档*/public class ShootingGame implements Serializable {private static final long serialVersionUID 1L;public enum Difficulty { EASY, MEDIUM, HARD }private GameEntity player;private int playerLives 3;private int maxLives 3;private List enemies;private List bullets;private List particles;private boolean running false;private boolean paused false;private boolean gameOver false;private int score 0;private int killCount 0;private int shotCount 0;private int difficulty 1;private String difficultyName “简单”;private transient long startTime;private int elapsedTime 0;private int enemySpawnTimer 0;private int enemySpawnInterval 60;private int enemySpeedBase 2;private Random random new Random();private int width 600;private int height 700;public void init(int width, int height, Difficulty diff) {this.width width;this.height height;this.difficulty diff.ordinal() 1;this.difficultyName diff.name().equals(“EASY”) ? “简单” : diff.name().equals(“MEDIUM”) ? “中等” : “困难”;switch (diff) { case EASY: enemySpawnInterval 80; enemySpeedBase 1; maxLives 5; break; case MEDIUM: enemySpawnInterval 50; enemySpeedBase 2; maxLives 3; break; case HARD: enemySpawnInterval 30; enemySpeedBase 3; maxLives 2; break; } playerLives maxLives; score 0; killCount 0; shotCount 0; elapsedTime 0; gameOver false; paused false; player new GameEntity(width / 2 - 20, height - 80, 40, 40, 0, 0, new Color(50, 130, 220), player) { Override public void draw(Graphics2D g2d) { g2d.setColor(color); int[] xs {(int)x width/2, (int)x, (int)x width}; int[] ys {(int)y, (int)y height, (int)y height}; g2d.fillPolygon(xs, ys, 3); g2d.setColor(Color.CYAN); g2d.fillOval((int)x 15, (int)y 20, 10, 10); } }; enemies new ArrayList(); bullets new ArrayList(); particles new ArrayList(); running true; startTime System.currentTimeMillis();}public void update() {if (!running || paused || gameOver) return;elapsedTime (int)((System.currentTimeMillis() - startTime) / 1000); player.update(); if (player.getX() 0) player.setX(0); if (player.getX() width - player.getWidth()) player.setX(width - player.getWidth()); enemySpawnTimer; if (enemySpawnTimer enemySpawnInterval) { enemySpawnTimer 0; spawnEnemy(); } IteratorGameEntity bit bullets.iterator(); while (bit.hasNext()) { GameEntity b bit.next(); b.update(); if (b.getY() -10) b.setAlive(false); } IteratorGameEntity eit enemies.iterator(); while (eit.hasNext()) { GameEntity e eit.next(); e.update(); if (e.getY() height) { e.setAlive(false); playerLives--; createExplosion(e.getX() e.getWidth()/2, e.getY() e.getHeight(), Color.RED); if (playerLives 0) { gameOver true; running false; } } } IteratorGameEntity pit particles.iterator(); while (pit.hasNext()) { GameEntity p pit.next(); p.update(); if (p.getY() p.getY() 50 || !p.isAlive()) pit.remove(); } for (GameEntity b : bullets) { if (!b.isAlive()) continue; for (GameEntity e : enemies) { if (!e.isAlive()) continue; if (b.intersects(e)) { b.setAlive(false); e.setAlive(false); score 10; killCount; createExplosion(e.getX() e.getWidth()/2, e.getY() e.getHeight()/2, e.color); break; } } } for (GameEntity e : enemies) { if (!e.isAlive()) continue; if (e.intersects(player)) { e.setAlive(false); playerLives--; createExplosion(player.getX() 20, player.getY(), Color.ORANGE); if (playerLives 0) { gameOver true; running false; } } } bullets.removeIf(b - !b.isAlive()); enemies.removeIf(e - !e.isAlive());}private void spawnEnemy() {int w 30 random.nextInt(20);int h 30 random.nextInt(20);int ex random.nextInt(width - w);int speed enemySpeedBase random.nextInt(2);Color[] colors {Color.RED, Color.MAGENTA, Color.ORANGE, new Color(200, 50, 50)};Color c colors[random.nextInt(colors.length)];GameEntity enemy new GameEntity(ex, -h, w, h, 0, speed, c, enemy) { Override public void draw(Graphics2D g2d) { g2d.setColor(color); g2d.fillOval((int)x, (int)y, width, height); g2d.setColor(Color.WHITE); g2d.fillOval((int)x 5, (int)y 5, width - 10, height / 3); } }; enemies.add(enemy);}public void shoot() {if (!running || paused || gameOver) return;shotCount;GameEntity bullet new GameEntity(player.getX() player.getWidth()/2 - 3,player.getY() - 10,6, 12, 0, -8, new Color(255, 220, 50), “bullet”) {Overridepublic void draw(Graphics2D g2d) {g2d.setColor(color);g2d.fillRect((int)x, (int)y, width, height);g2d.setColor(Color.WHITE);g2d.fillRect((int)x 2, (int)y, 2, 4);}};bullets.add(bullet);}public void movePlayer(int dx) {if (player ! null) {player.setX(player.getX() dx);}}public void setPlayerX(double x) {if (player ! null) player.setX(x - player.getWidth()/2);}private void createExplosion(double cx, double cy, Color c) {for (int i 0; i 8; i) {double angle Math.random() * Math.PI * 2;double speed 1 Math.random() * 3;final double sx Math.cos(angle) * speed;final double sy Math.sin(angle) * speed;final Color pc c;GameEntity p new GameEntity(cx, cy, 4, 4, sx, sy, pc, “particle”) {private int life 20;Overridepublic void update() {super.update();life–;if (life 0) setAlive(false);}Overridepublic void draw(Graphics2D g2d) {g2d.setColor(pc);g2d.fillOval((int)x, (int)y, width, height);}};particles.add§;}}public void draw(Graphics2D g2d) {g2d.setColor(new Color(20, 20, 40));g2d.fillRect(0, 0, width, height);g2d.setColor(new Color(255, 255, 255, 80)); for (int i 0; i 50; i) { int sx (i * 37 13) % width; int sy (i * 23 7) % height; g2d.fillOval(sx, (sy elapsedTime * 10) % height, 2, 2); } for (GameEntity p : particles) p.draw(g2d); for (GameEntity e : enemies) e.draw(g2d); for (GameEntity b : bullets) b.draw(g2d); if (player ! null playerLives 0) player.draw(g2d); g2d.setColor(Color.WHITE); g2d.setFont(new Font(微软雅黑, Font.BOLD, 16)); g2d.drawString(分数: score, 15, 25); g2d.drawString(时间: elapsedTime 秒, 150, 25); g2d.drawString(击杀: killCount, 280, 25); g2d.drawString(发射: shotCount, 400, 25); g2d.drawString(生命: , 15, 50); for (int i 0; i maxLives; i) { if (i playerLives) { g2d.setColor(Color.RED); g2d.fillOval(60 i * 20, 38, 12, 12); } else { g2d.setColor(Color.GRAY); g2d.drawOval(60 i * 20, 38, 12, 12); } } g2d.setColor(Color.YELLOW); g2d.drawString(难度: difficultyName, width - 100, 25); if (gameOver) { g2d.setColor(new Color(0, 0, 0, 180)); g2d.fillRect(0, 0, width, height); g2d.setColor(Color.WHITE); g2d.setFont(new Font(微软雅黑, Font.BOLD, 40)); String msg playerLives 0 ? 游戏结束 : 胜利; int msgW g2d.getFontMetrics().stringWidth(msg); g2d.drawString(msg, (width - msgW) / 2, height / 2 - 40); g2d.setFont(new Font(微软雅黑, Font.PLAIN, 20)); String info 最终得分: score 击杀: killCount 用时: elapsedTime 秒; int infoW g2d.getFontMetrics().stringWidth(info); g2d.drawString(info, (width - infoW) / 2, height / 2 10); g2d.setFont(new Font(微软雅黑, Font.PLAIN, 16)); String hint 按 R 重新开始 或 空格 发射; int hintW g2d.getFontMetrics().stringWidth(hint); g2d.drawString(hint, (width - hintW) / 2, height / 2 50); } if (paused !gameOver) { g2d.setColor(new Color(0, 0, 0, 120)); g2d.fillRect(0, 0, width, height); g2d.setColor(Color.YELLOW); g2d.setFont(new Font(微软雅黑, Font.BOLD, 36)); String msg 暂 停; int msgW g2d.getFontMetrics().stringWidth(msg); g2d.drawString(msg, (width - msgW) / 2, height / 2); g2d.setFont(new Font(微软雅黑, Font.PLAIN, 16)); g2d.drawString(按 P 继续, (width - 60) / 2, height / 2 40); }}public boolean isRunning() { return running; }public boolean isPaused() { return paused; }public boolean isGameOver() { return gameOver; }public int getScore() { return score; }public int getKillCount() { return killCount; }public int getShotCount() { return shotCount; }public int getElapsedTime() { return elapsedTime; }public int getPlayerLives() { return playerLives; }public int getDifficulty() { return difficulty; }public String getDifficultyName() { return difficultyName; }public int getWidth() { return width; }public int getHeight() { return height; }public void setPaused(boolean paused) {this.paused paused;if (!paused) {startTime System.currentTimeMillis() - elapsedTime * 1000L;}}public void setRunning(boolean running) { this.running running; }public void setGameOver(boolean gameOver) { this.gameOver gameOver; }public void setScore(int score) { this.score score; }public void setKillCount(int killCount) { this.killCount killCount; }public void setShotCount(int shotCount) { this.shotCount shotCount; }public void setElapsedTime(int elapsedTime) { this.elapsedTime elapsedTime; }public void setPlayerLives(int playerLives) { this.playerLives playerLives; }public void setDifficulty(int difficulty) { this.difficulty difficulty; }public void setDifficultyName(String difficultyName) { this.difficultyName difficultyName; }public void setStartTime(long startTime) { this.startTime startTime; }public List getEnemies() { return enemies; }public List getBullets() { return bullets; }public List getParticles() { return particles; }public GameEntity getPlayer() { return player; }public void setPlayer(GameEntity player) { this.player player; }public void setEnemies(List enemies) { this.enemies enemies; }public void setBullets(List bullets) { this.bullets bullets; }public void setParticles(List particles) { this.particles particles; }public void setMaxLives(int maxLives) { this.maxLives maxLives; }public int getMaxLives() { return maxLives; }public void setEnemySpawnInterval(int interval) { this.enemySpawnInterval interval; }public void setEnemySpeedBase(int speed) { this.enemySpeedBase speed; }public int getEnemySpawnInterval() { return enemySpawnInterval; }public int getEnemySpeedBase() { return enemySpeedBase; }}GameState.java射击import java.io.Serializable;import java.util.List;/**射击游戏存档状态*/public class GameState implements Serializable {private static final long serialVersionUID 1L;private List enemies, bullets, particles;private GameEntity player;private int playerLives, maxLives;private int score, killCount, shotCount, elapsedTime;private boolean running, paused, gameOver;private int difficulty, enemySpawnInterval, enemySpeedBase;private String difficultyName;private int width, height;public GameState(ShootingGame game) {this.enemies game.getEnemies();this.bullets game.getBullets();this.particles game.getParticles();this.player game.getPlayer();this.playerLives game.getPlayerLives();this.maxLives game.getMaxLives();this.score game.getScore();this.killCount game.getKillCount();this.shotCount game.getShotCount();this.elapsedTime game.getElapsedTime();this.running game.isRunning();this.paused game.isPaused();this.gameOver game.isGameOver();this.difficulty game.getDifficulty();this.difficultyName game.getDifficultyName();this.enemySpawnInterval game.getEnemySpawnInterval();this.enemySpeedBase game.getEnemySpeedBase();this.width game.getWidth();this.height game.getHeight();}public List getEnemies() { return enemies; }public List getBullets() { return bullets; }public List getParticles() { return particles; }public GameEntity getPlayer() { return player; }public int getPlayerLives() { return playerLives; }public int getMaxLives() { return maxLives; }public int getScore() { return score; }

相关新闻

如何读论文【论文精读·1】

如何读论文【论文精读·1】

如何读论文【论文精读1】如何读论文【论文精读1】论文结构第一遍(海选,约10–15分钟)第二遍(精选,整体通读)第三遍(精读,深度复刻)如何读论文【论文精读1】 论文结构 标…

2026/7/21 17:50:31 阅读更多 →
3分钟快速上手:Python逆运动学库IKPy终极指南

3分钟快速上手:Python逆运动学库IKPy终极指南

3分钟快速上手:Python逆运动学库IKPy终极指南 【免费下载链接】ikpy IKPy, an Universal Inverse Kinematics library 项目地址: https://gitcode.com/gh_mirrors/ik/ikpy IKPy是一个专注于性能和模块化的Python逆运动学库,让开发者能够轻松计算各…

2026/7/21 17:50:31 阅读更多 →
2026毕业必看|90%学生论文翻车的5个真相!避开这些坑,免费稳过双检

2026毕业必看|90%学生论文翻车的5个真相!避开这些坑,免费稳过双检

2026年毕业审核真的变严了,不是危言耸听。 今年很多同学不是写不出论文,而是辛辛苦苦写完,最后栽在不起眼的细节里:查重忽高忽低、AI检测红标、开题被打回、格式扣分、答辩无话可答。 更冤的是:不少人花几百块买查重…

2026/7/21 17:50:33 阅读更多 →

最新新闻

专科生论文写作利器:8款AI工具实测与组合使用指南

专科生论文写作利器:8款AI工具实测与组合使用指南

1. 论文写作困境与AI工具的崛起又到了一年一度的毕业季,对于广大专科院校的学生来说,毕业论文无疑是求学路上最后一道关卡。不同于本科院校有专门的论文指导课程,很多专科生在面对学术写作时常常感到无从下手——不知道如何选题、不会组织论文…

2026/7/22 9:22:17 阅读更多 →
Python开发工作流优化:10个提升效率的实用技巧

Python开发工作流优化:10个提升效率的实用技巧

1. 为什么Python高手也需要优化工作流? 在Python开发领域摸爬滚打多年后,我发现一个有趣的现象:许多能写出复杂算法的开发者,却常常被重复性任务和低效流程困扰。上周我review团队代码时,发现一位能用TensorFlow实现自…

2026/7/22 9:22:17 阅读更多 →
C++连连看游戏开发全解析:从算法到图形界面实战

C++连连看游戏开发全解析:从算法到图形界面实战

1. 项目概述:从“玩”到“造”,理解连连看背后的工程逻辑 “连连看”这个游戏,大家肯定都不陌生。鼠标点点,消除一对对相同的图案,看似简单,背后却是一套完整的逻辑和算法。作为一个有十多年经验的开发者&a…

2026/7/22 9:22:17 阅读更多 →
C语言指针核心原理与安全实践指南

C语言指针核心原理与安全实践指南

1. 指针的本质与内存模型指针本质上就是一个存储内存地址的变量。在32位系统中,指针变量占4字节;在64位系统中则占8字节。理解指针的关键在于建立正确的内存模型认知。每个变量在内存中都有确定的存储位置,这个位置用地址表示。例如&#xff…

2026/7/22 9:22:17 阅读更多 →
Unity游戏AI本地化插件配置指南:3分钟集成多语言翻译

Unity游戏AI本地化插件配置指南:3分钟集成多语言翻译

1. 项目概述:为什么我们需要AI驱动的游戏本地化?如果你是一个独立游戏开发者,或者在一个小型团队里负责全球化发行,那么“本地化”这个词对你来说,可能既熟悉又头疼。熟悉是因为你知道,想让游戏在欧美、日韩…

2026/7/22 9:22:16 阅读更多 →
M2 Mac本地AI智能体搭建与优化指南

M2 Mac本地AI智能体搭建与优化指南

1. 项目概述:M2 Mac本地AI智能体搭建方案在2023年Mac设备性能大幅跃升的背景下,16GB版M2 Mac已成为本地运行AI模型的理想平台。这个方案的核心价值在于:完全摆脱对云服务的依赖,所有数据处理都在本地完成,既保障隐私安…

2026/7/22 9:21:16 阅读更多 →

日新闻

TI DSP系统配置模块SYSCFG详解:中断机制与主设备优先级配置实战

TI DSP系统配置模块SYSCFG详解:中断机制与主设备优先级配置实战

1. 项目概述与SYSCFG模块的核心价值在嵌入式系统,尤其是像TI C6000系列这样的高性能DSP开发中,我们常常会与芯片手册里那些密密麻麻的寄存器打交道。很多开发者可能更关注算法实现、内存优化或者外设驱动,但对于一个稳定、高效的系统而言&…

2026/7/22 0:00:26 阅读更多 →
微信Server酱:高到达率的应急通知方案实践

微信Server酱:高到达率的应急通知方案实践

1. 为什么我们需要"最次"的通知方案? 在数字化协作环境中,消息通知系统的重要性不言而喻明。但现实情况是,企业级通知方案往往需要复杂的API对接(如企业微信、钉钉、飞书),个人开发者的小项目又经…

2026/7/22 0:00:26 阅读更多 →
甲方要的“简洁“PPT,到底是简洁还是省事?

甲方要的“简洁“PPT,到底是简洁还是省事?

甲方说"简洁一点",乙方听到的是"少做几页"。甲方说"不要太复杂",乙方理解成"别放图表了"。结果交过去,甲方说"我说的简洁不是这个意思"。"简洁"这个词在PPT语境里,是…

2026/7/22 0:00:26 阅读更多 →

周新闻

Go语言静态资源打包方案对比与实践指南

Go语言静态资源打包方案对比与实践指南

1. 项目背景与核心需求在Go语言开发中,我们经常需要处理静态资源文件的打包问题。无论是Web应用的模板文件、前端资源,还是配置文件、证书等,都需要随程序一起分发。传统做法是将这些文件与编译后的二进制文件放在同一目录下,但这…

2026/7/22 8:58:19 阅读更多 →
Go语言实现高性能LDAP认证服务的架构与实践

Go语言实现高性能LDAP认证服务的架构与实践

1. 项目背景与核心价值LDAP(轻量级目录访问协议)作为企业级身份认证的黄金标准,已经服务了超过80%的财富500强公司。我在金融科技领域实施统一认证体系时,发现传统Java方案存在启动慢、内存占用高等痛点。而Go语言凭借其协程并发模…

2026/7/21 5:34:47 阅读更多 →
【AI面试官实战指南】:用ChatGPT模拟10类高频技术岗面试,3天提升应答精准度92%

【AI面试官实战指南】:用ChatGPT模拟10类高频技术岗面试,3天提升应答精准度92%

更多请点击: https://intelliparadigm.com 第一章:AI面试官实战指南的核心价值与适用场景 AI面试官并非替代人类HR的“黑箱工具”,而是以可解释、可审计、可迭代的方式,赋能招聘全链路的关键基础设施。其核心价值在于将主观经验沉…

2026/7/21 8:25:39 阅读更多 →

月新闻