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

📄 player.java

📁 这是我编写的第一个J2ME程序
💻 JAVA
字号:
/* * Copyright (c) 2002, 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of Sun Microsystems, Inc., 'Java', 'Java'-based * names, or the names of contributors may be used to endorse or promote * products derived from this software without specific prior written * permission. * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * You acknowledge that this software is not designed, licensed or * intended for use in the design, construction, operation or maintenance * of any nuclear facility. $Id: Player.java,v 1.1 2003/05/16 00:16:01 zull Exp $ */package com.sun.j2me.blueprints.slugs.server;import com.sun.j2me.blueprints.slugs.shared.*;/** * This class represents a player in the game. * Players have an (x, y) location, an id, a * status, direction, a number of remaining lives, * shovels and jetpacks. */public class Player extends Item implements PlayerActions {    // direction    public static final int STILL = 0;    public static final int NORTH = 1;    public static final int SOUTH = 2;    public static final int WEST = 3;    public static final int EAST = 4;    public static final int MAX_TICKS = 15;    private Item covered;    private int direction;    private int lives;    private int jetpack_count;    private int shovel_count;    private int speed;    private int fly_ticks;    private int dig_ticks;    private int speed_ticks;    /**     * Create a new instance with location     * ('x', 'y') and ID 'id'.     */    public Player(int x, int y, int id) {        super(x, y, RUN | id);        direction = STILL;        lives = 0;        jetpack_count = 0;        shovel_count = 0;        speed = 1;        fly_ticks = 0;        dig_ticks = 0;        speed_ticks = 0;    }    /**     * Set the direction for this instance     */    public void setDirection(int direction) {        this.direction = direction;    }     /**     * Get the direction for this instance     */    public int getDirection() {        return direction;    }     /**     * Set the number of lives for this instance     */    public void setLives(int lives) {        this.lives = lives;    }     /**     * Get the number of lives for this instance     */    public int getLives() {        return lives;    }     /**     * Set the number of jetpacks for this instance     */    public void setJetpackCount(int jetpack_count) {        this.jetpack_count = jetpack_count;    }     /**     * Get the number of jetpacks for this instance     */    public int getJetpackCount() {        return jetpack_count;    }     /**     * Set the number of shovels for this instance     */    public void setShovelCount(int shovel_count) {        this.shovel_count = shovel_count;    }     /**     * Get the number of shovels for this instance     */    public int getShovelCount() {        return shovel_count;    }     /**     * Track flying, digging and boosting activity     */    public void tick() {        int status = getStatus();        if (fly_ticks > 0 && (status & FLY) != 0) {            if (--fly_ticks == 0) {                clearStatusBit(FLY);                setStatusBit(RUN);            }         }         if (dig_ticks > 0 && (status & BURROW) != 0) {            if (--dig_ticks == 0) {                clearStatusBit(BURROW);                setStatusBit(RUN);            }         }         if (speed_ticks > 0) {            if (--speed_ticks == 0) {                speed = 1;            }         }     }     /**     * Set the item this instance is covering on the field     */    public void setCovered(Item item) {        covered = item;    }     /**     * Get the item this instance is covering on the field     */    public Item getCovered() {        return covered;    }     /**     * Returns 'true' if the player is flying, 'false' othewise     */    public boolean isFlying() {        return (getStatus() & FLY) != 0;    }     /**     * Returns 'true' if the player is digging, 'false' othewise     */    public boolean isDigging() {        return (getStatus() & BURROW) != 0;    }     /**     * Returns 'true' if the player is on the ground, 'false' othewise     */    public boolean isOnGround() {        return !isFlying() &&!isDigging();    }     /**     * Get the speed for this instance     */    public int getSpeed() {        return speed;    }     /**     * Add a status bit for the player     */    public void setStatusBit(int bit) {        if (bit == FLY) {            fly_ticks = MAX_TICKS;        } else if (bit == BURROW) {            dig_ticks = MAX_TICKS;        } else if (bit == RUN_FAST) {            speed = 2;            speed_ticks = MAX_TICKS;            return;        }         setStatus(getStatus() | bit);    }     /**     * Remove a status bit for the player     */    public void clearStatusBit(int bit) {        setStatus(getStatus() & ~bit);    } }

⌨️ 快捷键说明

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