源码获取:博客首页 "资源" 里下载!

功能简介:

星际争霸游戏项目,该项目实现了单人模式和多人合作模式,可记录游戏进度,新建游戏,载入历史记录等功能,多人模式下可以创建一个区,然后邀请玩家加入一起玩

游戏服务页面:

/*** Simple abstract class used for testing. Subclasses should implement the* draw() method.*/
public abstract class GameCore extends JFrame {protected static final int FONT_SIZE = 10;private boolean isRunning;protected JFrame window;public void stop() {}/*** Calls init() and gameLoop()*/public void run() {init();gameLoop();}/*** Sets full screen mode and initiates and objects.*/public void init() {setUndecorated(true);setTitle("JStarCraft");setIconImage(ResourceManager.loadImage("title.png"));setDefaultCloseOperation(EXIT_ON_CLOSE);setSize(800, 600);setVisible(true);setIgnoreRepaint(true);setResizable(false);setFont(new Font("Dialog", Font.PLAIN, FONT_SIZE));setBackground(Color.black);setForeground(Color.white);createBufferStrategy(2);isRunning = true;setCursor(Toolkit.getDefaultToolkit().createCustomCursor(ResourceManager.loadImage("cur.png"), new Point(0, 0), "cur"));window = getWindow();NullRepaintManager.install();window.setLayout(null);Container contentPane = getWindow().getContentPane();((JComponent) contentPane).setOpaque(false);}/*** Runs through the game loop until stop() is called.*/public void gameLoop() {BufferStrategy strategy = getBufferStrategy();long startTime = System.currentTimeMillis();long currTime = startTime;while (isRunning) {long elapsedTime = System.currentTimeMillis() - currTime;currTime += elapsedTime;// updateupdate(elapsedTime);// draw the screenGraphics2D g = (Graphics2D) strategy.getDrawGraphics();g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);       // g.drawImage(ResourceManager.loadImage("background3.jpg"), 0, 33,// null);draw(g);g.dispose();if (!strategy.contentsLost()) {strategy.show();}// take a naptry {Thread.sleep(5);} catch (InterruptedException ex) {}}}/*** Updates the state of the game/animation based on the amount of elapsed* time that has passed.*/public void update(long elapsedTime) {// do nothing}/*** Draws to the screen. Subclasses must override this method.*/public abstract void draw(Graphics2D g);public JFrame getWindow() {return this;}
}

游戏核心:

/**Simple abstract class used for testing. Subclasses shouldimplement the draw() method.
*/
public abstract class FullGameCore {protected static final int FONT_SIZE = 24;private static final DisplayMode POSSIBLE_MODES[] = {new DisplayMode(800, 600, 16, 0),new DisplayMode(800, 600, 32, 0),new DisplayMode(800, 600, 24, 0),new DisplayMode(640, 480, 16, 0),new DisplayMode(640, 480, 32, 0),new DisplayMode(640, 480, 24, 0),new DisplayMode(1024, 768, 16, 0),new DisplayMode(1024, 768, 32, 0),new DisplayMode(1024, 768, 24, 0),};private boolean isRunning;protected ScreenManager screen;/**Signals the game loop that it's time to quit*/public void stop() {isRunning = false;}/**Calls init() and gameLoop()*/public void run() {try {init();gameLoop();}finally {screen.restoreScreen();lazilyExit();}}/**Exits the VM from a daemon thread. The daemon thread waits2 seconds then calls System.exit(0). Since the VM shouldexit when only daemon threads are running, this makes sureSystem.exit(0) is only called if neccesary. It's neccesaryif the Java Sound system is running.*/public void lazilyExit() {Thread thread = new Thread() {public void run() {try {Thread.sleep(2000);}catch (InterruptedException ex) { }System.exit(0);}};thread.setDaemon(true);thread.start();}/**Sets full screen mode and initiates and objects.*/public void init() {screen = new ScreenManager();DisplayMode displayMode = screen.findFirstCompatibleMode(POSSIBLE_MODES);screen.setFullScreen(displayMode);JFrame frame = screen.getFullScreenWindow();frame.setFont(new Font("Dialog", Font.PLAIN, FONT_SIZE));frame.setBackground(Color.white);frame.setForeground(Color.white);frame.setTitle("JStarCraft");frame.setIconImage(ResourceManager.loadImage("title.png"));isRunning = true;frame.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(ResourceManager.loadImage("cur.png"), new Point(0, 0), "cur"));NullRepaintManager.install();frame.setLayout(null);((JComponent) frame.getContentPane()).setOpaque(false);}/**Runs through the game loop until stop() is called.*/public void gameLoop() {long startTime = System.currentTimeMillis();long currTime = startTime;while (isRunning) {long elapsedTime =System.currentTimeMillis() - currTime;currTime += elapsedTime;// updateupdate(elapsedTime);// draw the screenGraphics2D g = screen.getGraphics();draw(g);g.dispose();screen.update();//             don't take a nap! run as fast as possibletry {Thread.sleep(5);}catch (InterruptedException ex) { }}}/**Updates the state of the game/animation based on theamount of elapsed time that has passed.*/public void update(long elapsedTime) {// do nothing}/**Draws to the screen. Subclasses must override thismethod.*/public abstract void draw(Graphics2D g);public int getHeight(){return  screen.getFullScreenWindow().getHeight();}public int getWidth(){return  screen.getFullScreenWindow().getWidth();}public JFrame getWindow(){return screen.getFullScreenWindow();}
}

源码获取:博客首页 "资源" 里下载!

Java项目:星际争霸游戏(java+swing+awt界面编程+IO输入输出流+socket+udp网络通信)相关推荐

  1. Java项目:贪吃蛇游戏(java+swing)

    源码获取:博客首页 "资源" 里下载! 功能简介: 贪吃蛇游戏 大嘴鱼洁面类.完成大嘴鱼的界面的绘制: /*** 大嘴鱼洁面类.完成大嘴鱼的界面的绘制.*/ public clas ...

  2. java手机游戏星际争霸_java Swing实现的星际争霸游戏源码

    今天给大家介绍一下由Java swing实现的星际争霸游戏项目,该项目实现了单人模式和多人合作模式,可记录游戏进度,新建游戏,载入历史记录等功能,多人模式下可以创建一个区,然后邀请玩家加入一起玩,主要 ...

  3. 多智能体强化学习_基于多智能体强化学习主宰星际争霸游戏

    大家好,今天我们来介绍基于多智能体强化学习主宰星际争霸游戏这篇论文 Grandmaster level in StarCraft II using multi-agent reinforcement ...

  4. eclipse java转class_Eclipse中的Java项目:无法解析java.lang.Object类型。 它是从所需的.class文件间接引用的...

    Eclipse中的Java项目:无法解析java.lang.Object类型. 它是从所需的.class文件间接引用的 在Eclipse中导入项目后,我收到以下错误: 无法解析java.lang.Ob ...

  5. java io字符输出流_灵魂一击!详解Java中的IO输入输出流

    什么是流?流表示任何有能力产生数据的数据源对象或者是有能力接收数据的接收端对象,它屏蔽了实际的I/O设备中处理数据的细节. IO流是实现输入输出的基础,它可以很方便地实现数据的输入输出操作,即读写操作 ...

  6. java 写的星际争霸_用java写星际争霸的ai

    一直有这个想法很久了.以前也知道可以用BWAPI这个API写星际争霸的ai.但是直接用那个的话一直没调试好,各种版本都搭配不好然后导致星际崩溃,C++又不是很懂只得作罢. 幸好最近发现了这个网站:ht ...

  7. Java实现的五子棋游戏 ~java.awtjava.swing

    文章目录 Java实现的五子棋游戏 1.实现效果 2.实现源码 2.1运行主函数main.java 2.2 棋盘布局Chessboard.java 3.Algorithm算法 点击下载链接:Java实 ...

  8. 用JAVA来制作大鱼吃小鱼游戏,JAVA项目实战

    大鱼吃小鱼,又称吞食鱼,是一款动作类小游戏.通过不断的吞吃比自己小的鱼类快速成长,最终成为海洋霸主. 本课程讲解一个大鱼吃小鱼游戏的详细开发过程.只要60分钟就可以完成一个你自己亲手开发出来的Java ...

  9. 快速熟悉Java -- 《电玩游戏Java实战DIY》

    <电玩游戏Java实战DIY>简介 第1版 (2009年3月1日): Ian Cinnamon,是一位年仅15岁的天才程序员,他现在已经有着7年的编程经验,并且获得Java和C++认证.他 ...

最新文章

  1. 清华沈阳老师团队:元宇宙发展研究报告2.0版
  2. 编程珠玑第九章——习题
  3. UML-如何使用层进行设计?
  4. setsockopt()使用方法(參数具体说明)
  5. 一次性删除数据库中某库的所有存储过程的方法
  6. 【数据结构与算法】之深入解析“学生出勤记录I”的求解思路与算法示例
  7. P7717-「EZEC-10」序列【Trie】
  8. mongodb的delete_大数据技术之MongoDB数据删除
  9. Java RMI 介绍
  10. LVQ,Learning Vector Quantization,学习向量量化
  11. IaaS、PaaS和SaaS的区别
  12. 一加闷声发大财 成为今年第一季度全球高端手机市场前四
  13. MySQL常用优化指南,及大表优化思路(值得收藏)
  14. 徐中约与《中国近代史》 (zz)
  15. ltp-ddt的makefile结构
  16. EXT ajax简单实例
  17. HDU 2196 Computer 树形DP
  18. 慎用"加速"一词,可以使用"早日"代替
  19. 计算机课堂热身游戏,电脑课我们常玩的13个小游戏
  20. 制作纯净系统U盘教程(详细版)

热门文章

  1. 设置vue运行npm run dev时候,项目在浏览器自动打开页面的方法
  2. 在github上创建自己的第一个项目仓库实录
  3. Linux 的内存管理工具和调优参数
  4. 高并发系统搭建:web负载均衡
  5. 基于QProbe创建基本Android图像处理框架
  6. 洛谷1216 数字三角形
  7. Android studio 获取每次编译apk时的日期
  8. 引擎设计跟踪(九.14.2i) Android GLES 3.0 完善
  9. linux的more 命令
  10. C#控制远程计算机的服务