pacman.java

来自「用Java做的小游戏:Pacman 和小时候玩的吃豆豆一样」· Java 代码 · 共 56 行

JAVA
56
字号
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 + =
减小字号Ctrl + -
显示快捷键?