⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playertank.java

📁 还记得儿时在游戏机上玩坦克大战吗?如今这种经典游戏不在游戏机上玩了
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//------------------------------------------------------------------------------
//                         COPYRIGHT 2008 GUIDEBEE
//                           ALL RIGHTS RESERVED.
//                     GUIDEBEE CONFIDENTIAL PROPRIETARY
///////////////////////////////////// REVISIONS ////////////////////////////////
// Date       Name                 Tracking #         Description
// ---------  -------------------  ----------         --------------------------
// 17JAN2008  James Shen                 	      Initial Creation
////////////////////////////////////////////////////////////////////////////////
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//The Software shall be used for Good, not Evil.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
//Any questions, feel free to drop me a mail at james.shen@guidebee.biz.
//--------------------------------- PACKAGE ------------------------------------
package com.pstreets.game.battlecity;

//--------------------------------- IMPORTS ------------------------------------
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;

//[------------------------------ MAIN CLASS ----------------------------------]
////////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ----------------------------------
// Date       Name                 Tracking #         Description
// --------   -------------------  -------------      --------------------------
// 15JAN2008  James Shen                 	      Initial Creation
////////////////////////////////////////////////////////////////////////////////
/**
 * Player's tank.
 * <p>
 * <hr><b>&copy; Copyright 2008 Guidebee, Inc. All Rights Reserved.</b>
 * @version     1.00, 17/01/08
 * @author      Guidebee, Inc.
 */
public final class PlayerTank extends Tank{
    
    /**
     * Is key pressed?
     */
    private boolean keyPressed=false;
    
    /**
     * player's current grade,if equal 0,mean player dies.
     */
    private int grade = MIN_GRADE;
    
    /**
     * Player's minimum grade
     */
    private static final int MIN_GRADE=1;
    
    /**
     * tank can shoot 2 bulltes.   **
     */
    private static final int GRADE_TWO_BULLETS=2;
    
    /**
     * tank can shoot 3 bulltes.   ***
     */
    private static final int GRADE_THREE_BULLETS=3;
    
    /**
     * tank can break concrete walls. ****
     */
    private static final int GRADE_BREAK_CONCRETE_WALL=4;
    
    /**
     * tank can break water and snow. *****
     */
    private static final int GRADE_BREAK_WATER=5;
    
    /**
     * tank add one layer of shell. ******
     */
    private static final int GRADE_SHELL_1=6;
    
    /**
     * tank move fast, go one star. *
     */
    private static final int GRADE_SPEED=7;
    
    /**
     * tank add two layers of shell. *******
     */
    private static final int GRADE_SHELL_2=8;
    
    /**
     * Player's maximum grade
     */
    private static final int MAX_GRADE=8;
    
    /**
     * the player's tank is just created.
     */
    private static final int NEW_BORN=9;
    
    /**
     * the Invulnerable sheild for the player tank.
     */
    private Powerup sheild;
    
    /**
     * player tank is invulnerable at the start of the level,
     * and can become invulnerable if collects {@see Powerup.SHIELD}.
     */
    private int invulnerabilityTicks;
    
    /**
     * the time begin invulnerable
     */
    private long invulnerableTime;
    
    /**
     * invulnerable period. for start ,the time is 7.5 seconds.
     */
    private static final int invulnerablePeriod=30000;
    
    /**
     * store current direction as shooting direction
     */
    private int currentDirection=BattleField.NONE;
    
    /**
     * how many bullets can player shoot at same time.
     */
    private int avaiableBullets=1;
    
    /**
     * same direction,switch 2 image to make tank move animation.
     */
    private boolean switchImage=false;
    
    /**
     * how many lifes player has.
     */
    private int avaiableLife=3;
    
    /**
     * the score the player gets.
     */
    private int score=0;
    
    
    ////////////////////////////////////////////////////////////////////////////
    //--------------------------------- REVISIONS ------------------------------
    // Date       Name                 Tracking #         Description
    // ---------  -------------------  -------------      ----------------------
    // 17JAN2008  James Shen                 	          Initial Creation
    ////////////////////////////////////////////////////////////////////////////
    /**
     * Constructor
     */
    protected PlayerTank() {
        super(ResourceManager.getInstance().getImage(ResourceManager.PLAYER),
                ResourceManager.TILE_WIDTH,ResourceManager.TILE_WIDTH);
        sheild=Powerup.getInvulnerable();
    }
    
    ////////////////////////////////////////////////////////////////////////////
    //--------------------------------- REVISIONS ------------------------------
    // Date       Name                 Tracking #         Description
    // ---------  -------------------  -------------      ----------------------
    // 17JAN2008  James Shen                 	          Initial Creation
    ////////////////////////////////////////////////////////////////////////////
    /**
     * Add player's score with given value
     * @param value the score value.
     */
    public void addScore(int value) {
        score+=value;
    }
    
    ////////////////////////////////////////////////////////////////////////////
    //--------------------------------- REVISIONS ------------------------------
    // Date       Name                 Tracking #         Description
    // ---------  -------------------  -------------      ----------------------
    // 17JAN2008  James Shen                 	          Initial Creation
    ////////////////////////////////////////////////////////////////////////////
    /**
     * set player's score with given value
     * @param value the score value.
     */
    public void setScore(int value) {
        score=value;
    }
    ////////////////////////////////////////////////////////////////////////////
    //--------------------------------- REVISIONS ------------------------------
    // Date       Name                 Tracking #         Description
    // ---------  -------------------  -------------      ----------------------
    // 17JAN2008  James Shen                 	          Initial Creation
    ////////////////////////////////////////////////////////////////////////////
    /**
     * return player's score with given value.
     * @return player's score with given value.
     */
    public int getScore() {
        return score;
    }
    
    ////////////////////////////////////////////////////////////////////////////
    //--------------------------------- REVISIONS ------------------------------
    // Date       Name                 Tracking #         Description
    // ---------  -------------------  -------------      ----------------------
    // 17JAN2008  James Shen                 	          Initial Creation
    ////////////////////////////////////////////////////////////////////////////
    /**
     * Intialize the player tank after been destoryed or first start.
     */
    public void initTank(){
        if(battleField!=null){
            battleField.initPlayerTankPos(this);
            setVisible(true);
            direction=BattleField.NONE;
            grade=NEW_BORN;
            newBornTimer=0;
            avaiableBullets=1;
            speed=DEFAULT_SPEED;
            shoot=false;
        }
    }
    
    ////////////////////////////////////////////////////////////////////////////
    //--------------------------------- REVISIONS ------------------------------
    // Date       Name                 Tracking #         Description
    // ---------  -------------------  -------------      ----------------------
    // 16JAN2008  James Shen                 	          Initial Creation
    ////////////////////////////////////////////////////////////////////////////
    /**
     * Player tanks handle key press event.
     * @param gameAction the game key code.
     */
    public void keyPressed(int gameAction){
        keyPressed=true;
        if (gameAction == GameCanvas.UP) {
            direction = BattleField.NORTH;
        } else if (gameAction == GameCanvas.RIGHT) {
            direction = BattleField.EAST;
        } else if (gameAction == GameCanvas.LEFT) {
            direction = BattleField.WEST;
        } else if (gameAction == GameCanvas.DOWN) {
            direction = BattleField.SOUTH;
        } else if (gameAction == GameCanvas.FIRE) {
            shoot = true;
        }
        if(direction!=BattleField.NONE){
            currentDirection=direction;
        }
    }
    
    ////////////////////////////////////////////////////////////////////////////
    //--------------------------------- REVISIONS ------------------------------
    // Date       Name                 Tracking #         Description
    // ---------  -------------------  -------------      ----------------------
    // 16JAN2008  James Shen                 	          Initial Creation
    ////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -