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

📄 item.java

📁 DOJA平台赛车游戏
💻 JAVA
字号:
/*
 * @(#)Item.java    1.0 04/07/01 @(#)
 *
 * Copyright 2004 NTT DoCoMo, Inc. All rights reserved.
 */
import java.util.Random;

/** 
 * Item<BR>
 * The definition class of item.
 * <p>
 * @version 1.0
 * </p>
 */
public class Item extends AbstractItem {
    /** Bonus point item */
    public static final int ATTR_BONUS = 0;
    /** 1UP item */
    public static final int ATTR_1UP = 1;
    
    /**
     * The definition of item.
     * <br>
     * The following composition defines each item.<br>
     * Image ID needs to be defined by the {@link MediaCollection} class.
     * <ul>
     * <li>Item-1
     * <ul>
     * <li>[0][0]丗Attribute
     * <li>[0][1]丗Score  Attribute=Bonus point
     * <li>[0][2]丗Image id (Normal)
     * <li>[0][3]丗Image id (Get)  Attribute=1UP
     * </ul>
     * <li>Item-2
     * <ul>
     * <li>[1][0]丗Attribute
     * <li>[1][1]丗Score
     * <li>[1][2]丗Image id (Normal)
     * <li>[1][3]丗Image id (Get)
     * </ul>
     * <li> and define Item-3 and after as same.
     * </ul>
     * </ul>
     * @see MediaCollection#URL
     */
    private static final int[][] ITEM_DEFINE = {
        /* Regular Bonus */
        {
            ATTR_BONUS,
            100,
            MediaCollection.IMG_BONUS_MIN,
            MediaCollection.IMG_BONUS_MIN
        },
        /* Big Bonus */
        {
            ATTR_BONUS,
            500,
            MediaCollection.IMG_BONUS_BIG,
            MediaCollection.IMG_BONUS_BIG
        },
        /* 1UP */
        {
            ATTR_1UP,
            0,
            MediaCollection.IMG_1UP,
            MediaCollection.IMG_1UP_C
        }
    };

    /**
     * Attribute
     * @see #ITEM_DEFINE
     */
    private static final int ATTR = 0;

    /**
     * Score
     * @see #ITEM_DEFINE
     */
    private static final int BONUS = 1;

    /**
     * Image id (Normal)
     * @see #ITEM_DEFINE
     */
    private static final int IMAGE_NAME = 2;

    /**
     * Image id (Get)
     * @see #ITEM_DEFINE
     */
    private static final int IMAGE_NAME_CONTACT = 3;

    /**
     * Item index
     * <br>
     * It is set up at random within the limits of the number of array of {@link #ITEM_DEFINE}
     * @see #ITEM_DEFINE
     */
    private int index;

    /** Random number generation class */
    private Random rndm;

    /**
     * Constructor.
     * <br>
     * An item is created at random from the item information defined by {@link #ITEM_DEFINE}
     * @param _leftEnd Range which displays an item (Minimum)
     * @param _rightEnd Range which displays an item (Maximum)
     * @see #ITEM_DEFINE
     */
    public Item(int _leftEnd, int _rightEnd) {
        super(TYPE_ITEM);
        rndm = new Random();

        /* The kind of item to generate */
        index = Math.abs(rndm.nextInt()) % ITEM_DEFINE.length;

        /* The picture of an item */
        setImage(ITEM_DEFINE[index][IMAGE_NAME]);

        /* Display position */
        if (0 == Math.abs(rndm.nextInt()) % 2) {
            setPosX(_leftEnd);
        } else {
            setPosX(_rightEnd - getImage().getWidth());
        }
        setPosY(1);
    }

    /**
     * Gets the bonus score.
     * @return Bonus
     */
    public int getBonus() {
        return ITEM_DEFINE[index][BONUS];
    }

    /**
     * Gets the attribute of an item.
     * @return Attribute
     */
    public int getAttr() {
        return ITEM_DEFINE[index][ATTR];
    }

    /*
     * @see AbstractItem#contact()
     */
    public void contact() {
        setStatus(STATUS_CONTACT);
        setImage(ITEM_DEFINE[index][IMAGE_NAME_CONTACT]);
    }
}

⌨️ 快捷键说明

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