云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 基于java的吃豆子小游戏开发-毕设论文

基于java的吃豆子小游戏开发-毕设论文

  • 62 次阅读
  • 3 次下载
  • 2026/4/24 1:46:46

常州大学本科生毕业设计(论文)

}

int[] yPoints = new int[] {yPos - 9,

};

yPos - 4, yPos + 9, yPos + 4, yPos + 9, yPos + 4, yPos + 9, yPos - 4, yPos - 9,

Ghost = new Polygon (xPoints, yPoints, xPoints.length);

if(!alarm && !ghost){ }

//用图形上下文的当前颜色填充由指定的Polygon对象定义的多边形Ghost。 g.fillPolygon(Ghost);

//如果敌人没有失去反抗能力,则用蓝色进行填充敌人的整体,用白色填充敌人的眼睛。

if(!alarm || ghost){

//填充敌人眼睛的白色部分 g.setColor(Color.white);

g.fillOval(xPos - 8, yPos - 5, 7, 8); g.fillOval(xPos + 2, yPos - 5, 7, 8);

//填充敌人眼睛中的蓝色十字部分 g.setColor(Color.blue); if(direction == 0){ }

//使用当前颜色填充外接指定矩形框的椭圆。 g.fillOval(xPos - 6, yPos - 4, 3, 4); g.fillOval(xPos + 4, yPos - 4, 3, 4);

第 28 页 共41页

28

常州大学本科生毕业设计(论文)

if(direction == 1){ g.fillOval(xPos - 6, yPos - 2, 3, 4); g.fillOval(xPos + 4, yPos - 2, 3, 4);

}

if(direction == 2){ g.fillOval(xPos - 7, yPos - 3, 3, 4); g.fillOval(xPos + 3, yPos - 3, 3, 4); }

if(direction == 3){ g.fillOval(xPos - 5, yPos - 3, 3, 4); g.fillOval(xPos + 5, yPos - 3, 3, 4); }

}

//如果敌人失去反抗能力 if(alarm){ g.setColor(Color.blue);

//当敌人即将恢复攻击能力时,将其颜色显示为蓝色 if(alarmTime >= 231 && alarmTime%6 > 2)

g.setColor(Color.lightGray); g.fillPolygon(Ghost); g.setColor(Color.white);

g.fillOval(xPos - 6, yPos - 6, 5, 6); g.fillOval(xPos + 2, yPos - 6, 5, 6);

//在此图形上下文的坐标系统中,使用当前颜色(灰色), //在点(xPos - 6, yPos + 3)和(xPos - 4, yPos + 1)之间画一条线。 g.drawLine(xPos - 6, yPos + 3, xPos - 4, yPos + 1); g.drawLine(xPos - 4, yPos + 1, xPos - 2, yPos + 3); g.drawLine(xPos - 2, yPos + 3, xPos, yPos + 1); g.drawLine(xPos, yPos + 1, xPos + 2, yPos + 3); g.drawLine(xPos + 2, yPos + 3, xPos + 4, yPos + 1);

g.drawLine(xPos + 4, yPos + 1, xPos + 6, yPos + 3);

第 29 页 共41页

29

常州大学本科生毕业设计(论文)

}

图6-5敌人图片

6.2.5 移动控制模块设计

使用键盘方向键对吃豆者的移动进行控制,其代码如下: if(e.getKeyCode() == KeyEvent.VK_UP){ player.ChangeDirection(0); //控制键盘向上移动的操作 UP_TYPED = true; DOWN_TYPED = false; LEFT_TYPED = false; RIGHT_TYPED = false; } if(e.getKeyCode() == KeyEvent.VK_DOWN){ player.ChangeDirection(1);//控制键盘向下移动的操作 UP_TYPED = false; DOWN_TYPED = true; LEFT_TYPED = false; RIGHT_TYPED = false; }

if(e.getKeyCode() == KeyEvent.VK_LEFT ){

player.ChangeDirection(2); //控制键盘向左移动的操作 UP_TYPED = false;

DOWN_TYPED = false; LEFT_TYPED = true; RIGHT_TYPED = false; }

if(e.getKeyCode() == KeyEvent.VK_RIGHT){ player.ChangeDirection(3); //控制键盘向右移动的操作

UP_TYPED = false;

第 30 页 共41页

30

常州大学本科生毕业设计(论文)

DOWN_TYPED = false; LEFT_TYPED = false; RIGHT_TYPED = true; } }

public void keyReleased(KeyEvent e){} public void keyTyped(KeyEvent e){} public void update(Graphics g) { Graphics offScreenGraphics; if (offScreenImage == null) {

//返回创建一幅用于双缓冲的、可在屏幕外绘制的图像。 //如果组件是不可显示的,则返回值可能为 null。 offScreenImage = createImage(545, 482); }

offScreenGraphics = offScreenImage.getGraphics(); offScreenGraphics.setColor(Color.white); offScreenGraphics.fillRect(0, 0, 545, 482); paint(offScreenGraphics);

g.drawImage(offScreenImage, 0, 0, this);

}

6.2.6水果模块设计

通过fruit包的public类,利用x、y数组来实现带水果的绘制,代码如下: interval = 63 + 21*((int)(Math.random()*10)); }//间隔时间的计算 //水果移动 if(direction == 0 && canMoveUp) yPos-=1; if(direction == 1 && canMoveDown) yPos+=1;

if(direction == 2 && canMoveLeft) xPos-=1;

if(direction == 3 && canMoveRight)

xPos+=1;

第 31 页 共41页

31

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

常州大学本科生毕业设计(论文) } int[] yPoints = new int[] {yPos - 9, }; yPos - 4, yPos + 9, yPos + 4, yPos + 9, yPos + 4, yPos + 9, yPos - 4, yPos - 9, Ghost = new Polygon (xPoints, yPoints, xPoints.length); if(!alarm && !ghost){ } //用图形上下文的当前颜色填充由指定的Polygon对象定义的多边形Ghos

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com