当前位置: 首页 > 编程日记 > 正文

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

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

功能简介:

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

游戏服务页面:

/*** 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();}
}

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

相关文章:

GTONE清理维护建议方案

1、日志清理/home/gtone/AppGov/analyzer/log//home/gtone/AppGov/analyzer/SRC/temp//home/gtone/AppGov/WAS/logs/ 2、扩容现有磁盘空间至200GB转载于:https://www.cnblogs.com/arcer/p/4461018.html

[C#]委托和事件(讲解的非常不错)

引言 委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易。它们就像是一道槛儿,过了这个槛的人,觉得真是太容易了,而没有过去的人每次见到委托和事件就觉…

BZOJ1460: Pku2114 Boatherds

题目链接:点这里 题目描述:给你一棵n个点的带权有根树,有p个询问,每次询问树中是否存在一条长度为Len的路径,如果是,输出Yes否输出No. 数据范围:\(n\le1e5\,,p\le100\,,长度\le1e5\) Solution: …

centos 自定义内核模块 编译运行

简单记录一下 centos 自定义内核模块的一些编译运行记录&#xff0c;代码如下&#xff1a; 主要功能是通过rdtsc 指令直接从 CPU MSR 寄存器中获取时钟&#xff0c;尝试获取两次&#xff0c;两次之间会做一些赋值操作什么的&#xff0c;并记录一下时差。 #include <linux/…

os.system() 和 os.popen()

1.os.popen(command[, mode[, bufsize]]) os.system(command)2.os.popen() 功能强于os.system() , os.popen() 可以返回回显的内容&#xff0c;以文件描述符返回。eg:t_f os.popen ("ping 192.168.1.1")print t_f.read()或者:for line in os.popen("dir"…

Java项目:医院管理系统(java+Springboot+Maven+Mybatis+Vue+Mysql)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述本系统功能包括&#xff1a;医院挂号&#xff0c;退号&#xff0c;缴费&#xff0c;退费&#xff0c;检查申请单开立&#xff0c;科室管理&#xff0c;医生开单&#xff0c;挂号级别&#xff0c…

任意阶幻方..

1 /*coder Gxjun*/2 #include<stdio.h>3 #include<string.h>4 #include<stdlib.h>5 #define maxn 1006 int map[maxn][maxn] ;7 void creat_magic(int n,int x,int y ,int sn) //奇阶幻方构造8 {9 int i,j,k;10 i0;11 jn/2;12 for(kn;k<…

UML与软件建模 第三次作业

1.单元测试的任务有哪些&#xff1f; 单元测试是对软件基本组成单元进行的测试,而且软件单元是与程序的其他部分相隔离的情况下进行独立的测试. 任务主要包括对单元功能、逻辑控制、数据和安全性等各方面进行必要的测试。具体地说&#xff0c;包括单元中所有独立执行路径、数据…

Pliops XDP(Extreme Data Processor)数据库存储设计的新型加速硬件

文章目录0 前言1 核心问题1.1 引擎的各方面性能受限于数据结构的选择1.2 压缩功能 导致的CPU瓶颈1.3 Crash-safe 崩溃异常的无奈选择1.4 当前主流 加速硬件 较难满足存储性能提升的要求2 XDP 设计原则2.1 数据结构上的优化2.2 解决 压缩引入的CPU消耗2.3 异常恢复的设计2.4 易于…

Java项目:潜艇大战项目(java+swing)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 功能简介&#xff1a; Java swing实现的一款小游戏潜艇大战的项目源码 游戏界面&#xff1a; SuppressWarnings({ "unused", "serial" }) public class GameGUI extends JPanel {//卡…

可以发张图片做链接用吗

转载于:https://www.cnblogs.com/wasss/p/4466492.html

更改显示器的分辨率

1.桌面右击&#xff0c;如图1-1所示。2.点击屏幕分辩率&#xff0c;选择分辨率调大小&#xff0c;确定&#xff0c;如图1-2所示。转载于:https://blog.51cto.com/qikai/1367734

Java 处理0x00特殊字符

Java 处理0x00特殊字符 一、0x00字符 1&#xff0c;0x00是ascii码的0值&#xff1a;NUL 2&#xff0c;0x00在windows系统中显示&#xff1a; 3&#xff0c;0x00在Linux中显示&#xff1a; ctrlV ctrl可以打出此字符 二、Java解决0x00字符 str.replaceAll("\\u0000",&…

关于 并查集(union find) 算法基本原理 以及 其 在分布式图场景的应用

二月的最后一篇水文…想写一些有意思的东西。 文章目录环检测在图数据结构中的应用深度/广度优先 检测环并查集数据结构 (Union-Find)基本概念初始化合并 union查找祖先优化1: 合并过程 利用 rank 优化路径优化2: 路径压缩(Path Compression)并查集 解决图中检测环问题环检测在…

Java项目:智能制造生产管理平台(java+SSM+mysql+Maven+Easyui+JSP)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 运行环境&#xff1a;jdk1.8、tomcat7.0/8.5、Mysql5.7/5.1、Maven3.6/3.5、 eclipse/STS 功能简介&#xff1a;计划进度、设备管理、工艺监控、物料监控、质量监控、人员监控等 访问注册控制层&#xff1a;…

JAVA-Eclipse快捷键

Ctrl1&#xff1a;快速修复。CtrlD:快速删除行。ShiftEnter&#xff1a;快速调到下一行。CtrlF11:快速运行。Alt上下方向键&#xff1a;快速移动。CtrlM:光标所在视图最大化。Alt/:智能补全。Ctrl/&#xff1a;快速注释代码。 转载于:https://www.cnblogs.com/bluewhy/p/44669…

Android RelativeLayout属性

// 相对于给定ID控件android:layout_above 将该控件的底部置于给定ID的控件之上;android:layout_below 将该控件的底部置于给定ID的控件之下;android:layout_toLeftOf 将该控件的右边缘与给定ID的控件左边缘对齐;android:layout_toRightOf 将该控件的左边缘与给定ID的控件右边缘…

详解Azure的权限控制

注意&#xff1a;本文档仅限于Azure国际版&#xff0c;国内版略有不同Azure中的角色分配相对来说是比较复杂的的&#xff0c;对于任何云组织来说&#xff0c;云的资源访问管理权限都是一项非常重要的功能&#xff0c;azure中的授权系统叫做基于角色的访问控制&#xff08;RBAC&…

SNMP introduction

简单网络管理协议(SNMP)首先是由Internet工程任务组织(Internet Engineering Task Force)(IETF)的研究小组为了解决Internet上的路由器管理问题而提出的。许多人认为 SNMP在IP上运行的原因是Internet运行的是TCP/IP协议&#xff0c;然而事实并不是这样。 SNMP被设计成与协议无…

Java项目:在线考试系统(java+SSM+mysql+JSP)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 运行环境&#xff1a;jdk1.8、Mysql5.7、Tomcat8.5、IDEA/Eclipse 功能简介&#xff1a;在线考试、历史回顾、个人成绩查询等。 管理员和教师功能有&#xff1a;学院管理、班级管理、课程管理、教师、学生…

Keil中使用宏编译来定义DEBUG输出

使用宏编译来格式化调试信息&#xff0c;是一个不错的方法&#xff0c;即可以在需要的时候打印出信息&#xff0c;还可以格式化我们所需要的输出。 #define DEBUG 1 #if (DEBUG 1) #define DBG(Args...) printf(##Args) #define DBGFL(s, Args...) printf("[%s:%d]&qu…

解决用户使用临时配置文件登陆WIN7的问题

用户登录Win7后&#xff0c;经常会遇到 “您已使用临时配置文件登陆” 的提示,忽略此提示的用户通常在桌面上保留的文件再次重启进入后发现文件丢失了&#xff0c;或者原有桌面上的文件不见了&#xff0c;这样一定程度上降低了工作的效率.这里主要说一下如何解决此问题。用户登…

chosen.jquery.js 有搜索功能、多选功能的下拉框插件

chosen.jquery.js 有搜索功能、多选功能的下拉框插件 官方源码&#xff1a; https://github.com/harvesthq/chosen 该源码中的样例index.html有该插件的详细使用介绍posted on 2019-05-09 14:40 三天打鱼&#xff0c;两天晒网 阅读(...) 评论(...) 编辑 收藏 转载于:https://w…

MIB in SNMP

管理信息库MIB指明了网络元素所维持的变量&#xff08;即能够被管理进程查询和设置的信息&#xff09;。MIB给出了一个网络中所有可能的被管理对象的集合的数据结构。SNMP的管理信息库采用和域名系统DNS相似的树型结构&#xff0c;它的根在最上面&#xff0c;根没有名字。图3画…

Java项目:后台管理系统脚手架项目(java+SpringBoot+FreeMarker+mysql+JSP)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 项目描述&#xff1a; 这是一个基于SpringBoot框架开发的后台管理系统脚手架项目。之所以称为脚手架项目&#xff0c;是因为这个项目复用性很强&#xff0c;如果以后有其他新的项目要设计后台管理系统的话&…

Extjs4.0.7 MVC Architecture异常

uncaught exception: Ext.Loader is not enabled, so dependencies cannot be resolved dynamically. Missing required class: AM.controller.User 解决方法&#xff1a; 在app.js最上面加上&#xff1a;Ext.Loader.setConfig({ enabled: true }); Ext.Loader.setConfig({ …

Mybatis常见面试题(三)

Mybatis 映射文件中&#xff0c;如果 A 标签通过 include 引用了 B 标签的内容&#xff0c;请问&#xff0c; B 标签能否定义在 A 标签的后面&#xff0c;还是说必须定义在 A 标签的前面&#xff1f; :虽然 Mybatis 解析 Xml 映射文件是按照顺序解析的&#xff0c;但是&#x…

SMI in SNMP

SNMP中&#xff0c;数据类型并不多。这里我们就讨论这些数据类型&#xff0c;而不关心这些数据类型在实际中是如何编码的。INTEGER一个变量虽然定义为整型&#xff0c;但也有多种形式。有些整型变量没有范围限制&#xff0c;有些整型变量定义为特定的数值&#xff08;例如&am…

Java项目:在线拍卖竞价系统(java+SpringBoot+FreeMarker+Mysql+redis)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 超级管理员&#xff1a;系统管理、用户管理&#xff08;冻结等&#xff09;、审批竞拍标的物管理、竞标类型管理、审批机构、个人提现管理&#xff08;审核&#xff09;、企业提现管理&#xff08;审批&…

pig脚本不需要后缀名(python tempfile模块生成pig脚本临时文件,执行)

pig 脚本运行不需要后缀名 pig脚本名为tempfile&#xff0c;无后缀名 用pig -f tempfile 可直接运行 另外&#xff0c;pig tempfile也可以直接运行这样就可以用python临时文件存储pig脚本内容直接调用 python调用pig脚本的一种方式 将pig脚本用任意文件存储&#xff0c;执行时写…