ghost.java
来自「用Java做的小游戏:Pacman 和小时候玩的吃豆豆一样」· Java 代码 · 共 53 行
JAVA
53 行
import cs101.lang.*;import java.util.*;import java.awt.*;import gaming.*;public abstract class Ghost extends DummyItem implements ScreenObject{ WalledSquare[][] walls; Pacman pacman ; boolean Flag = true; public abstract void move(); public Ghost(int x, int y, Pacman p ) { super( x, y,java.awt.Color.green,2); pacman = p; } public int getX() { return x; } public void setX(int xPos){ x = xPos; } public void setY(int yPos){ y = yPos; } public int getY() { return y; } public Color getColor() { return this.color; } public Image getImage() { return this.image; } public void Chase(Pacman p) { walls = PacmanBoard.getWalls(); if(pacman.getX()<x&&!walls[x][y].hasLeftWall()) x--;//if pacman is at the left of the ghost and there is no wall on the left of the ghost then move to left one step else if(pacman.getY()<y&&!walls[x][y].hasUpperWall()) y--;//if pacman is at the uppper of the ghost and there is no wall on the upper of the ghost then move to upper one step else if(pacman.getX()>x&&!walls[x][y].hasRightWall()) x++;//if pacman is at the right of the ghost and there is no wall on the right of the ghost then move to right one step else if(pacman.getY()>y&&!walls[x][y].hasLowerWall()) y++;//if pacman is at the lower of the ghost and there is no wall on the lower of the ghost then move to lower one step PacmanBoard.repaint(); } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?