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

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

?? world.java

?? SIMULATION FOURMILIERE -3D-ISOMETRIQUE
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
package fr.umlv.fourmIR2000.world;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

import fr.umlv.fourmIR2000.Game;
import fr.umlv.fourmIR2000.insect.Insect;
import fr.umlv.fourmIR2000.insect.Team;
import fr.umlv.fourmIR2000.pictures.Values;
import fr.umlv.lawrence.impl.DefaultGridModel;


/**
 * World to use with the game.
 * This is a sort of container of all objects that must be drawn on the JPanel.
 */
public final class World implements Serializable {
	
    /** For serialization : version of the class */
    private final static long serialVersionUID = 1L;
    
    /** Model used to draw pictures  BE CAREFUL : We don't want it to be serializable !!! */
    private transient DefaultGridModel<Values> model;

    /** Shortest path finding */
    private transient PathFinding path;
    
    /** Size X of the game */
    private int sizeX;
    
    /** Size Y of the game */
    private int sizeY;
    
    /** Matrix of Floor elements */
    private Floor tab[][];  
    
    /** Array of teams playing */
    private ArrayList<Team> tabTeam;
    
    /** Array of food present in the game */
    private ArrayList<WorldPoint> tabFood;

    /** The point of the map who has the focus */
    private WorldPoint selectedPoint;
    
    
    /**
     * Create a new World for playing
     * @param sizeX     Size X of the game (the real size is this size + size of the left menu)
     * @param sizeY     Size Y of the game
     */
    public World(int sizeX, int sizeY) {
        // Errors detection
        if (sizeX < 1) sizeX = 1;
        if (sizeY < 1) sizeY = 1;
        
        // Initialization of the variables
        this.sizeX = sizeX;
        this.sizeY = sizeY;
        tabTeam = new ArrayList<Team>();
        tabFood = new ArrayList<WorldPoint>();
        path = null;
        selectedPoint = null;
        initializeGridModel();
    }
    

    /**
     * Give the GridModel used by the world
     * @return the DefaultGridModel to use in a GridPane
     * @see fr.umlv.lawrence.GridPane
     */
    public DefaultGridModel<Values> getModel() {
        return model;
    }

    
    /**
     * Generate an new world, and store the position of the two antHills
     * >> The first antHill is the one we play with
     * @param maxX          new X maximal coord
     * @param maxY          new Y maximal coord
     * @param percentDesert percent of desert tiles in the map
     * @param percentWater  percent of water tiles in the map
     * @param percentRocks  % of rocks to have in the map
     * @param percentFood   % of food to have in the map
     */
    public void generateNewWorld(int maxX, int maxY, int percentDesert, int percentWater, int percentRocks, int percentFood) {
        sizeX = maxX;
        sizeY = maxY;
        RandomWorld rndWorld = new RandomWorld(sizeX, sizeY, percentDesert, percentWater, percentRocks, percentFood);
        tab = rndWorld.getWorld();
        tabTeam.clear();
        path = new PathFinding(this);
        initializeGridModel();
        refresh();
    }
    
    
    /**
     * Initialize a new GridModel with the current 'Floor' elements 
     */
    private void initializeGridModel() {
        @SuppressWarnings("unchecked")
        Set<Values>[] array = (Set<Values>[]) new Set<?>[sizeX * sizeY];
        int i = 0;
        for (int y=0; y < sizeY; ++y)
            for (int x=0; x < sizeX; ++x) {
            	array[i]=EnumSet.noneOf(Values.class);
            	if (tab == null)
            		array[i].add(Values.grass);
            	else
            		array[i].addAll(tab[y][x].getPictures());
            	i++;
            }
        model = new DefaultGridModel<Values>(sizeY, sizeX, Arrays.asList(array));
    }
    
    
    /**
     * Store the food positions in an array. This way, all insects can find where is the nearest food.
     */
    public void storeFood() {
        tabFood.clear();
        for (int y = 0; y < sizeY; ++y)
            for (int x = 0; x < sizeX; ++x)
                if (tab[y][x].getType() == Values.food)
                    tabFood.add(tab[y][x].getPoint());
    }

    
    /**
     * Give the width of the map
     * @return the width of the map (+ the size of the menu)
     */
    public int getWidth() {
        return sizeX;
    }
    
    
    /**
     * Give the height of the map
     * @return the height of the map
     */
    public int getHeight() {
        return sizeY;
    }

    
    /**
     * Return the value of the element at this tile
     * @param x X position
     * @param y Y position
     * @return the value
     */
    public Values getElement(int x, int y) {
        if (isPositionAvailable(x, y))
            return tab[y][x].getType();
        return null;
    }

    
    /**
     * Return the value of the background element at this tile
     * @param x X position
     * @param y Y position
     * @return the value
     */
    public Values getBackgroundElement(int x, int y) {
        if (isPositionAvailable(x, y))
            return tab[y][x].getBackgroundType();
        return null;
    }
    
    
    /**
     * Assign an element for the backgroun of a specific tile
     * @param x         X posiiton
     * @param y         Y position
     * @param type value to assign
     * @param isDirect true to redraw immediately, false to wait for a refresh() call
     * @see #refresh()
     */
    public void setElement(int x, int y, Values type, boolean isDirect) {
        if (isPositionAvailable(x, y)) {
            // We update the ground element
            tab[y][x].setType(type);
            tab[y][x].setObstacle(Values.isObstacle(type));
            // And we inform the model that it has changed
            updateModelAndAdjacentTiles(x, y, isDirect);
        }
    }
    
    
    /**
     * Assign an element for the backgroun of a specific tile
     * @param floor		the floor element to update
     * @param isDirect true to redraw immediately, false to wait for a refresh() call
     * @see #refresh()
     */
    public void setElement(Floor floor, boolean isDirect) {
        int x = floor.getPoint().getX();
        int y = floor.getPoint().getY();
    	if (isPositionAvailable(x, y)) {
            // We update the ground element and the graphics of tiles around
            tab[y][x] = floor;
            WorldBlur.blurFloor(tab, floor);
            WorldBlur.blurAdjacentFloors(tab, floor);
            // And we inform the model that it has changed
            updateModelAndAdjacentTiles(x, y, isDirect);
     
        }
    }
    

    /**
     * Try to update the pictures of all adjacent tiles
     * @param x	the X coord of the main tile
     * @param y	the Y coord of the main tile
     * @param isDirect true to redraw immediately, false to wait for a refresh() call
     * @see #refresh()
     */
    private void updateModelAndAdjacentTiles(int x, int y, boolean isDirect) {
        updateModel(x, y, isDirect);
        if (isPositionAvailable(x-1, y)) updateModel(x-1, y, isDirect);
        if (isPositionAvailable(x+1, y)) updateModel(x+1, y, isDirect);
        if (isPositionAvailable(x, y-1)) updateModel(x, y-1, isDirect);
        if (isPositionAvailable(x, y+1)) updateModel(x, y+1, isDirect);
    }
    

    /**
     * Indicate if the specified position is crossable or not, without
     * regarding if there is an insect or not in the tile. 
     * @param p The position to check
     * @return true if it is crossable
     */
    private boolean isBackgroundCrossable(WorldPoint p) {
        return isPositionAvailable(p) && !tab[p.getY()][p.getX()].isObstacle();
    }

    
    /**
     * Indicate if the specified position is crossable or not, regarding
     * if there is an insect on it
     * @param p The position to check
     * @return true if it is crossable
     */
    public boolean isCrossable(WorldPoint p) {
        return isBackgroundCrossable(p) && tab[p.getY()][p.getX()].getInsect() == null;
    }


    /**
     * Indicate if the specified position is available for an insect or not
     * @param x     X position
     * @param y     Y position
     * @return true if the tile is free
     * @see #isPositionAvailable(WorldPoint)
     */
    public boolean isPositionAvailable(int x, int y) {
        return (x < 0 || y < 0 || x >= sizeX || y >= sizeY) ? false : true;
    }
    

    /**
     * Indicate if the specified position is available for an insect or not
     * @param p the point to check
     * @return true if the tile is free
     * @see #isPositionAvailable(int, int) 
     */
    boolean isPositionAvailable(final WorldPoint p) {
        return isPositionAvailable(p.getX(), p.getY());
    }
        
    
    /**
     * Tell us if we can move to the chosen destination.
     * Be careful: we can only move of one tile ! 
     * @param src   the source Point
     * @param dest  the destination Point
     * @return true if we can go there
     */
    public boolean canMoveHere(WorldPoint src, WorldPoint dest) {
        int destX = dest.getX();
        int destY = dest.getY();
        
        // Bad position ? We quit immediatly
        if (src.distance(dest) >= 2 || ! isPositionAvailable(dest) || tab[destY][destX].isObstacle())
            return false;
        /* We check for diagonals : we can't move in a diagonal if there are block all around.
         * ie. if we want to go Upper/Left, and if there are rocks on left and upper, we can't go. */
        int x = src.getX();
        int y = src.getY();
        final WorldPoint UpLeft =    getPoint(x - 1, y - 1);
        final WorldPoint Up =        getPoint(x,     y - 1);
        final WorldPoint UpRight =   getPoint(x + 1, y - 1);
        final WorldPoint Left =      getPoint(x - 1, y);
        final WorldPoint Right =     getPoint(x + 1, y);
        final WorldPoint DownLeft =  getPoint(x - 1, y + 1);
        final WorldPoint Down =      getPoint(x,     y + 1);
        final WorldPoint DownRight = getPoint(x + 1, y + 1);
        if (   (dest.equals(UpLeft)    && !isCrossable(Up)   && !isCrossable(Left))
            || (dest.equals(UpRight)   && !isCrossable(Up)   && !isCrossable(Right))
            || (dest.equals(DownLeft)  && !isCrossable(Down) && !isCrossable(Left))
            || (dest.equals(DownRight) && !isCrossable(Down) && !isCrossable(Right))
        )
            return false;
        return true;
    }
    
    
     /**
     * Give the list of all insects that are around a point
     * @param me        insect who calls the verification
     * @param radius    the radius to check around the insect
     * @param wantAFriend if true return our friends. If false, return the ennemies
     * @return true if exists or false;
     */
    public LinkedList<Insect> giveInsectAround(Insect me, int radius, boolean wantAFriend) {
        WorldPoint p = me.getPos();
        LinkedList<Insect> result= new LinkedList<Insect>();

        for(int y = p.getY() - radius; y <= p.getY() + radius; y++) {
            for (int x = p.getX() - radius; x <= p.getX() + radius; x++) {
                if (isPositionAvailable(x, y)) {
                    Floor floor = tab[y][x];
                    if (! floor.getPoint().equals(p)) {
                        Insect insect = floor.getInsect();
                        if (insect != null) {
                            boolean isOurTeam = insect.getTeam().equals(me.getTeam());
                            if ((isOurTeam && wantAFriend) || (!isOurTeam && !wantAFriend))
                                result.add(insect);
                        }
                    }
                }
            }
        }
        return result;
    }
    
    
    /**
     * Add a team of insects to the world. The first team would be the team we play with !
     * >> it works because we use an ArrayList
     * @param antHill    point of the antHill
     * @param color      color of the team
     * @param game       the gameassociated (to perform some special actions when an antQueen die for example)
     */
    public void addTeam(WorldPoint antHill, int color, Game game) {
        Team team = new Team(this, antHill, color, game);
        team.addMaster();
        tabTeam.add(team);
    }

    
    /**
     * Add an insect in the game
     * @param insect    new insect to add
     * @return          true if we can add the insect in the specified place
     */
    public boolean addInsect(Insect insect) {
        if (insect == null)
            return false;
        WorldPoint p = insect.getPos();

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲制服丝袜av| 亚洲午夜影视影院在线观看| 日韩国产精品久久久久久亚洲| www.av亚洲| 久久综合色综合88| 青青草国产精品97视觉盛宴| 国产日韩精品一区二区三区在线| 欧美日韩不卡一区| 欧美va在线播放| 欧美午夜一区二区| 欧美性大战xxxxx久久久| 国产欧美日韩综合| 国产精品一级片| 欧美日韩精品一区二区三区蜜桃 | 精品国产欧美一区二区| 亚洲欧美一区二区久久| 不卡大黄网站免费看| 亚洲三级电影全部在线观看高清| 97精品视频在线观看自产线路二| 亚洲三级电影全部在线观看高清| 精品国一区二区三区| 日韩一区和二区| 国产一区二区主播在线| 中文天堂在线一区| 91免费版pro下载短视频| 亚洲午夜久久久久久久久电影网 | 欧美成人a在线| 欧美日韩综合不卡| 久久精品久久精品| 亚洲精品一区二区三区四区高清| 欧美日韩中文一区| 欧美午夜片在线看| 欧洲国内综合视频| 国产乱码精品1区2区3区| 日韩电影免费在线观看网站| 亚洲国产乱码最新视频| 亚洲国产日韩在线一区模特 | 国产亚洲精品超碰| 色妞www精品视频| 国产欧美中文在线| 2023国产精品自拍| 日韩女优制服丝袜电影| 色婷婷综合久久久中文字幕| 91视频一区二区| 色域天天综合网| 欧美性一二三区| 欧美电影一区二区| 成人黄色在线视频| 91日韩一区二区三区| 在线观看国产精品网站| 欧美日本不卡视频| 日韩精品中文字幕在线不卡尤物| 欧美不卡一区二区三区| 久久亚区不卡日本| 中文字幕在线不卡| 久久综合一区二区| 九一九一国产精品| 中文字幕久久午夜不卡| 欧美男女性生活在线直播观看| 色综合久久久网| 91电影在线观看| 国产精品自拍一区| 日本va欧美va瓶| 久久99久久久久| 精品在线播放免费| 国产精品一区二区三区乱码 | 亚洲mv在线观看| 欧美日韩一级片网站| 精品视频在线免费| 欧美人牲a欧美精品| 99久久婷婷国产综合精品| 成+人+亚洲+综合天堂| 91国产成人在线| 欧美精品第1页| 欧美精品一区视频| 日本一区二区三级电影在线观看| 久久久777精品电影网影网| 亚洲精品在线观| 亚洲国产岛国毛片在线| 亚洲综合一区二区三区| 日本亚洲视频在线| 国产精品一区二区三区乱码| 精品一区二区三区在线播放视频 | 国产一区二区三区最好精华液| 国产一区二区三区精品欧美日韩一区二区三区 | 亚洲激情综合网| 午夜电影久久久| 国产在线一区二区综合免费视频| 韩国精品免费视频| av成人老司机| 51久久夜色精品国产麻豆| 久久久久综合网| 亚洲品质自拍视频网站| 肉丝袜脚交视频一区二区| 久久午夜免费电影| 亚洲女性喷水在线观看一区| 日韩在线一二三区| 国产精品18久久久久| 色哟哟在线观看一区二区三区| 成人黄页毛片网站| 精品久久久久久久久久久院品网 | 亚洲午夜在线视频| 国产又粗又猛又爽又黄91精品| 色婷婷av一区二区三区gif| 91精品国产一区二区三区| 国产精品午夜春色av| 日韩中文字幕不卡| 成人蜜臀av电影| 欧美三级中文字幕在线观看| 91麻豆精品国产91久久久资源速度| 久久精品在线免费观看| 五月天一区二区| 成人黄色在线网站| 精品福利在线导航| 午夜国产精品一区| 91视视频在线观看入口直接观看www | 国产日韩欧美不卡在线| 五月天欧美精品| 97久久超碰国产精品| 日韩一区二区三区视频在线 | av在线不卡网| 日韩写真欧美这视频| 亚洲婷婷综合色高清在线| 精品亚洲欧美一区| 欧美久久久久久久久久| 日韩伦理av电影| 国产成人丝袜美腿| 99视频一区二区三区| 国产午夜精品理论片a级大结局| 日本三级亚洲精品| 欧美三级视频在线| 伊人色综合久久天天人手人婷| 国产成人高清在线| 欧美videos中文字幕| 日韩综合小视频| 国产二区国产一区在线观看| 欧美日韩极品在线观看一区| 精品成人在线观看| 日韩高清在线一区| 在线免费观看日本一区| 国产精品国产精品国产专区不蜜| 中文字幕在线不卡| 懂色av一区二区三区蜜臀| 欧美精品一区二区不卡| 亚洲成人在线免费| 色综合视频在线观看| 亚洲视频香蕉人妖| 91丨porny丨国产入口| 国产亚洲一区字幕| 免费成人你懂的| 欧美一级欧美一级在线播放| 青青草97国产精品免费观看 | 尤物视频一区二区| 一本大道久久精品懂色aⅴ| 亚洲三级在线免费| 在线免费观看不卡av| 一区二区三区在线免费播放| 91官网在线免费观看| 亚洲视频在线一区二区| 99久久精品免费精品国产| 国产精品进线69影院| 国产一区二区网址| 欧美成人高清电影在线| 国产做a爰片久久毛片| 久久久久亚洲蜜桃| 成人91在线观看| 国产亚洲精品久| 99re免费视频精品全部| 亚洲欧洲精品天堂一级| 99久久久久久99| 亚洲一区二区高清| 日韩亚洲欧美高清| 国产成人av电影在线播放| 国产欧美一区二区精品婷婷| 国产成人免费视频精品含羞草妖精| 国产精品美日韩| 欧美三级在线视频| 天堂精品中文字幕在线| 精品日韩一区二区三区 | 日本精品裸体写真集在线观看| 亚洲人成精品久久久久久| 成熟亚洲日本毛茸茸凸凹| 久久美女高清视频| 99精品久久久久久| 三级久久三级久久| 国产亚洲成年网址在线观看| 99视频精品全部免费在线| 首页国产丝袜综合| 一本色道久久综合狠狠躁的推荐| 亚洲第一福利一区| 久久久九九九九| 色综合久久九月婷婷色综合| 日本午夜精品视频在线观看 | 亚洲一级二级在线| 久久免费国产精品| jizz一区二区| 激情丁香综合五月| 亚洲小少妇裸体bbw| 国产婷婷色一区二区三区| 欧美曰成人黄网|