📄 pacman.java
字号:
import cs101.lang.*;import java.util.*;import java.awt.*;import gaming.*;import javax.swing.JOptionPane;public class Pacman extends DummyItem implements KeyControllable,ScreenObject{ protected int x = 7; protected int y = 7;//locate the pacman's location in the centre protected java.awt.Color myColor; public Pacman(int x,int yposition) { super(7,7,java.awt.Color.white,3);//pacman is a round with a gap on the right this.myColor=java.awt.Color.white;//set the initial information of the pacman } public int getX() { return x; } public void setX(int xPos) {x=xPos;} public void setY(int yPos) {y=yPos;}//set the position public int getY() { return y; } public Color getColor() { return myColor; } public Image getImage() { return this.image; } public void actOnKey(char key) { WalledSquare[][] walls = PacmanBoard.getWalls(); switch(key) { case 'w': if(!walls[x][y].hasUpperWall()) y--; break; //go up case 's': if(!walls[x][y].hasLowerWall()) y++; break;//go down case 'a': if(!walls[x][y].hasLeftWall()) x--; break;//go left case 'd': if(!walls[x][y].hasRightWall()) x++; break;//go right default: break; } PacmanBoard.repaint(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -