java吃豆子游戏设计-课程设计

上传人:公**** 文档编号:551985628 上传时间:2023-06-30 格式:DOC 页数:42 大小:96.50KB
返回 下载 相关 举报
java吃豆子游戏设计-课程设计_第1页
第1页 / 共42页
java吃豆子游戏设计-课程设计_第2页
第2页 / 共42页
java吃豆子游戏设计-课程设计_第3页
第3页 / 共42页
java吃豆子游戏设计-课程设计_第4页
第4页 / 共42页
java吃豆子游戏设计-课程设计_第5页
第5页 / 共42页
点击查看更多>>
资源描述

《java吃豆子游戏设计-课程设计》由会员分享,可在线阅读,更多相关《java吃豆子游戏设计-课程设计(42页珍藏版)》请在金锄头文库上搜索。

1、java吃豆子游戏设计-课程设计java吃豆子游戏设计import java.awt.*;/* 定义敌人的类*/public class Enemyprivate int xPos;private int yPos;private int xVPos;private int yVPos;private int direction;/敌人是否失去对抗能力private boolean alarm;/敌人失去防抗能力的时间private int alarmTime;private boolean ghostMode;private Rectangle Enemy;private int speed

2、;private int interval;private int Colour;private int AI_time1, AI_time2;private int lefttime, uptime, righttime, downtime;private int gameFlow;private boolean ghost;private boolean canMoveUp, canMoveDown, canMoveLeft,canMoveRight;private boolean cantGoAnyWhere;private int prisonTime;private boolean

3、stop;/* *根据x、y、颜色、是否已经出牢笼、剩余多长时间才可出牢笼 *构造敌人对象 */public Enemy(int a, int b, int c, boolean cantGoAnyWhere, int prisonTime)xPos = a;yPos = b;xVPos = xPos;yVPos = yVPos;direction = 3;speed = 3;interval = 63 + 21*(int)(Math.random()*10);AI_time1 = 0;Colour = c;this.prisonTime = prisonTime;this.cantGoAny

4、Where = cantGoAnyWhere;Enemy = new Rectangle(xPos -10, yPos - 10, 21, 21);/* *方法:敌人的移动 */public void move(int a, int b, Wall wall)AI_time1+;AI_time2+;uptime+;downtime+;lefttime+;righttime+;gameFlow+;/如果敌人没有对抗能力if(alarm)alarmTime+;boolean changeMovement = false;/如果敌人不能移动,就将囚禁得时间不停增加if(cantGoAnyWhere)

5、prisonTime+;/当敌人失去对抗能力后,速度降低if(alarm)speed = 1;elsespeed = 2;/失去对抗能力到指定时间后,恢复原态if(alarmTime = 330)alarmTime = 0;alarm = false;canMoveUp = true;canMoveDown = true;canMoveLeft = true;canMoveRight = true;Rectangle R;Rectangle UP = new Rectangle(xVPos - 10, yVPos - 10 - speed, 21, 21);Rectangle DOWN = n

6、ew Rectangle(xVPos - 10, yVPos - 10 + speed, 21, 21);Rectangle LEFT = new Rectangle(xVPos - 10 - speed, yVPos - 10, 21, 21);Rectangle RIGHT = new Rectangle(xVPos - 10 + speed, yVPos - 10, 21, 21);for(int i = 0; i wall.length; i+)R = new Rectangle(walli.getxPos() - 10, walli.getyPos() - 10, 21, 21);i

7、f(R.intersects(UP)canMoveUp = false;if(prisonTime = 189 & yVPos 231 & xVPos = 210)if(R.intersects(DOWN)canMoveDown = false;if(R.intersects(DOWN) & direction = 1)yPos = yVPos;changeMovement = true;if(R.intersects(LEFT)canMoveLeft = false;if(R.intersects(LEFT) & direction = 2)xPos = xVPos;changeMoveme

8、nt = true;if(R.intersects(RIGHT)canMoveRight = false;if(R.intersects(RIGHT) & direction = 3)xPos = xVPos;changeMovement = true;interval-=speed;if(interval 10 & u = 0)direction = 0;xPos = xVPos;AI_time1 = 0;if(canMoveDown & direction != 0 & AI_time1 10 & u = 1)direction = 1;xPos = xVPos;AI_time1 = 0;

9、if(canMoveRight & direction != 2 & AI_time1 10 & u = 3)direction = 3;xPos = xVPos;AI_time1 = 0;if(!alarm & !cantGoAnyWhere)if(AI_time2 99)if(canMoveUp & yPos b & AI_time2 99)direction = 0;xPos = xVPos;AI_time2 = 0;if(canMoveDown & yPos 99)direction = 1;xPos = xVPos;AI_time2 = 0;if(canMoveLeft & xPos

10、 a & AI_time2 99)direction = 2;yPos = yVPos;AI_time2 = 0;if(canMoveRight & xPos 99)direction = 3;yPos = yVPos;AI_time2 = 0;if(alarm)if(AI_time2 99)if(canMoveDown & yPos b & AI_time2 99)direction = 1;xPos = xVPos;AI_time2 = 0;if(canMoveUp & yPos 99)direction = 0;xPos = xVPos;AI_time2 = 0;if(canMoveRi

11、ght & xPos a & AI_time2 99)direction = 3;yPos = yVPos;AI_time2 = 0;if(canMoveLeft & xPos 99)direction = 2;yPos = yVPos;AI_time2 = 0;if(ghost)a = 210;b = 189;speed = 4;alarm = false;alarmTime = 0;if(AI_time2 99)if(canMoveUp & yPos b & AI_time2 99)direction = 0;xPos = xVPos;AI_time2 = 0;if(canMoveDown & yPos 99)direction = 1;xPos = xVPos;AI_time2 = 0;if(canMoveLeft & xPos a & AI_time2 99)direction = 2;yPos = yVPos;AI_time2

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 商业计划书

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号