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

📄 brick.java

📁 this a game,you can learn the j2me content by this project
💻 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: Brick.java,v 1.2 2003/05/16 00:25:15 zull Exp $ */package com.sun.j2me.blueprints.jbricks;import javax.microedition.lcdui.Graphics;/** * This class represents an individual brick, with its * position, dimension, type and color. Bricks know * how to draw themselves, and how to handle collisions. */public class Brick extends Sprite {    public static final int WIDTH = Screen.width / 15;    public static final int HEIGHT = Screen.height / 30;    public static final int STEP = Screen.width / 25;    public static final int GAP = Math.max(2, Screen.width / 50);    public static final int ZOMBIE = 0;    public static final int STANDARD = 1;    public static final int FIXED = 2;    public static final int SLIDE = 3;    private int pos;    private int type;    private ThreeDColor color;    private ThreeDColor brighter;    private ThreeDColor darker;    private ThreeDColor[] color_list = {        ThreeDColor.black, ThreeDColor.blue, ThreeDColor.green,         ThreeDColor.darkGreen    };    private int score;    private BrickList owner;    public Brick(BrickList owner, int x, int y, int pos, int type) {        this.pos = pos;        this.owner = owner;        moveTo(x, y);        if (type == ZOMBIE) {            width = 0;            height = 0;        } else {            width = WIDTH;            height = HEIGHT;        }         this.type = type;        color = color_list[type];        brighter = color.brighter();        darker = color.darker();        if (type == STANDARD) {            score = 1;        }     }    public Brick(Brick brick) {        pos = brick.pos;        owner = brick.owner;        moveTo(brick.x, brick.y);        type = brick.type;        width = brick.width;        height = brick.height;        color = brick.color;        brighter = brick.brighter;        darker = brick.darker;        score = brick.score;    }    public int getPos() {        return pos;    }     public void setPos(int pos) {        this.pos = pos;    }     public void setColor(ThreeDColor color) {        this.color = color;        brighter = color.brighter();        darker = color.darker();    }     public void clear() {        type = ZOMBIE;        width = 0;        height = 0;    }     public int hit(int direction) {        if (type == STANDARD) {            clear();        }         if (type == SLIDE) {            Brick neighbor = owner.getNeighbor(this, direction);            if (neighbor != null && neighbor.getType() == 0) {                owner.moveBrick(pos, neighbor.pos);            }         }         return score;    }     public int getType() {        return type;    }     public boolean isFixed() {        return type == ZOMBIE || type == FIXED;    }     public void paint(Graphics g) {        if (type == ZOMBIE) {            return;        }         g.setColor(color.getRGB());        g.fillRect(x, y, width, height);        g.setColor(brighter.getRGB());        g.drawLine(x, y, x + width, y);        if (Screen.width >= 150) {            g.drawLine(x, y + 1, x + width - 1, y + 1);        }         g.drawLine(x, y, x, y + height);        if (Screen.height >= 150) {            g.drawLine(x + 1, y, x + 1, y + height - 1);        }         g.setColor(darker.getRGB());        g.drawLine(x + width, y, x + width, y + height);        if (Screen.height >= 150) {            g.drawLine(x + width - 1, y + 1, x + width - 1, y + height);        }         g.drawLine(x, y + height, x + width, y + height);        if (Screen.width >= 150) {            g.drawLine(x + 1, y + height - 1, x + width, y + height - 1);        }     }     public void paintShadow(Graphics g) {        if (type == ZOMBIE) {            return;        }         g.setColor(ThreeDColor.black.getRGB());        g.fillRect(x + shadow, y + shadow, width, height);    }     public void erase(Graphics g) {        if (isFixed()) {            return;        }         g.setColor(Screen.BACKGROUND);        g.fillRect(x, y, width + shadow, height + shadow);    } }

⌨️ 快捷键说明

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