/*
 * CxgNX
 * 
 */
package dqc;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;

public abstract class Event {
    public static final int CS = 32;
    // }bv`bvÌ1sÌ
    public static final int NUM_CHIPS_IN_ROW = 30;
    
    // ÀWi}XPÊj
    protected int x, y;
    // ÀWisNZPÊj
    protected int px, py;
    // C[WÔ
    protected int imageNo;
    // Ú®Â\©
    protected boolean isMovable;

    // }bv`bvC[WiNXÏÈÌÅIuWFNgÅ¤Lj
    protected static Image mapchipImage;
    
    public Event(int x, int y, int imageNo, boolean isMovable) {
        this.x = x;
        this.y = y;
        px = x * CS;
        py = y * CS;
        this.imageNo = imageNo;
        this.isMovable = isMovable;
        
        // C[Wð[h
        if (mapchipImage == null) {
            loadImage();
        }
    }
    
    /**
     * `æ
     * 
     * @param g OtBbNXIuWFNg
     * @param offsetX XûüItZbg
     * @param offsetY YûüItZbg
     * @param mapchipImage }bv`bvC[W
     */
    public void draw(Graphics g, int offsetX, int offsetY) {
        int cx = (imageNo % NUM_CHIPS_IN_ROW) * CS;
        int cy = (imageNo / NUM_CHIPS_IN_ROW) * CS;
        g.drawImage(mapchipImage,
                px - offsetX,
                py - offsetY,
                px - offsetX + CS,
                py - offsetY + CS,
                cx,
                cy,
                cx + CS,
                cy + CS,
                null);
    }
    
    public abstract void start(Hero hero, Map map, MessageWindow msgWnd);
    
    /**
     * XÀWðÔ·
     * 
     * @return ÊuÌXÀWi}XPÊj
     */
    public int getX() {
        return x;
    }
    
    /**
     * YÀWðÔ·
     * 
     * @return ÊuÌYÀWi}XPÊj
     */
    public int getY() {
        return y;
    }
    
    /**
     * XÀWðZbg
     * 
     * @param x XÀWi}XPÊj
     */
    public void setX(int x) {
        this.x = x;
        px = x * CS;
    }
    
    /**
     * YÀWðZbg
     * 
     * @param x YÀWi}XPÊj
     */
    public void setY(int y) {
        this.y = y;
        py = y * CS;
    }
    
    /**
     * XÀWisNZPÊjðÔ·
     * 
     * @return ÊuÌXÀWisNZPÊj
     */
    public int getPx() {
        return px;
    }

    /**
     * YÀWisNZPÊjðÔ·
     * 
     * @return ÊuÌYÀWisNZPÊj
     */
    public int getPy() {
        return py;
    }
    
    /**
     * C[WÔðÔ·
     * 
     * @return C[WÔ
     */
    public int getImageNo() {
        return imageNo;
    }
    
    /**
     * Ú®Â\©²×é
     * 
     * @return Ú®Â\Èçtrue
     */
    public boolean isMovable() {
        return isMovable;
    }
    
    /**
     * C[Wð[h
     * 
     */
    private void loadImage() {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        mapchipImage = toolkit.getImage(getClass().getClassLoader().getResource("image/mapchip.png"));
    }
    
    /**
     * CxgÌ¶ñðÔ·ifobOpj
     * 
     * @return Cxg¶ñ
     */
    public String toString() {
        return x + "," + y + "," + px + "," + py + "," + imageNo + "," + isMovable;
    }
}
