📄 player.java
字号:
/*
* @(#)Player.java 1.0 04/07/01 @(#)
*
* Copyright 2004 NTT DoCoMo, Inc. All rights reserved.
*/
import com.nttdocomo.ui.Display;
/**
* Player<BR>
* The definition class of the player.
* <p>
* @version 1.0
* </p>
*/
public class Player extends AbstractItem {
/** The position of the player at the time of game start (Width) */
private static final int START_POSITION_X = 150;
/** The position of the player at the time of game start (Height) */
private static final int START_POSITION_Y = 150;
/** The amount of movements of the car */
private static final int DEFAULT_AMOUNT = 2;
/** The frequency of movements of the car */
private static final int MOVE_FREQUENCY = 20;
/** The number of stocks of the car */
private int stock;
/** The first number of stocks of the car */
private static final int INTITIL_STOCK = 3;
/**
* Constructor.
*/
public Player() {
super(TYPE_PLAYER);
init();
}
/**
* Initialization
*/
public void init() {
stock = INTITIL_STOCK;
reset();
}
/**
* Initializes the state of the player.
*/
public void reset() {
setStatus(STATUS_NORMAL);
setImage(MediaCollection.IMG_PLAYER);
setPosX(START_POSITION_X);
setPosY(START_POSITION_Y);
}
/**
* Acquires the number of stocks of the car.
* @return stocks
*/
public int getStock() {
return stock;
}
/*
* @see AbstractItem#move(int, int)
*/
public void move(int _direction, int stage) {
move(_direction, MOVE_FREQUENCY, DEFAULT_AMOUNT);
}
/*
* @see AbstractItem#move(int, int, int)
*/
public void move(int _direction, int _frequency, int _amount) {
if (STATUS_CONTACT == getStatus()) {
return;
}
/* Upper end / Lower end */
int posY = this.getPosY();
int height = this.getImage().getHeight();
if ((DIRECTION_UP == _direction) && (2 > (posY - DEFAULT_AMOUNT))) {
return;
}
if ((DIRECTION_DOWN == _direction) &&
((posY + DEFAULT_AMOUNT) > (Display.getHeight() - height))) {
return;
}
super.move(_direction, _frequency, _amount);
}
/**
* Confirmes whether the player is moving out of course.
* @param _leftEnd Left end of course
* @param _rightEnd Right end of course
* @return true:Course out
*/
public boolean isCourseOut(int _leftEnd, int _rightEnd) {
int posX = this.getPosX();
int width = this.getImage().getWidth();
/* Course out */
if ((posX < _leftEnd) || (posX + width > _rightEnd)) {
fail();
return true;
}
return false;
}
/**
* Subtracts one from the number of stocks.
*/
public void fail() {
setStatus(STATUS_CONTACT);
setImage(MediaCollection.IMG_FIRE);
stock--;
}
/**
* Adds one to the number of stocks.
*/
public void oneUp() {
stock++;
}
/*
* @see AbstractItem#contact()
*/
public void contact() {
fail();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -