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

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

?? hex.java

?? 用java開發的一個實施策略游戲源碼 值得學習一下
?? JAVA
字號:
/*
	Netwar
	Copyright (C) 2002  Daniel Grund, Kyle Kakligian, Jason Komutrattananon, & Brian Hibler.
 
	This file is part of Netwar.
 
	Netwar is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.
 
	Netwar is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
 
	You should have received a copy of the GNU General Public License
	along with Netwar; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package netwar.game;
import netwar.utils.*;
import netwar.utils.vectorgraphics.*;
import java.awt.*;
import netwar.mapper.HexM;
import netwar.game.object.*;

/** This class represents a single hexagon-shaped region of game-space.
 * These regions are used to simplify path-finding algorithms,
 * graphical draw-order, and terrain logic and display.
 * A Hex may contain up to one GameObject at a time.
 * @author Group N2 - Project Netwar
 * @author Daniel Grund, with adjustments by Kyle Kakligian
 */
public class Hex {
	/** The square root of three, which is particularly relavent to hexagon geometry. */
	public static final double sqrt3 = Math.sqrt(3);
	private static Hex board[][];
	private static int radius;
	private GameObject occupant;
	private int status; //Poly-boolean. 1 = occupied flag. 2 = reserved flag.
	private HexType hexType;
	
	/** Used for determining initial base locations.
	 * @param radial a number from 0 to 11 indicating the direction from the center.
	 * @param offset the distance along that radian.
	 * @param fromEdge if true, count the distance (offset) from the edge of the map, instead of the center.
	 * @return the X coordinate of the desired location (in hex coordinates).
	 */
	public static int radialX(int radial, int offset, boolean fromEdge) {
		if(fromEdge) {
			switch (radial) {
				case 4:
				case 5:
				case 6:
					return offset;
				case 3:
				case 7:
					return (radius / 2 + offset / 2);
				case 2:
				case 8:
					return (radius - 1);
				case 1:
				case 9:
					return (3 * (radius - 1) / 2 - offset / 2);
				case 0:
				case 10:
				case 11:
					return (2 * (radius - 1) - offset);
			}
		}else{
			switch (radial) {
				case 4:
				case 5:
				case 6:
					return radius - 1 - offset;
				case 3:
				case 7:
					return (radius - 1 -  (offset + 1) / 2);
				case 2:
				case 8:
					return (radius - 1);
				case 1:
				case 9:
					return ((radius - 1) + (offset + 1) / 2);
				case 0:
				case 10:
				case 11:
					return (radius - 1 + offset);
			}
		}
		return (radius - 1);
	}
	
	/** Used for determining initial base locations.
	 * @param radial a number from 0 to 11 indicating the direction from the center.
	 * @param offset the distance along that radian.
	 * @param fromEdge if true, count the distance (offset) from the edge of the map, instead of the center.
	 * @return the Y coordinate of the desired location (in hex coordinates).
	 */
	public static int radialY(int radial, int offset, boolean fromEdge) {
		if(fromEdge) {
			switch(radial) {
				case 6:
				case 7:
				case 8:
					
					return offset;
				case 5:
				case 9:
					return (radius / 2 + (offset - 1) / 2);
				case 4:
				case 10:
					return (radius - 1);
				case 3:
				case 11:
					return (3 * (radius - 1) / 2 - (offset - 1) / 2);
				case 0:
				case 1:
				case 2:
					return (2 * (radius - 1) - offset);
			}
		}else{
			switch(radial) {
				case 6:
				case 7:
				case 8:
					return radius - 1 - offset;
				case 5:
				case 9:
					return (radius - 1 -  (offset) / 2);
				case 4:
				case 10:
					return (radius - 1);
				case 3:
				case 11:
					return ((radius - 1) + (offset) / 2);
				case 0:
				case 1:
				case 2:
					return (radius - 1 + offset);
			}
		}
		return (radius - 1);
	}
	
	/** Initializes the board, which is a static array of Hex objects,
	 * designed to produce a hexagon of hexagons.
	 * Also initializes the HexType objects, and assigns them to the appropriate Hexes.
	 * @param rad The radius of the board in Hexes.
	 */
	public static void makeBoard(int rad) {
		Color brown = new Color(112,48,0);
                Color aqua = new Color(0,128,255);
		HexType temp[] = {  new HexType("tiles/brown1.gif", brown, true),
		new HexType("tiles/brown2.gif", brown, true),
		new HexType("tiles/brown3.gif", brown, true),
		new HexType("tiles/brown2.gif", brown, true),
		new HexType("tiles/brown1.gif", brown, true),
		new HexType("tiles/brown2.gif", brown, true),
		new HexType("tiles/brown1.gif", brown, true),
                new HexType("tiles/blue1.gif", aqua, false)};
		
		int i, j;
		
		
		radius = rad;
		board = new Hex[2 * radius - 1][];
		for(i = 0; i < radius; i++) {
			board[i] = new Hex[i + radius];
			for(j = 0; j < i + radius; j++) {
				board[i][j] = new Hex(temp[netwar.Netwar.netwar.random.nextInt(8)]); // temp until we can load a map
				if((board[i][j].status == 0) && (i > 7) && (j > 7) && (j < i + radius - 8) && (netwar.Netwar.netwar.random.nextFloat() < .1))
					switch(netwar.Netwar.netwar.random.nextInt(4)) {
						case 0:
							GameObject.newGameObject( new Bush(), i, j, 0, null);
						break;
						case 1:
							GameObject.newGameObject( new BushRed(), i, j, 0, null);
						break;
						case 2:
							GameObject.newGameObject( new Palm(), i, j, 0, null);
						break;
						case 3:
							GameObject.newGameObject( new PineTree(), i, j, 0, null);
						break;
					}
			}
		}
		for(i = radius; i < (2 * radius - 1); i++) {
			board[i] = new Hex[2 * radius - 1];
			for(j = i - (radius - 1); j < (2 * radius - 1); j++) {
				board[i][j] = new Hex(temp[netwar.Netwar.netwar.random.nextInt(8)]); // temp until we can load a map
				if((board[i][j].status == 0) && (i < 2 * radius - 9) && (j - i + radius - 1 > 7) && (j < 2 * radius - 9) && (netwar.Netwar.netwar.random.nextFloat() < .1))
					switch(netwar.Netwar.netwar.random.nextInt(4)) {
						case 0:
							GameObject.newGameObject( new Bush(), i, j, 0, null);
						break;
						case 1:
							GameObject.newGameObject( new BushRed(), i, j, 0, null);
						break;
						case 2:
							GameObject.newGameObject( new Palm(), i, j, 0, null);
						break;
						case 3:
							GameObject.newGameObject( new PineTree(), i, j, 0, null);
						break;
					}
			}
		}
	}
	/** Retrieves a Hex from the board.
	 * @param x The x part of the Hex coordinate of the desired hex.
	 * @param y The y part of the Hex coordinate of the desired hex.
	 * @return The desired Hex, or null if the coordinates are invalid.
	 */
	public static Hex getHex(int x, int y) {
		//Confirm validity
		if(x < 0 || x >= 2 * radius - 1 || y < 0 || y >= 2 * radius - 1 || (x < radius && y >= radius + x))
			return null;
		return board[x][y];
	}
	/** This constructor initializes the Hex according to a HexType's initializing data.
	 * @param h The HexType containing the data for this type of Hex.
	 */
	protected Hex(HexType h) {
		hexType = h;
		status = h.getDefaultStatus();
		occupant = null;
	}
	/** Draws all hexes onto GameViewer v.
	 * @param v A GameViewer seeking to display the entire map (or at least the visible portion).
	 */
	public static void draw(Graphics2D g) {
		int i, j;
		Point3D vm = new Point3D();
		for(i = 0; i < radius; i++) {
			//if(x is within viewable range) {
			for(j = radius + i - 1; j >= 0; j--) {
				//if(y is within viewable range)
				vm = getMapPoint(i,j);
				board[i][j].hexType.draw(g, vm);
			}
			//}
		}
		for(i = radius; i < 2 * radius - 1; i++) {
			//if(x is within viewable range) {
			for(j = 2 * (radius - 1); j >= i - (radius - 1); j--) {
				//if(y is within viewable range)
				vm = getMapPoint(i,j);
				board[i][j].hexType.draw(g, vm);
			}
			//}
		}
	}
	/** Draws all the GameObjects in the game onto GameViewer v.
	 * These are drawn in order from south to north to enable the Z-order to
	 * be preserved.
	 * @param v The GameViewer seeking to display all of the GameObjects.
	 */
	public static void drawGameObject(GameViewer v) {
		int i, j;
		Point3D vm = new Point3D();
		//if(x is within viewable range) {
		for(j = 2 * (radius - 1); j > radius - 1; j--) {
			for(i = j - (radius - 1); i <= 2 * (radius - 1); i++) {
				//if(y is within viewable range)
				if(board[i][j].occupant != null)
					board[i][j].occupant.draw(v);
			}
			//}
		}
		//if(x is within viewable range) {
		for(j = radius - 1; j >= 0; j--) {
			for(i = 0; i < radius + j; i++) {
				//if(y is within viewable range)
				if(board[i][j].occupant != null)
					board[i][j].occupant.draw(v);
			}
			//}
		}
	}
	/** Gets the ground-center of the Hex at hex coordinate (x,y).
	 * @param x The x part of the hex coordinate.
	 * @param y The y part of the hex coordinate.
	 * @return The ground-center of the specified hex.
	 */
	public static Point3D getMapPoint(int x, int y) 	{
		if(radius == 0) // called from Mapper
			return HexM.getMapPoint(x,y);
		return (new Point3D(10 * sqrt3 * (-radius + x), 10 * (2 * y - radius - x + 1), 0));
	}
	/** Gets the Hex containing a game-space point, and alters the parameter
	 * to contain the hex coordinates, by storing the hex x in vr.x and the
	 * hex y in vr.y
	 * @param vr The game-space point to locate, and the storage space for the x and y.
	 * @return The Hex containing the game-space point.
	 */
	public static Hex getXY(Point3D vr) {
		vr.x = Math.round(vr.x/(10 * sqrt3) + radius);
		vr.y = Math.round((vr.y/10 + radius + vr.x - 1)/2);
		return getHex((int)vr.x, (int)vr.y);
	}
	/** Attempts to reserve this Hex for the caller.
	 * @return true if the Hex was reserved for the caller.
	 */
	public boolean reserve() {
		if((status & 2) == 2)
			return false;
		status |= 2;
		return true;
	}
	/** Unreserves this Hex.
	 * This should only be called by something which successfully called reserve().
	 */
	public void unreserve() {
		status -= status & 2;
	}
	/** Attempts to put the GameObject into this Hex.
	 * @param u The GameObject which is attempting to occupy the Hex.
	 * @return True if the GameObject was put into this Hex.
	 */
	public boolean enter(GameObject u) {
		if(occupant != null)
			return false;
		occupant = u;
		status |= 1;
		
		return true;
	}
	/** Removes the GameObject from the Hex, if it is the GameObject which was in the Hex.
	 * @param u The GameObject which is leaving the Hex.
	 */
	public void leave(GameObject u) {
		if(occupant != u)
			return;
		occupant = null;
		status -= status & 1;
	}
	/** Checks if the Hex is unoccupied.
	 * @return true if there is no GameObject in the Hex.
	 */
	public boolean isEmpty() {
		return ((status & 1) == 0);
	}
	/** Returns the GameObject which is in the Hex.
	 * @return the occupant, or null if the Hex is empty.
	 */
	public GameObject getOccupant() {
		return occupant;
	}
	/** Returns the Color to display on the minimap.
	 * @return A Color for use on the Minimap.
	 */
	public Color getMinimapColor() {
		try{
			if(occupant != null && Class.forName("netwar.game.Base").isInstance(occupant))
				return occupant.getMinimapColor();
		} catch(ClassNotFoundException cnfe) {
			System.err.println("Class netwar.game.Base not found. This class is absolutely necessary for Netwar.");
		}
		return hexType.getColor();
	}
	/** Returns the size of a rectangle just big enough to contain one Hex.
	 * This size is stored into a Point2D as x = width, y = height.
	 * @return the Point2D containing the size of the rectangle.
	 */
	public static Point2D getHexDimension() {
		netwar.utils.vectorgraphics.Transform t = netwar.gui.HexViewer.getHexViewer().getTransform();
		return new Point2D(Math.abs(t.getPoint2D(HexType.m_middleLeft).x * 2),
		Math.abs(t.getPoint2D(HexType.m_topLeft).y * 2));
	}
	public static int getRadius() { return radius;}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩一区二区三免费高清| 精品无人码麻豆乱码1区2区 | 欧美猛男gaygay网站| 亚洲精品久久久蜜桃| 色就色 综合激情| 亚洲一区二区欧美激情| 欧美喷潮久久久xxxxx| 久久精品国产色蜜蜜麻豆| 精品日韩99亚洲| 国产成人一区二区精品非洲| 中文字幕在线不卡| 在线一区二区观看| 日本vs亚洲vs韩国一区三区二区 | 日韩美女一区二区三区| 久久99久久久欧美国产| 国产欧美日韩麻豆91| 91丨九色porny丨蝌蚪| 亚洲大片精品永久免费| 欧美成人精品高清在线播放| 高清shemale亚洲人妖| 亚洲一级在线观看| 精品对白一区国产伦| aaa欧美日韩| 日韩精品电影一区亚洲| 中文子幕无线码一区tr| 欧美三电影在线| 国内精品伊人久久久久av影院| 国产农村妇女精品| 色爱区综合激月婷婷| 欧美特级限制片免费在线观看| 亚洲一区二区三区四区中文字幕| 欧美大片在线观看| 97aⅴ精品视频一二三区| 婷婷综合五月天| 国产精品久久久久婷婷二区次| 欧美日韩免费视频| 国产一区二区美女| 亚洲一区二区三区中文字幕在线| 精品免费一区二区三区| 91免费视频网| 国产自产v一区二区三区c| 亚洲三级在线播放| 欧美一区二区三级| 91年精品国产| 国产一区二区三区久久久| 亚洲精品免费播放| 国产清纯白嫩初高生在线观看91 | 中文字幕不卡在线观看| 欧美日韩一区中文字幕| 国产成人精品一区二 | 另类专区欧美蜜桃臀第一页| 亚洲欧美日韩一区二区三区在线观看| 日韩午夜在线播放| 色综合久久综合网欧美综合网| 精品亚洲免费视频| 亚洲线精品一区二区三区| 欧美tk丨vk视频| 欧洲精品视频在线观看| 国产寡妇亲子伦一区二区| 五月天丁香久久| 最新国产精品久久精品| 欧美精品一区在线观看| 6080国产精品一区二区| 日本韩国欧美一区| 风间由美一区二区三区在线观看 | 国产精品一级黄| 日韩av二区在线播放| 亚洲精品成人精品456| 国产视频一区二区在线观看| 日韩欧美在线123| 欧美日韩日日夜夜| 91极品视觉盛宴| 99久久伊人久久99| 成人黄色a**站在线观看| 激情欧美一区二区| 秋霞电影网一区二区| 一区二区三区四区激情| 1024成人网| 国产精品嫩草99a| 久久久精品2019中文字幕之3| 欧美成人伊人久久综合网| 欧美二区在线观看| 欧美日韩在线播| 欧美日韩亚洲丝袜制服| 欧美三级资源在线| 欧美在线观看视频在线| 欧美一a一片一级一片| 91免费小视频| 精品婷婷伊人一区三区三| 91福利在线播放| 在线观看成人小视频| 欧美调教femdomvk| 欧美日韩中文精品| 欧美日韩国产高清一区二区三区| 欧美三级三级三级| 欧美美女视频在线观看| 日韩一区二区三| 欧美r级在线观看| 国产亚洲精品超碰| 国产农村妇女精品| 亚洲情趣在线观看| 一区二区三区中文在线观看| 午夜精品福利久久久| 日韩精品电影在线| 国产在线精品一区在线观看麻豆| 精品写真视频在线观看| 成人性视频免费网站| 92精品国产成人观看免费| 91黄色免费网站| 6080午夜不卡| 久久精品一区四区| 综合久久给合久久狠狠狠97色 | 亚洲成av人片在线观看| 久久se精品一区精品二区| 国产精品1区2区| hitomi一区二区三区精品| 日本精品一区二区三区高清| 欧美一区二区三区人| 亚洲精品一区二区三区在线观看| 日本一区二区电影| 亚洲国产cao| 激情欧美一区二区三区在线观看| 99久久婷婷国产精品综合| 欧美视频在线一区二区三区| 精品动漫一区二区三区在线观看| 136国产福利精品导航| 日本欧美大码aⅴ在线播放| 国产一区二区不卡| 在线免费亚洲电影| 精品国产一区二区三区av性色| 亚洲欧洲成人精品av97| 日韩av网站免费在线| 99久久精品免费观看| 欧美一区二区在线视频| 国产精品网站在线观看| 天天色天天爱天天射综合| 国产91高潮流白浆在线麻豆| 91超碰这里只有精品国产| 国产精品污www在线观看| 日本中文一区二区三区| www.亚洲在线| 欧美一级日韩免费不卡| 亚洲视频每日更新| 国产二区国产一区在线观看| 91精品蜜臀在线一区尤物| 成人欧美一区二区三区黑人麻豆| 麻豆精品国产91久久久久久| 在线观看日韩高清av| 国产午夜亚洲精品理论片色戒| 天堂久久一区二区三区| 91欧美一区二区| 久久久无码精品亚洲日韩按摩| 午夜不卡在线视频| 91在线观看视频| 久久久久97国产精华液好用吗| 日韩黄色一级片| 在线观看亚洲专区| 国产精品成人免费| 国产精品自拍在线| 欧美一区二区三区影视| 亚洲国产成人av网| 一本一道波多野结衣一区二区| 中文字幕精品综合| 国产一区在线观看视频| 日韩欧美在线123| 日韩av中文在线观看| 欧美性受xxxx| 亚洲一级不卡视频| 91视频91自| 亚洲国产成人一区二区三区| 国产suv精品一区二区三区| 久久亚洲一级片| 韩国一区二区在线观看| 日韩一区二区三区三四区视频在线观看| 亚洲va国产va欧美va观看| 日本道色综合久久| 亚洲国产一区二区a毛片| 91黄色免费看| 亚洲色图色小说| 在线观看网站黄不卡| 一区二区三区精品在线| 欧美亚洲国产一区二区三区| 亚洲裸体xxx| 91久久精品日日躁夜夜躁欧美| 亚洲午夜一区二区| 欧美一区二区三区免费视频 | 激情国产一区二区 | 国产高清精品久久久久| 国产日韩精品一区二区三区在线| 国产精品自拍毛片| 欧美国产欧美综合| av在线不卡免费看| 一个色妞综合视频在线观看| 欧美日韩国产天堂| 美女视频网站久久| 欧美r级电影在线观看| 国产精品自拍av| 亚洲人被黑人高潮完整版| 欧美色偷偷大香| 蜜臀国产一区二区三区在线播放 |