资源预览内容
第1页 / 共42页
第2页 / 共42页
第3页 / 共42页
第4页 / 共42页
第5页 / 共42页
第6页 / 共42页
第7页 / 共42页
第8页 / 共42页
第9页 / 共42页
第10页 / 共42页
亲,该文档总共42页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
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;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 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.cantGoAnyWhere = 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)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 = new 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);if(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;changeMovement = 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;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 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(canMoveRight & 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
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号