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

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

?? unit.java

?? 用java開發的一個實施策略游戲源碼 值得學習一下
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
/*
	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 java.awt.*;
import netwar.utils.Assert;

/** Abstract class which defines a mobile GameObject.
 * This provides default implementation of the following behaviors:
 * <BR> Guard mode in which the Unit scans for nearby enemies.
 * <BR> Move mode in which the Unit tries to reach a particular Hex.
 * <BR> Pursuit mode in which the Unit moves toward a particular GameObject,
 * up to a range less than the weapon range, and fires repeatedly if that
 * GameObject is a damagable object which is not part of the same team.
 * <BR> Receiving damage using the standard health/armor model.
 * <BR> Navigating obstacles using a simple alternate direction system.
 * @author Group N2 - Project Netwar
 * @author Daniel Grund
 */
public abstract class Unit extends GameObject {
	/** A value indicating the amount of damage still needed to destroy this Unit. */
	protected int health = maxHealth();
	/** A value indicating the number of frames to remain paralyzed. */
	protected int stun = 0;
	/** A code number indicating the direction that the Unit is facing */
	protected int f = 4;
	
	//Adjacent hex reservation data
	/** X part of the Hex coord reserved for this Unit to move into another Hex. */
	protected int resX;
	/** Y part of the Hex coord reserved for this Unit to move into another Hex. */
	protected int resY;
	/** The facing this Unit should have when moving into the reserved Hex. */
	protected int resF;
	/** True if the Unit has a Hex reserved to move into. */
	protected boolean reserved = false;
	//If traceMode = 0, use classic pathfinding intelligence.
	//If traceMode = 1, use Keep-Obstacles-On-Your-Right mode.
	//If traceMode = -1, use Keep-Obstacles-On-Your-Left mode.
	private int traceMode = 0;
	private boolean validSubPlan = false;
	private int subPlanDirection;
	private int subPlanBias;
	
	/** Sets the facing of the Unit when it is created */
	protected void param(int p) {
		f = p;
		resX = x;
		resY = y;
	}
	//Default setGoal()s for a mobile Unit.
	/** Sets the unit to Guard Mode */
	public void setGoal() {
		//Set to 0  (remain stationary)
		mode = 0;
                traceMode = 0;
	}
	/** Sets the unit to Move Mode
	 * @param gx The X part of the Hex coordinate to move to.
	 * @param gy The Y part of the Hex coordinate to move to.
	 */
	public void setGoal(int gx, int gy) {
		//Set to 1 (go to destination)
		mode = 1;
                traceMode = 0;
		goalX = gx;
		goalY = gy;
	}
	/** Sets the Unit to Pursuit Mode
	 * @param u The GameObject to approach/pursue and attack (if not an ally).
	 */
	public void setGoal(GameObject u) {
		//Set to 2 (pursue target)
		mode = 2;
                traceMode = 0;
		target = u;
		targetSSMDS = firstSSMDS.getTarget(this, target);
		goalX = u.x;
		goalY = u.y;
	}
	//Default update for a mobile unit.
	/** Called once per time-step to perform necessary processing.
	 * Provides default logic to determine what animation is in place,
	 * fire a weapon if possible, etc.
	 */
	protected void update() {
		if(isDead()) {
			animateDie();
			return;
		}
		if(stun > 0) {
			stun--;
			return;
		}
		
		//Firing logic.
		if(reload > 0) {
			reload--;
			aim();
		}else{
			if(aim())
			{
				if(targetSSMDS.getDistanceSquared() <= weaponRangeSquared()) {
					if(fire())
						reload = weaponDelay();
				}
			}
		}
			
		if(frame == 0) {	//AI decision frame.
			if(!reserved) {
				//Don't know where I'm going, so I'd better think
				think(); //separate function for subclasses to overload
			}
			//If I know where I'm going next, I'll go.
			if(reserved) //Reserved the next hex already, check if I can move.
			{
				if(resF == f) //facing toward the hex. Now just wait for the unit to move.
				{
					if(Hex.getHex(resX, resY).isEmpty()) {
						action = 3; frame = framesToMove();
					}else //Wait for the hex to be clear.
						action = 0;
				}else{ //need to rotate toward the destination.
					if((resF - f > 0 && resF - f < 3) || resF - f < -3){
						//rotate left
						action = 1; frame = framesToRotate();
					}else{
						//rotate right
						action = 2; frame = framesToRotate();
					}
				}
			}
		}
		switch(action)
		{
			case 1: //Turn left
				animateRotateLeft();
				frame--;
				if(frame == 0)
					f++;
				if(f == 6) f = 0;
			break;
			case 2: //Turn right
				animateRotateRight();
				frame--;
				if(frame == 0)
					f--;
				if(f == -1) f = 5;
			break;
			case 3: //Move forward
				animateMove();
				
				if(firstSSMDS != null){
					//Update SSMDSs for this unit. Note, that this is not simple because the things reorder themselves when updated.
					SelfSortingMutualDistanceSquared ssmds[] = new SelfSortingMutualDistanceSquared[GameObjects.getLength() - 1];
					if(ssmds.length > 0) {
						int i = 0;
						SelfSortingMutualDistanceSquared curr = firstSSMDS;
						for(; i < ssmds.length; i++)
						{
							ssmds[i] = curr;
							curr = curr.getNext(this);
						}
						for(i = 0; i < ssmds.length; i++)
						{
							ssmds[i].update();
						}
					}
				}
				
				frame--;
				if(frame == 0) {
					Hex.getHex(x,y).leave(this);
					switch(f)
					{
						case 0:	x++;	y++;	break;
						case 1:		y++;	break;
						case 2:	x--;		break;
						case 3:	x--;	y--;	break;
						case 4:		y--;	break;
						case 5:	x++;		break;
					}
					Hex.getHex(x,y).enter(this);
					reserved = false; //Remember: The hex I am in is still reserved for me.
					confirmSubPlan(goalX, goalY);
					if(mode == 1 && x == goalX && y == goalY)
						mode = 0;
					think(); //Try to decide on a new space to be in, so this one can be unreserved.
				}
			break;
			case 4: //Making
				animateMake();
				frame--;
			break;
			default:
				frame = 0;
		}
	}
	/** Returns the facing code for the 'best' direction to head.
	 * Assumes the Unit is going from its current location to (gx, gy)
	 * with no obstacles in between. Other code will adjust for obstacles.
	 * @param gx The x part of the destination hex coordinate.
	 * @param gy The y part of the destination hex coordinate.
	 * @return The idealized facing code.
	 */
	protected int bestDirection(int gx, int gy){
		int dxy;
		if(validSubPlan)
			return subPlanDirection;
		gx -= x;
		gy -= y;
		dxy = gx - gy;
		if(gx == 0) {//Goal is vertically aligned.
			if(gy == 0) { //Already at goal.
				subPlanDirection = f;
				subPlanBias = 1;
			}else if(gy < 0) { //Goal is south (facing 4)
				subPlanDirection = 4;
				subPlanBias = 1;
			}else{ //Goal is north (facing 1)
				subPlanDirection = 1;
				subPlanBias = 1;
			}
		}else if(gx > 0) {//Goal is somewhere to the east.
			if(gy == 0) { //Goal is south-east (facing 5)
				subPlanDirection = 5;
				subPlanBias = 1;
			}else if(gy < 0) { //Goal is between facings 4 and 5
				if(gx > -1 * gy) { //Goal is closer to facing 5
					subPlanDirection = 5;
					subPlanBias = -1;
				}else{
					subPlanDirection = 4;
					subPlanBias = 1;
				}
			}else{ //Goal is between facings 5 and 1. First compare against facing 0.
				if(dxy == 0) { //Goal is north-east (facing 0)
					subPlanDirection = 0;
					subPlanBias = 1;
				}else if(dxy < 0) { //Goal is between facings 0 and 1
					if(gy > 2 * gx) { //Goal is closer to facing 1
						subPlanDirection = 1;
						subPlanBias = -1;
					}else{
						subPlanDirection = 0;
						subPlanBias = 1;
					}
				}else{ //Goal is between facings 5 and 0
					if(gx > 2 * gy) { //Goal is closer to facing 5
						subPlanDirection = 5;
						subPlanBias = 1;
					}else{
						subPlanDirection = 0;
						subPlanBias = -1;
					}
				}
			}
		}else{ //Goal is somewhere to the west.
			if(gy == 0) { //Goal is north-west (facing 2)
				subPlanDirection = 2;
				subPlanBias = 1;
			}else if(gy > 0) { //Goal is between facings 1 and 2
				if(gy > -1 * gx) { //Goal is closer to facing 1
					subPlanDirection = 1;
					subPlanBias = 1;
				}else{
					subPlanDirection = 2;
					subPlanBias = -1;
				}
			}else{ //Goal is between facings 2 and 4. First compare against facing 3.
				if(dxy == 0) { //Goal is south-west (facing 3)
					subPlanDirection = 3;
					subPlanBias = 1;
				}else if(dxy > 0) { //Goal is between facings 3 and 4
					if(gy < 2 * gx) { //Goal is closer to facing 4
						subPlanDirection = 4;
						subPlanBias = -1;
					}else{
						subPlanDirection = 3;
						subPlanBias = 1;
					}
				}else{ //Goal is between facings 2 and 3
					if(gx < 2 * gy) { //Goal is closer to facing 2
						subPlanDirection = 2;
						subPlanBias = 1;
					}else{
						subPlanDirection = 3;
						subPlanBias = -1;
					}
				}
			}
		}
		validSubPlan = true;
		return subPlanDirection;
	}
	/** Checks to make sure that the idealized direction to get to the destination is still good.
	 * If the previously calculated best direction would no longer cause the Unit to get
	 * closer to its destination, a flag is set to calculate a new direction the next time
	 * the direction is checked.
	 * @param gx The (updated) x part of the goal hex coordinate.
	 * @param gy The (updated) y part of the goal hex coordinate.
	 */
	protected void confirmSubPlan(int gx, int gy) {
		//Used when either the goal changes, or the unit moves.
		//Makes sure the current subPlan direction still makes sense.
		//If not, invalidate it so that it will be recalculated.
		int dxy;
		gx -= x;
		gy -= y;
		dxy = gx - gy;
		switch(subPlanDirection) {
			case 0:
				if(gx <= 0 || gy <= 0) validSubPlan = false;
			break;
			case 1:
				if(gy <= 0 || dxy >= 0) validSubPlan = false;
			break;
			case 2:
				if(dxy >= 0 || gx >= 0) validSubPlan = false;
			break;
			case 3:
				if(gx >= 0 || gy >= 0) validSubPlan = false;
			break;
			case 4:
				if(gy >= 0 || dxy <= 0) validSubPlan = false;
			break;
			case 5:
				if(dxy <= 0 || gx <= 0) validSubPlan = false;
			break;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一区二区三区在线看| 色婷婷精品久久二区二区蜜臂av| 中文字幕亚洲视频| 日本一区二区三区电影| www国产成人免费观看视频 深夜成人网| 欧美主播一区二区三区美女| 91理论电影在线观看| 91色视频在线| 在线亚洲免费视频| 91高清视频免费看| 欧美网站一区二区| 欧美日韩一级视频| 欧美日本一区二区| 欧美一区二区视频在线观看2020| 5月丁香婷婷综合| 日韩一区二区三区视频在线观看| 日韩欧美一级二级三级久久久| 69p69国产精品| 欧美电影免费观看高清完整版在 | 亚洲精品写真福利| 亚洲欧美在线另类| 一区二区在线观看免费| 婷婷激情综合网| 麻豆久久久久久| 国产一二三精品| 91香蕉视频污在线| 精品处破学生在线二十三| 日韩欧美一卡二卡| 日本一区二区三区dvd视频在线| 中文字幕亚洲精品在线观看| 亚洲一二三四久久| 精品一区二区三区不卡| 成人激情午夜影院| 欧美日韩精品欧美日韩精品一| 日韩三级中文字幕| 中文字幕av一区二区三区免费看| 一区二区三区欧美久久| 蜜臀99久久精品久久久久久软件| 国产精品中文字幕日韩精品| 一本到一区二区三区| 日韩写真欧美这视频| 亚洲欧洲日韩综合一区二区| 午夜视频在线观看一区二区| 国产精品白丝av| 欧美在线视频你懂得| 精品国产123| 1区2区3区国产精品| 麻豆精品在线看| 91香蕉视频黄| 久久久久久免费网| 五月婷婷激情综合网| av一区二区三区四区| 日韩美女一区二区三区| 亚洲主播在线播放| 成人午夜精品在线| 日韩你懂的在线观看| 亚洲高清视频中文字幕| 国产精品一区二区久久精品爱涩| 久久久久久久久97黄色工厂| 午夜欧美在线一二页| 99麻豆久久久国产精品免费| 欧美精品一区二区久久婷婷| 亚洲国产sm捆绑调教视频| 丁香婷婷综合激情五月色| 日韩三区在线观看| 偷拍与自拍一区| 日本乱码高清不卡字幕| 成人免费视频在线观看| 成人国产视频在线观看| 26uuu国产日韩综合| 麻豆精品久久久| 欧美日韩美少妇| 艳妇臀荡乳欲伦亚洲一区| 91一区二区三区在线播放| 欧美韩国一区二区| 国产精品12区| 久久精品一区八戒影视| 国产一区二区日韩精品| 久久老女人爱爱| 国模一区二区三区白浆| 久久色中文字幕| 狠狠色丁香久久婷婷综| 2021国产精品久久精品| 国产毛片精品国产一区二区三区| 精品蜜桃在线看| 国产精品综合网| 久久欧美一区二区| 豆国产96在线|亚洲| 国产精品福利一区二区| 97精品国产露脸对白| 日韩伦理av电影| 欧洲精品一区二区三区在线观看| 亚洲午夜激情网站| 欧美性视频一区二区三区| 午夜精品爽啪视频| 56国语精品自产拍在线观看| 精品在线免费观看| 久久精品亚洲精品国产欧美| 欧美军同video69gay| 麻豆精品一区二区av白丝在线| 日韩欧美中文一区二区| 国产激情精品久久久第一区二区 | 成人一道本在线| 一区在线观看免费| 欧美三级日韩三级| 美女视频网站久久| 国产精品你懂的在线欣赏| 色综合久久中文综合久久97 | 欧美日韩一区二区欧美激情| 免费成人深夜小野草| 欧美激情一区二区三区不卡 | 色吧成人激情小说| 五月天亚洲婷婷| 精品国产乱码久久| 色综合天天天天做夜夜夜夜做| 亚洲风情在线资源站| 久久综合视频网| 97久久久精品综合88久久| 午夜精品久久久久久久99樱桃| 欧美mv日韩mv国产网站app| 97精品久久久午夜一区二区三区| 天堂在线一区二区| 欧美激情一区不卡| 4438x成人网最大色成网站| 成人av资源在线| 日本午夜精品视频在线观看| 日本va欧美va精品发布| 国产精品午夜春色av| 欧美一区国产二区| 色综合久久中文字幕综合网 | 26uuu精品一区二区三区四区在线| 99久久精品国产网站| 黑人巨大精品欧美一区| 亚洲一区二区三区美女| 中国色在线观看另类| 欧美成人伊人久久综合网| 在线视频国内一区二区| 国产a久久麻豆| 日本亚洲三级在线| 伊人婷婷欧美激情| 国产精品女上位| 国产婷婷色一区二区三区| 日韩亚洲欧美综合| 欧美在线色视频| 色婷婷国产精品综合在线观看| 成人深夜视频在线观看| 国产精品影视网| 麻豆高清免费国产一区| 香蕉久久一区二区不卡无毒影院| 中文字幕亚洲欧美在线不卡| 亚洲国产精品成人综合色在线婷婷| 欧美成人综合网站| 日韩欧美一区二区三区在线| 欧美三级日本三级少妇99| 91丝袜国产在线播放| 丁香六月久久综合狠狠色| 国产麻豆精品视频| 国产一区二区三区四| 国产乱子轮精品视频| 国内偷窥港台综合视频在线播放| 日韩av二区在线播放| 男女男精品网站| 蜜臀av国产精品久久久久| 麻豆成人久久精品二区三区小说| 91麻豆swag| 91久色porny | 奇米影视7777精品一区二区| 午夜精品久久久久久| 日韩电影在线免费看| 蜜桃久久精品一区二区| 黄网站免费久久| 国产丶欧美丶日本不卡视频| 成人免费不卡视频| 91在线精品秘密一区二区| 色一情一乱一乱一91av| 欧美日韩久久一区| 日韩免费观看2025年上映的电影 | 久久久国产一区二区三区四区小说 | 久久精品网站免费观看| 久久伊人中文字幕| 久久蜜桃av一区二区天堂| 国产精品午夜久久| 夜夜嗨av一区二区三区四季av| 性做久久久久久久久| 久久se精品一区精品二区| 岛国一区二区在线观看| 色婷婷国产精品久久包臀| 日韩一区二区在线看| 国产欧美视频一区二区| 一区二区成人在线| 韩国视频一区二区| 99久久免费精品| 91精品一区二区三区在线观看| 久久久99精品久久| 亚洲永久免费视频| 久99久精品视频免费观看| 91玉足脚交白嫩脚丫在线播放| 日韩天堂在线观看| 亚洲人成在线播放网站岛国| 美女国产一区二区|