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

📄 item.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: Item.java,v 1.1 2003/05/16 00:16:02 zull Exp $ */package com.sun.j2me.blueprints.slugs.shared;/** * This class represents a state change in the * game engine. Because this class extends Data, * instances can easily be converted from and to * integer arrays for communicating them over sockets. */public class Item extends Data {    // object types    public static final int JET_PACK = 0;    public static final int SHOVEL = 1;    public static final int BOOSTER = 2;    public static final int EXTRA_LIFE = 3;    public static final int POISON = 4;    public static final int WALL = 5;    public static final int HOUSE = 6;    public static final int PATH1 = 7;    public static final int PATH2 = 8;    public static final int GRASS = 9;    public static final int DELETE = 10;    public static final int JETPACK_COUNT = 11;    public static final int SHOVEL_COUNT = 12;    public static final int LIFE_COUNT = 13;    // game status    public static final int NEW_LEVEL = 14;    private static final String[] OBJECT_TYPE_STRING = {        "jetpack", "shovel", "booster", "extra_life", "poison", "wall",         "house"    };    private static final int X = 0;    private static final int Y = 1;    private static final int STATUS = 2;    private static final int SIZE = 3;    private boolean dirty;    /**     * Construct a new instance from an     * ('x', 'y') coordinate and a status     * indicator.     */    public Item(int x, int y, int status) {        buf = new int[SIZE];        setX(x);        setY(y);        setStatus(status);    }    /**     * Parse 'string' and return the numeric status     * for it. Will throw a RuntimeException for     * unrecognized types.     */    public static int getStatusTypeForString(String string) {        for (int i = 0; i < OBJECT_TYPE_STRING.length; i++) {            if (string.equals(OBJECT_TYPE_STRING[i])) {                return i;            }         }         throw new RuntimeException("invalid type");    }     /**     * Initialize this instance from 'item'     */    public void copyFrom(Item item) {        setX(item.getX());        setY(item.getY());        setStatus(item.getStatus());    }     /**     * Return the x attribute of this instance     */    public int getX() {        return buf[X];    }     /**     * Return the y attribute of this instance     */    public int getY() {        return buf[Y];    }     /**     * Return the status attribute of this instance     */    public int getStatus() {        return buf[STATUS];    }     /**     * Return the status attribute of this instance     * as a string     */    public String getStatusString() {        int status = getStatus();        return status >= JET_PACK && status <= PATH2                ? OBJECT_TYPE_STRING[status] : "" + status;    }     /**     * Returns 'true' if this instance has been modified     * since the last call to setDirty(false), 'false'     * otherwise     */    public boolean isDirty() {        return dirty;    }     /**     * Set the x attribute of this instance to 'x'     */    public void setX(int x) {        if (x == buf[X]) {            return;        }         buf[X] = x;        dirty = true;    }     /**     * Set the y attribute of this instance to 'x'     */    public void setY(int y) {        if (y == buf[Y]) {            return;        }         buf[Y] = y;        dirty = true;    }     /**     * Set the 'status' attribute of this instance to 'x'     */    public void setStatus(int status) {        if (status == buf[STATUS]) {            return;        }         buf[STATUS] = status;        dirty = true;    }     /**     * Marks this instance as dirty when 'x' is true,     * as clean otherwise     */    public void setDirty(boolean x) {        dirty = x;    }     /**     * Return the size of this particular Data subtype     */    public static int getSize() {        return SIZE;    }     /**     * Return a string representation of this instance     */    public String toString() {        return "x = " + getX() + ", y = " + getY() + ", status = "                + getStatusString();    } }

⌨️ 快捷键说明

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