急求java小游戏源代码代码。 百度云

java小游戏源代码大全下载|java小游戏源代码大全下载_快猴软件下载&>&几个java小游戏源代码
几个java小游戏源代码
上传大小:1.71MB
JAVA小游戏,例如中国象棋,贪吃蛇等等
综合评分:0
下载个数:
{%username%}回复{%com_username%}{%time%}\
/*点击出现回复框*/
$(".respond_btn").on("click", function (e) {
$(this).parents(".rightLi").children(".respond_box").show();
e.stopPropagation();
$(".cancel_res").on("click", function (e) {
$(this).parents(".res_b").siblings(".res_area").val("");
$(this).parents(".respond_box").hide();
e.stopPropagation();
/*删除评论*/
$(".del_comment_c").on("click", function (e) {
var id = $(e.target).attr("id");
$.getJSON('/index.php/comment/do_invalid/' + id,
function (data) {
if (data.succ == 1) {
$(e.target).parents(".conLi").remove();
alert(data.msg);
$(".res_btn").click(function (e) {
var parentWrap = $(this).parents(".respond_box"),
q = parentWrap.find(".form1").serializeArray(),
resStr = $.trim(parentWrap.find(".res_area_r").val());
console.log(q);
//var res_area_r = $.trim($(".res_area_r").val());
if (resStr == '') {
$(".res_text").css({color: "red"});
$.post("/index.php/comment/do_comment_reply/", q,
function (data) {
if (data.succ == 1) {
var $target,
evt = e || window.
$target = $(evt.target || evt.srcElement);
var $dd = $target.parents('dd');
var $wrapReply = $dd.find('.respond_box');
console.log($wrapReply);
//var mess = $(".res_area_r").val();
var mess = resS
var str = str.replace(/{%header%}/g, data.header)
.replace(/{%href%}/g, 'http://' + window.location.host + '/user/' + data.username)
.replace(/{%username%}/g, data.username)
.replace(/{%com_username%}/g, data.com_username)
.replace(/{%time%}/g, data.time)
.replace(/{%id%}/g, data.id)
.replace(/{%mess%}/g, mess);
$dd.after(str);
$(".respond_box").hide();
$(".res_area_r").val("");
$(".res_area").val("");
$wrapReply.hide();
alert(data.msg);
}, "json");
/*删除回复*/
$(".rightLi").on("click", '.del_comment_r', function (e) {
var id = $(e.target).attr("id");
$.getJSON('/index.php/comment/do_comment_del/' + id,
function (data) {
if (data.succ == 1) {
$(e.target).parent().parent().parent().parent().parent().remove();
$(e.target).parents('.res_list').remove()
alert(data.msg);
//填充回复
function KeyP(v) {
var parentWrap = $(v).parents(".respond_box");
parentWrap.find(".res_area_r").val($.trim(parentWrap.find(".res_area").val()));
评论共有0条
综合评分:
积分/C币:5
meng020712
综合评分:
积分/C币:5
综合评分:
积分/C币:5
VIP会员动态
CSDN下载频道资源及相关规则调整公告V11.10
下载频道用户反馈专区
下载频道积分规则调整V1710.18
spring mvc+mybatis+mysql+maven+bootstrap 整合实现增删查改简单实例.zip
资源所需积分/C币
当前拥有积分
当前拥有C币
输入下载码
为了良好体验,不建议使用迅雷下载
几个java小游戏源代码
会员到期时间:
剩余下载个数:
剩余积分:0
为了良好体验,不建议使用迅雷下载
积分不足!
资源所需积分/C币
当前拥有积分
您可以选择
程序员的必选
绿色安全资源
资源所需积分/C币
当前拥有积分
当前拥有C币
为了良好体验,不建议使用迅雷下载
资源所需积分/C币
当前拥有积分
当前拥有C币
为了良好体验,不建议使用迅雷下载
资源所需积分/C币
当前拥有积分
当前拥有C币
您的积分不足,将扣除 10 C币
为了良好体验,不建议使用迅雷下载
无法举报自己的资源
你当前的下载分为234。
你还不是VIP会员
开通VIP会员权限,免积分下载
你下载资源过于频繁,请输入验证码
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
若举报审核通过,可返还被扣除的积分
被举报人:
举报的资源分:
请选择类型
资源无法下载 ( 404页面、下载失败、资源本身问题)
资源无法使用 (文件损坏、内容缺失、题文不符)
侵犯版权资源 (侵犯公司或个人版权)
虚假资源 (恶意欺诈、刷分资源)
含色情、危害国家安全内容
含广告、木马病毒资源
*详细原因:
几个java小游戏源代码Java实现打飞机小游戏(附完整源码)
转载 & & 作者:CSDN邓帅
这篇文章主要介绍了Java实现打飞机小游戏(附完整源码),这里整理了详细的代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
技术源于分享,所以今天抽空把自己之前用java做过的小游戏整理贴出来给大家参考学习。java确实不适合写桌面应用,这里只是通过这个游戏让大家理解oop面向对象编程的过程,纯属娱乐。代码写的很简单,也很容易理解,并且注释写的很清楚了,还有问题,自己私下去补课学习。
import java.util.R
敌飞机: 是飞行物,也是敌人
public class Airplane extends FlyingObject implements Enemy {
private int speed = 3; //移动步骤
/** 初始化数据 */
public Airplane(){
this.image = ShootGame.
width = image.getWidth();
height = image.getHeight();
Random rand = new Random();
x = rand.nextInt(ShootGame.WIDTH - width);
/** 获取分数 */
public int getScore() {
/** //越界处理 */
boolean outOfBounds() {
return y&ShootGame.HEIGHT;
/** 移动 */
public void step() {
public interface Award {
int DOUBLE_FIRE = 0; //双倍火力
int LIFE = 1; //1条命
/** 获得奖励类型(上面的0或1) */
int getType();
import java.util.R
/** 蜜蜂 */
public class Bee extends FlyingObject implements Award{
private int xSpeed = 1; //x坐标移动速度
private int ySpeed = 2; //y坐标移动速度
private int awardT //奖励类型
/** 初始化数据 */
public Bee(){
this.image = ShootGame.
width = image.getWidth();
height = image.getHeight();
Random rand = new Random();
x = rand.nextInt(ShootGame.WIDTH - width);
awardType = rand.nextInt(2); //初始化时给奖励
/** 获得奖励类型 */
public int getType(){
return awardT
/** 越界处理 */
public boolean outOfBounds() {
return y&ShootGame.HEIGHT;
/** 移动,可斜着飞 */
public void step() {
if(x & ShootGame.WIDTH-width){
xSpeed = -1;
if(x & 0){
xSpeed = 1;
子弹类:是飞行物体
* 子弹类:是飞行物
public class Bullet extends FlyingObject {
private int speed = 3; //移动的速度
/** 初始化数据 */
public Bullet(int x,int y){
this.image = ShootGame.
/** 移动 */
public void step(){
/** 越界处理 */
public boolean outOfBounds() {
return y&-
敌人的分数
* 敌人,可以有分数
public interface Enemy {
/** 敌人的分数 */
int getScore();
飞行物(敌机,蜜蜂,子弹,英雄机)
import java.awt.image.BufferedI
* 飞行物(敌机,蜜蜂,子弹,英雄机)
public abstract class FlyingObject {
protected BufferedI //图片
public int getX() {
public void setX(int x) {
public int getY() {
public void setY(int y) {
public int getWidth() {
public void setWidth(int width) {
this.width =
public int getHeight() {
public void setHeight(int height) {
this.height =
public BufferedImage getImage() {
public void setImage(BufferedImage image) {
this.image =
* 检查是否出界
* @return true 出界与否
public abstract boolean outOfBounds();
* 飞行物移动一步
public abstract void step();
* 检查当前飞行物体是否被子弹(x,y)击(shoot)中
* @param Bullet 子弹对象
* @return true表示被击中了
public boolean shootBy(Bullet bullet){
int x = bullet.x; //子弹横坐标
int y = bullet.y; //子弹纵坐标
return this.x&x && x&this.x+width && this.y&y && y&this.y+
import java.awt.image.BufferedI
* 英雄机:是飞行物 Java学习交流QQ群: 我们一起学Java!
public class Hero extends FlyingObject{
private BufferedImage[] images = {}; //英雄机图片
private int index = 0;
//英雄机图片切换索引
private int doubleF //双倍火力
/** 初始化数据 */
public Hero(){
life = 3; //初始3条命
doubleFire = 0; //初始火力为0
images = new BufferedImage[]{ShootGame.hero0, ShootGame.hero1}; //英雄机图片数组
image = ShootGame.hero0; //初始为hero0图片
width = image.getWidth();
height = image.getHeight();
/** 获取双倍火力 */
public int isDoubleFire() {
return doubleF
/** 设置双倍火力 */
public void setDoubleFire(int doubleFire) {
this.doubleFire = doubleF
/** 增加火力 */
public void addDoubleFire(){
doubleFire = 40;
/** 增命 */
public void addLife(){ //增命
/** 减命 */
public void subtractLife(){ //减命
/** 获取命 */
public int getLife(){
/** 当前物体移动了一下,相对距离,x,y鼠标位置 */
public void moveTo(int x,int y){
this.x = x - width/2;
this.y = y - height/2;
/** 越界处理 */
public boolean outOfBounds() {
/** 发射子弹 */
public Bullet[] shoot(){
int xStep = width/4;
int yStep = 20; //步
if(doubleFire&0){ //双倍火力
Bullet[] bullets = new Bullet[2];
bullets[0] = new Bullet(x+xStep,y-yStep); //y-yStep(子弹距飞机的位置)
bullets[1] = new Bullet(x+3*xStep,y-yStep);
//单倍火力
Bullet[] bullets = new Bullet[1];
bullets[0] = new Bullet(x+2*xStep,y-yStep);
/** 移动 */
public void step() {
if(images.length&0){
image = images[index++/10%images.length]; //切换图片hero0,hero1
/** 碰撞算法 */
public boolean hit(FlyingObject other){
int x1 = other.x - this.width/2;
//x坐标最小距离
int x2 = other.x + this.width/2 + other. //x坐标最大距离
int y1 = other.y - this.height/2;
//y坐标最小距离
int y2 = other.y + this.height/2 + other. //y坐标最大距离
int herox = this.x + this.width/2;
//英雄机x坐标中心点距离
int heroy = this.y + this.height/2;
//英雄机y坐标中心点距离
return herox&x1 && herox&x2 && heroy&y1 && heroy&y2; //区间范围内为撞上了
游戏启动主类
import java.awt.F
import java.awt.C
import java.awt.G
import java.awt.event.MouseA
import java.awt.event.MouseE
import java.util.A
import java.util.R
import java.util.T
import java.util.TimerT
import java.awt.image.BufferedI
import javax.imageio.ImageIO;
import javax.swing.ImageI
import javax.swing.JF
import javax.swing.JP
* Java学习交流QQ群: 我们一起学Java!
public class ShootGame extends JPanel {
public static final int WIDTH = 400; // 面板宽
public static final int HEIGHT = 654; // 面板高
/** 游戏的当前状态: START RUNNING PAUSE GAME_OVER */
private static final int START = 0;
private static final int RUNNING = 1;
private static final int PAUSE = 2;
private static final int GAME_OVER = 3;
private int score = 0; // 得分
private T // 定时器
private int intervel = 1000 / 100; // 时间间隔(毫秒)
public static BufferedI
public static BufferedI
public static BufferedI
public static BufferedI
public static BufferedI
public static BufferedImage hero0;
public static BufferedImage hero1;
public static BufferedI
public static BufferedI
private FlyingObject[] flyings = {}; // 敌机数组
private Bullet[] bullets = {}; // 子弹数组
private Hero hero = new Hero(); // 英雄机
static { // 静态代码块,初始化图片资源
background = ImageIO.read(ShootGame.class
.getResource("background.png"));
start = ImageIO.read(ShootGame.class.getResource("start.png"));
airplane = ImageIO
.read(ShootGame.class.getResource("airplane.png"));
bee = ImageIO.read(ShootGame.class.getResource("bee.png"));
bullet = ImageIO.read(ShootGame.class.getResource("bullet.png"));
hero0 = ImageIO.read(ShootGame.class.getResource("hero0.png"));
hero1 = ImageIO.read(ShootGame.class.getResource("hero1.png"));
pause = ImageIO.read(ShootGame.class.getResource("pause.png"));
gameover = ImageIO
.read(ShootGame.class.getResource("gameover.png"));
} catch (Exception e) {
e.printStackTrace();
public void paint(Graphics g) {
g.drawImage(background, 0, 0, null); // 画背景图
paintHero(g); // 画英雄机
paintBullets(g); // 画子弹
paintFlyingObjects(g); // 画飞行物
paintScore(g); // 画分数
paintState(g); // 画游戏状态
/** 画英雄机 */
public void paintHero(Graphics g) {
g.drawImage(hero.getImage(), hero.getX(), hero.getY(), null);
/** 画子弹 */
public void paintBullets(Graphics g) {
for (int i = 0; i & bullets. i++) {
Bullet b = bullets[i];
g.drawImage(b.getImage(), b.getX() - b.getWidth() / 2, b.getY(),
/** 画飞行物 */
public void paintFlyingObjects(Graphics g) {
for (int i = 0; i & flyings. i++) {
FlyingObject f = flyings[i];
g.drawImage(f.getImage(), f.getX(), f.getY(), null);
/** 画分数 */
public void paintScore(Graphics g) {
int x = 10; // x坐标
int y = 25; // y坐标
Font font = new Font(Font.SANS_SERIF, Font.BOLD, 22); // 字体
g.setColor(new Color(0xFF0000));
g.setFont(font); // 设置字体
g.drawString("SCORE:" + score, x, y); // 画分数
y=y+20; // y坐标增20
g.drawString("LIFE:" + hero.getLife(), x, y); // 画命
/** 画游戏状态 */
public void paintState(Graphics g) {
switch (state) {
case START: // 启动状态
g.drawImage(start, 0, 0, null);
case PAUSE: // 暂停状态
g.drawImage(pause, 0, 0, null);
case GAME_OVER: // 游戏终止状态
g.drawImage(gameover, 0, 0, null);
public static void main(String[] args) {
JFrame frame = new JFrame("Fly");
ShootGame game = new ShootGame(); // 面板对象
frame.add(game); // 将面板添加到JFrame中
frame.setSize(WIDTH, HEIGHT); // 设置大小
frame.setAlwaysOnTop(true); // 设置其总在最上
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 默认关闭操作
frame.setIconImage(new ImageIcon("images/icon.jpg").getImage()); // 设置窗体的图标
frame.setLocationRelativeTo(null); // 设置窗体初始位置
frame.setVisible(true); // 尽快调用paint
game.action(); // 启动执行
/** 启动执行代码 */
public void action() {
// 鼠标监听事件
MouseAdapter l = new MouseAdapter() {
public void mouseMoved(MouseEvent e) { // 鼠标移动
if (state == RUNNING) { // 运行状态下移动英雄机--随鼠标位置
int x = e.getX();
int y = e.getY();
hero.moveTo(x, y);
public void mouseEntered(MouseEvent e) { // 鼠标进入
if (state == PAUSE) { // 暂停状态下运行
state = RUNNING;
public void mouseExited(MouseEvent e) { // 鼠标退出
if (state == RUNNING) { // 游戏未结束,则设置其为暂停
state = PAUSE;
public void mouseClicked(MouseEvent e) { // 鼠标点击
switch (state) {
case START:
state = RUNNING; // 启动状态下运行
case GAME_OVER: // 游戏结束,清理现场
flyings = new FlyingObject[0]; // 清空飞行物
bullets = new Bullet[0]; // 清空子弹
hero = new Hero(); // 重新创建英雄机
score = 0; // 清空成绩
state = START; // 状态设置为启动
this.addMouseListener(l); // 处理鼠标点击操作
this.addMouseMotionListener(l); // 处理鼠标滑动操作
timer = new Timer(); // 主流程控制
timer.schedule(new TimerTask() {
public void run() {
if (state == RUNNING) { // 运行状态
enterAction(); // 飞行物入场
stepAction(); // 走一步
shootAction(); // 英雄机射击
bangAction(); // 子弹打飞行物
outOfBoundsAction(); // 删除越界飞行物及子弹
checkGameOverAction(); // 检查游戏结束
repaint(); // 重绘,调用paint()方法
}, intervel, intervel);
int flyEnteredIndex = 0; // 飞行物入场计数
/** 飞行物入场 */
public void enterAction() {
flyEnteredIndex++;
if (flyEnteredIndex % 40 == 0) { // 400毫秒生成一个飞行物--10*40
FlyingObject obj = nextOne(); // 随机生成一个飞行物
flyings = Arrays.copyOf(flyings, flyings.length + 1);
flyings[flyings.length - 1] =
/** 走一步 */
public void stepAction() {
for (int i = 0; i & flyings. i++) { // 飞行物走一步
FlyingObject f = flyings[i];
for (int i = 0; i & bullets. i++) { // 子弹走一步
Bullet b = bullets[i];
hero.step(); // 英雄机走一步
/** 飞行物走一步 */
public void flyingStepAction() {
for (int i = 0; i & flyings. i++) {
FlyingObject f = flyings[i];
int shootIndex = 0; // 射击计数
/** 射击 */
public void shootAction() {
shootIndex++;
if (shootIndex % 30 == 0) { // 300毫秒发一颗
Bullet[] bs = hero.shoot(); // 英雄打出子弹
bullets = Arrays.copyOf(bullets, bullets.length + bs.length); // 扩容
System.arraycopy(bs, 0, bullets, bullets.length - bs.length,
bs.length); // 追加数组
/** 子弹与飞行物碰撞检测 */
public void bangAction() {
for (int i = 0; i & bullets. i++) { // 遍历所有子弹
Bullet b = bullets[i];
bang(b); // 子弹和飞行物之间的碰撞检查
/** 删除越界飞行物及子弹 */
public void outOfBoundsAction() {
int index = 0; // 索引
FlyingObject[] flyingLives = new FlyingObject[flyings.length]; // 活着的飞行物
for (int i = 0; i & flyings. i++) {
FlyingObject f = flyings[i];
if (!f.outOfBounds()) {
flyingLives[index++] = // 不越界的留着
flyings = Arrays.copyOf(flyingLives, index); // 将不越界的飞行物都留着
index = 0; // 索引重置为0
Bullet[] bulletLives = new Bullet[bullets.length];
for (int i = 0; i & bullets. i++) {
Bullet b = bullets[i];
if (!b.outOfBounds()) {
bulletLives[index++] =
bullets = Arrays.copyOf(bulletLives, index); // 将不越界的子弹留着
/** 检查游戏结束 */
public void checkGameOverAction() {
if (isGameOver()==true) {
state = GAME_OVER; // 改变状态
/** 检查游戏是否结束 */
public boolean isGameOver() {
for (int i = 0; i & flyings. i++) {
int index = -1;
FlyingObject obj = flyings[i];
if (hero.hit(obj)) { // 检查英雄机与飞行物是否碰撞
hero.subtractLife(); // 减命
hero.setDoubleFire(0); // 双倍火力解除
index = // 记录碰上的飞行物索引
if (index != -1) {
FlyingObject t = flyings[index];
flyings[index] = flyings[flyings.length - 1];
flyings[flyings.length - 1] = // 碰上的与最后一个飞行物交换
flyings = Arrays.copyOf(flyings, flyings.length - 1); // 删除碰上的飞行物
return hero.getLife() &= 0;
/** 子弹和飞行物之间的碰撞检查 */
public void bang(Bullet bullet) {
int index = -1; // 击中的飞行物索引
for (int i = 0; i & flyings. i++) {
FlyingObject obj = flyings[i];
if (obj.shootBy(bullet)) { // 判断是否击中
index = // 记录被击中的飞行物的索引
if (index != -1) { // 有击中的飞行物
FlyingObject one = flyings[index]; // 记录被击中的飞行物
FlyingObject temp = flyings[index]; // 被击中的飞行物与最后一个飞行物交换
flyings[index] = flyings[flyings.length - 1];
flyings[flyings.length - 1] =
flyings = Arrays.copyOf(flyings, flyings.length - 1); // 删除最后一个飞行物(即被击中的)
// 检查one的类型(敌人加分,奖励获取)
if (one instanceof Enemy) { // 检查类型,是敌人,则加分
Enemy e = (Enemy) // 强制类型转换
score += e.getScore(); // 加分
} else { // 若为奖励,设置奖励
Award a = (Award)
int type = a.getType(); // 获取奖励类型
switch (type) {
case Award.DOUBLE_FIRE:
hero.addDoubleFire(); // 设置双倍火力
case Award.LIFE:
hero.addLife(); // 设置加命
* 随机生成飞行物
* @return 飞行物对象
public static FlyingObject nextOne() {
Random random = new Random();
int type = random.nextInt(20); // [0,20)
if (type & 4) {
return new Bee();
return new Airplane();
以上就是这个游戏我整理的完整代码,最后,我做了一张思维导图贴出来让大家更好的理解OOP面向对象编程的过程。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具【急!在线求助帖】谁有能运行的JAVA小游戏的完整源代码?【java吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:706,731贴子:
【急!在线求助帖】谁有能运行的JAVA小游戏的完整源代码?收藏
谁有能运行的JAVA小游戏的完整源代码?比如拼图游戏,打字游戏都行!跪谢各位大神!
51CTO学院12年行业品牌,1600万用户选择,中国专业IT技能学习平台.java资深名师授课,0基础从入门到精通,java报名与培训中心.
java课程设计?
不留地址怎么给嘛
有人说我是来混经验的,卧槽 劳资反手就是一巴掌,你特么不是说废话么
到网上一大堆,只要会百度
登录百度帐号

我要回帖

更多关于 java小游戏2048源代码 的文章

 

随机推荐