亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? board.java

?? 貪食蛇小游戲 用j2me編的 用的是ide 大家參考一下下哦
?? JAVA
字號:
/*
 * @(#)Board.java	1.2 03/01/22
 *
 * Copyright (c) 2004 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms
 */

package example.pushpuzzle2;

import javax.microedition.lcdui.*;

/**
 * The class Board knows how the pieces move, handles undo, and
 * handles reading of screens.
 */
public class Board {
    private int level;
    private byte[] array;
    private byte[] pathmap;	// used for runTo to find shortest path
    private int width, height;
    private int pusher;	// position of the pusher at index into array
    private int packets = 0;	// total number of packets
    private int stored = 0;	// number of packets in Stores
    private byte[] moves;	// recorded moves
    private int nmoves;	// number of moves executed
    private int npushes;	// number of pushes executed

    // Move directions
    public static final int LEFT = 0;
    public static final int RIGHT = 3;
    public static final int UP = 1;
    public static final int DOWN = 2;
    public static final int MOVEPACKET = 4;

    // Bit definitions for pieces of each board position
    public static final byte GROUND = 0;	// If nothing there
    public static final byte STORE = 1;	// If it is a storage place
    public static final byte PACKET = 2;	// If it has a packet
    public static final byte WALL = 4;	// If it is a wall
    public static final byte PUSHER = 8;	// If the pusher is there

    /**
     * Creates new Board initialized to a simple puzzle.
     */
    public Board() {
        moves = new byte[200];
        screen0();
    }

    /**
     * Create the hard coded simple game board.
     */
    public void screen0() {
        width = 9;
        height = 7;
        array = new byte[width * height];
        level = 0;
        nmoves = 0;
        npushes = 0;
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                byte t = (x == 0 || y == 0 ||
                x == width - 1 || y == height - 1) ?
                WALL : GROUND;
                set(x, y, t);
            }
        }
        packets = 2;
        stored = 0;
        set(2, 2, PACKET);
        set(4, 4, PACKET);
        set(4, 2, STORE);
        set(6, 4, STORE);
        pusher = index(1, 1);
    }

    /**
     * Move the pusher in the direction indicated.
     * If there is a wall, don't move.
     * if there is a packet in that direction, try to move it.
     * @param move the direction; one of LEFT, RIGHT, UP, DOWN
     * @return the direction actually moved, -1 if not moved
     */
    public int move(int move) {
        int obj = pusher + indexOffset(move);

        // Handle the simple cases
        if ((array[obj] & WALL) != 0)
            return -1;

        int m = movePacket(obj, move);
        if (m < 0)
            return -1;	// If can't move packet, done!

        pusher = obj;	// move the pusher to the new spot
        saveMove(m);
	return m;
    }

    /**
     * Move the packet in the direction indicated relative to
     * the pusher.  If it fits into a store position remember.
     * @return -1 if can't be moved or the updated move
     * including the packet flag if there was a packet to move.
     */
    private int movePacket(int index, int move) {
        if ((array[index] & PACKET) == 0)
            return move;	// no packet to move

        int dest = index + indexOffset(move);
        if (array[dest] > STORE)
            return -1;	// can't move packet into next spot.

        // Remove packet from current location
        array[index] &= ~PACKET;
        if ((array[index] & STORE) != 0)
            stored--;

        // Insert packet into new location
        array[dest] |= PACKET;
        if ((array[dest] & STORE) != 0)
            stored++;

        npushes++;	// count pushes done
        return move + MOVEPACKET;
    }

    /*
     * Save a move, extending the array if necessary.
     */
    private void saveMove(int move) {
        if (nmoves >= moves.length) {
            byte[] n = new byte[moves.length + 50];
            System.arraycopy(moves, 0, n, 0, moves.length);
            moves = n;
        }
        moves[nmoves++] = (byte)move;
    }

    /**
     * Undo the most recent move
     * @return the move undone;  if none -1 is returned;
     *  See LEFT, RIGHT, UP, DOWN, and MOVEPACKET
     */
    public int undoMove() {
        if (nmoves <= 0)
            return -1;
        int move = moves[--nmoves];
        int rev = (move & 3) ^ 3;	// reverse the direction
        int back = pusher + indexOffset(rev);

        if ((move & MOVEPACKET) != 0) {
            npushes--;	// "unpush"
            movePacket(pusher + indexOffset(move), rev);	// move packet
        }
        pusher = back;
	return move;
    }

    /**
     * Determine if the screen has been solved.
     */
    public boolean solved() {
        return packets == stored;
    }

    /**
     * Move the player to the position (x,y), if possible. Return 
     * the direction it moved if successful, otherwise -1.
     * The position (x,y) must be empty.
     * @param x window coordinate
     * @param y window coordinate
     * @return the direction that it moved, -1 is not moved;
     *  See LEFT, RIGHT, UP, DOWN, MOVEPACKET
     */
    public int runTo(int x, int y, int max) {
        int target = index(x, y);
        if (target < 0 || target >= array.length)
            return -1;
        if (target == pusher)
            return -1;	// already there

	/* Fill the path map */
        if (pathmap == null || pathmap.length != array.length) {
            pathmap = new byte[array.length];
        }
        // Fill with unset value.
        for (int i = 0; i < pathmap.length; i++)
            pathmap[i] = 127;

        // flood fill search to find a shortest path to the push point.
        findTarget(target, (byte)0);

	/*
	 * if we didn't make it back to the players position,
	 * there is no valid path to that place.
	 */
        if (pathmap[pusher] == 127) {
            return -1;
        } else {
            // We made it back, so let's walk the path we just built up
	    // Save the final move to return
            int pathlen = pathmap[pusher];
            int pathmin = pathlen - max;
	    int dir = -1;
            for (pathlen--; pathlen >= pathmin; pathlen--) {
                if (pathmap[pusher - 1] == pathlen) {
		    dir = LEFT;
                    saveMove(dir);
                    pusher--;
                } else if (pathmap[pusher + 1] == pathlen) {
		    dir = RIGHT;
                    saveMove(dir);
                    pusher++;
                } else if (pathmap[pusher - width] == pathlen) {
		    dir = UP;
                    saveMove(dir);
                    pusher -= width;
                } else if (pathmap[pusher + width] == pathlen) {
		    dir = DOWN;
                    saveMove(dir);
                    pusher += width;
                } else {
		    /*
		     * if we get here, something is SERIOUSLY wrong,
		     * so we should abort
		     */
                    throw new RuntimeException("runTo abort");
                }
            }
	    return dir;
        }
    }

    /**
     * Find the shortest path to the pusher via a fill search algorithm
     */
    private void findTarget(int t, byte pathlen) {
        if (array[t] > STORE)
            return;	// Either a wall or looped back to player

	// Already tried here and this way is longer
        if (pathmap[t] <= pathlen)
                return;

        pathmap[t] = pathlen++;	// set path length to this location
        if (t == pusher)
            return;

        findTarget(t - 1, pathlen);	// to previous cell
        findTarget(t + 1, pathlen);	// to next cell
        findTarget(t - width, pathlen);	// to previous row
        findTarget(t + width, pathlen);	// to next row
    }

    /**
     * Return the pieces at the location.
     * @param x location in the board.
     * @param y location in the board.
     * @return flags indicating what pieces are in this board location.
     * Bit flags; combinations of WALL, PUSHER, STORE, PACKET.
     */
    public byte get(int x, int y) {
        int offset = index(x, y);
        if (offset == pusher)
            return (byte)(array[offset] | PUSHER);
        else
            return array[offset];
    }

    /**
     * Set the value of the location.
     */
    private void set(int x, int y, byte value) {
        array[index(x, y)] = value;
    }

    /**
     * Compute the index in the array of the x, y location.
     */
    private int index(int x, int y) {
        if (x < 0 || x >= width ||
        y < 0 || y >= height)
            return -1;

        return y * width + x;
    }

    /**
     * Get the location of the pusher.
     * It is returned as an int with the lower 16 bits being
     * the x index and the upper 16 bits being the y index.
     * @return the encoded location of the pusher.
     */
    public int getPusherLocation() {
	int x = pusher % width;
	int y = pusher / width;
	return (y << 16) + x;
    }

    /**
     * Compute the offset in the array of the cell relative
     * to the current pusher location in the direction of the move.
     * Note: the walls around the edge always make a +/- guard band.
     * Also, the order of evaluation should never try to get to +/- 2.
     */
    private int indexOffset(int move) {
        switch (move & 3) {
            case LEFT:
                return -1;
            case RIGHT:
                return +1;
            case UP:
                return -width;
            case DOWN:
                return +width;
        }
        return 0;
    }

    /**
     * Read a board from a stream.
     * Read it into a fixed size array and then shrink to fit.
     */
    public void read(java.io.InputStream is, int l) {
        final int W = 20;
        final int H = 20;
        byte[] b = new byte[W * H];
        // Add resize code later.
        int c, w = 0;
        int x = 0, y = 0, xn = 0, yn = 0, npackets = 0;
        try {
            while ((c = is.read()) != -1) {
                switch (c) {
                    case '\n':
                        if (x > w) {
                            w = x;
                        }

                        y++;
                        x = 0;
                        break;

                    case '$':
                        b[y * W + x++] = PACKET;
                        npackets++;
                        break;

                    case '#':
                        b[y * W + x++] = WALL;
                        break;

                    case ' ':
                        b[y * W + x++] = GROUND;
                        break;

                    case '.':
                        b[y * W + x++] = STORE;
                        break;

                    case '*':
                        b[y * W + x] = PACKET;
                        b[y * W + x++] |= STORE;
                        npackets++;
			stored++;
                        break;

                    case '+':	// player and store in same place
                        b[y * W + x++] = STORE;
                    case '@':
                        xn = x;
                        yn = y;
                        x++;
                        break;
                }
            }
        } catch (java.io.IOException ex) {
            ex.printStackTrace();
        }

        if (y > 0) {
            array = new byte[w * y];
            if (y > w) {	// Switch x for y while copying
                width = y;
                height = w;
                for (y = 0; y < width; y++) {
                    for (x = 0; x < w; x++) {
                        array[index(y, x)] = b[y * W + x];
                    }
                }
                pusher = index(yn, xn);
            } else {
                width = w;
                height = y;
                array = new byte[width * height];
                for (y = 0; y < height; y++) {
                    for (x = 0; x < width; x++) {
                        array[index(x, y)] = b[y * W + x];
                    }
                }
                pusher = index(xn, yn);
            }
            stored = 0;
            packets = npackets;
            level = l;
            nmoves = 0;
            npushes = 0;
        }
    }

    /**
     * Get the width of the game board.
     */
    public int getWidth() {
        return width;
    }

    /**
     * Get the height of the board.
     */
    public int getHeight() {
        return height;
    }

    /**
     * Get the number of moves to get this far.
     */
    public int getMoves() {
        return nmoves;
    }

    /**
     * Get the number of packets pushed around.
     */
    public int getPushes() {
        return npushes;
    }

    /**
     * Get the number of packets stored.
     */
    public int getStored() {
        return stored;
    }

    /**
     * Convert a left/right direction into an offset.
     */
    private int dx(int dir) {
        if (dir == LEFT)
            return -1;
        if (dir == RIGHT)
            return +1;
        return 0;
    }

    /**
     * Convert a up/down direction into an offset.
     */
    private int dy(int dir) {
        if (dir == UP)
            return -1;
        if (dir == DOWN)
            return +1;
        return 0;
    }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲一二三四区不卡| 成人sese在线| www.亚洲激情.com| 337p亚洲精品色噜噜噜| 欧美韩国一区二区| 久久99久久久欧美国产| 色综合久久久久综合体| 国产精品免费观看视频| 偷拍自拍另类欧美| 91天堂素人约啪| 国产日韩欧美高清在线| 蜜桃精品在线观看| 欧美日韩的一区二区| 亚洲另类在线一区| jlzzjlzz亚洲女人18| 国产目拍亚洲精品99久久精品| 麻豆国产欧美日韩综合精品二区| 在线看一区二区| 自拍偷自拍亚洲精品播放| 国产伦理精品不卡| 日韩欧美国产精品一区| 日韩中文字幕亚洲一区二区va在线| 97精品久久久久中文字幕 | 国产日韩v精品一区二区| 日韩电影在线观看电影| 欧美日韩久久不卡| 亚洲一二三区在线观看| 欧美性色欧美a在线播放| 亚洲欧美日韩综合aⅴ视频| kk眼镜猥琐国模调教系列一区二区| 国产欧美日本一区二区三区| 国产高清亚洲一区| 久久久久国产免费免费| 国产精品香蕉一区二区三区| 久久久蜜桃精品| 国产成人在线免费观看| 国产精品日产欧美久久久久| av在线综合网| 亚洲一区二区精品久久av| 欧美午夜电影网| 日韩精品亚洲一区| 精品国偷自产国产一区| 国产米奇在线777精品观看| 久久久久久久电影| 成人av网站免费观看| 一区二区三区中文字幕精品精品 | 91看片淫黄大片一级| 亚洲美女视频在线观看| 欧美日韩精品综合在线| 久久国产免费看| 中文av字幕一区| 在线观看日韩电影| 免费在线成人网| 国产精品污污网站在线观看 | 国产精品综合一区二区| 国产精品乱人伦| 欧美午夜片在线看| 另类小说视频一区二区| 中文一区二区完整视频在线观看| av电影一区二区| 三级成人在线视频| 国产色爱av资源综合区| 欧美日韩视频在线第一区| 久久超碰97中文字幕| 国产精品视频第一区| 欧美乱妇一区二区三区不卡视频| 青青草97国产精品免费观看无弹窗版| 26uuu亚洲| 欧美色图一区二区三区| 韩国毛片一区二区三区| 1区2区3区欧美| 精品乱人伦小说| 日本韩国一区二区| 国产真实乱对白精彩久久| 亚洲免费观看高清完整版在线| 欧美videos大乳护士334| 一本久久综合亚洲鲁鲁五月天| 六月丁香婷婷久久| 亚洲一卡二卡三卡四卡| 国产日韩三级在线| 这里是久久伊人| 色综合天天综合给合国产| 狠狠色丁香婷综合久久| 国产精品久久久久婷婷| 欧美一级理论片| 欧美午夜不卡在线观看免费| 懂色av一区二区三区免费看| 奇米影视在线99精品| 亚洲国产成人av好男人在线观看| 国产精品久久久久久久久快鸭 | 日韩一卡二卡三卡国产欧美| 成人av网站在线| 国产在线播放一区三区四| 三级成人在线视频| 亚洲成人777| 日韩久久一区二区| 国产精品久久久久久久久免费丝袜| 欧美变态口味重另类| 91精品国产欧美一区二区18| 欧美系列在线观看| 欧美唯美清纯偷拍| 色婷婷综合久色| 色综合久久久久综合体桃花网| 国产69精品久久久久777| 国产乱码字幕精品高清av| 精一区二区三区| 国产一区二区三区| 国产麻豆精品久久一二三| 国产专区综合网| 国内精品久久久久影院薰衣草| 捆绑变态av一区二区三区| 日本欧美在线观看| 蜜臀av性久久久久蜜臀aⅴ四虎 | 精品视频免费在线| 欧美久久久久久久久| 欧美日韩一区二区在线视频| 欧美日韩精品电影| 日韩欧美一二三区| 日韩一区二区三区电影在线观看| 91麻豆精品国产91久久久久| 日韩免费一区二区三区在线播放| 精品国产伦一区二区三区观看体验 | 国产精品私房写真福利视频| 国产婷婷一区二区| 欧美国产综合一区二区| 亚洲婷婷综合久久一本伊一区| 亚洲免费av高清| 亚洲一级电影视频| 青青草97国产精品免费观看无弹窗版 | 一区二区三区鲁丝不卡| 日韩中文字幕不卡| 久久99精品一区二区三区三区| 韩国精品主播一区二区在线观看 | 日韩毛片一二三区| 亚洲午夜久久久久久久久久久| 亚洲www啪成人一区二区麻豆 | 午夜激情综合网| 免费人成在线不卡| 国产乱码精品一区二区三区av| 成人av集中营| 欧美日韩激情一区| 精品国产91乱码一区二区三区 | 欧美日韩情趣电影| 久久综合网色—综合色88| 国产精品视频九色porn| 亚洲曰韩产成在线| 国产综合久久久久久鬼色| 色综合色综合色综合色综合色综合 | 欧美人狂配大交3d怪物一区| 欧美va亚洲va香蕉在线| 亚洲色图19p| 欧美a级理论片| 99国产精品久久久| 欧美成人一区二区| 一区二区在线电影| 国产九九视频一区二区三区| 欧美性大战久久久久久久蜜臀| 精品播放一区二区| 亚洲成在人线免费| www.亚洲人| 精品国内片67194| 午夜精品久久久久久久| 波多野结衣欧美| 日韩欧美亚洲一区二区| 一区二区三区国产豹纹内裤在线| 国产综合色在线| 欧美二区乱c少妇| 国产精品女主播在线观看| 美女视频黄免费的久久 | 色综合久久中文字幕| 亚洲精品在线观| 五月天激情小说综合| 成人综合在线观看| 日韩女优av电影在线观看| 亚洲sss视频在线视频| 9i看片成人免费高清| 国产亚洲一区字幕| 久久99精品久久只有精品| 欧美美女激情18p| 一区二区国产盗摄色噜噜| 豆国产96在线|亚洲| 久久日韩粉嫩一区二区三区 | 粉嫩av一区二区三区在线播放| 日韩欧美成人激情| 青青草精品视频| 欧美一区二区三区免费视频| 亚洲v精品v日韩v欧美v专区| 色嗨嗨av一区二区三区| 亚洲视频免费在线| aaa国产一区| 亚洲欧美激情在线| 91尤物视频在线观看| 国产精品欧美经典| 91在线高清观看| 亚洲欧美色综合| 欧美午夜电影网| 日本不卡的三区四区五区| 欧美精品粉嫩高潮一区二区| 日本在线播放一区二区三区| 在线播放国产精品二区一二区四区|