public ABMGridScreenDelete() { InitializeComponent(); this.handler = new GridHandler(); this.AccessibleName = "Borrar"; this.titleTxt.Text = "Borrar Plano"; }
//initialize //loads empty that holds the entire field (all tiles and characters) public void Init() { if (!_initialized) { _uiRef = UIHolder.UIInstance; GameObject field = Resources.Load <GameObject>("GridObjects/BattleFieldHolder"); GameObject newfield = Instantiate(field, Vector3.zero, Quaternion.identity, null); _battlefield = newfield.GetComponent <WorldGridHandler>(); _battlefield.Init(); GridHandler.Init(); _initialized = true; SetUI(); } else { _battlefield.Init(); GridHandler.Init(); } ChangeGrid(); }
private void Awake() { S = this; _origin = transform.position; _obstacles = GameObject.FindGameObjectsWithTag("Obstacle"); CalculateObstacles(); }
/// <summary> /// Plays the turn. /// </summary> /// <returns>The turn.</returns> /// <param name="gridHandler">Grid handler.</param> /// <param name="totalTurns">Total turns.</param> /// <param name="opponentUsedCellID">Opponent used cell ID</param> public int PlayTurn(GridHandler gridHandler, int totalTurns, int opponentUsedCellID) { if (totalTurns < 3) { int range = Random.Range(0, gridHandler.emptyCellsIndexes.Count); this.lastUsedCellID = gridHandler.emptyCellsIndexes[range]; return(this.lastUsedCellID); } //defence int defendCellID = Defend(gridHandler, totalTurns, opponentUsedCellID); //if cell id == -1 then attack otherwise defend. if (defendCellID != -1) { this.lastUsedCellID = defendCellID; return(defendCellID); } int attackCellID = Attack(gridHandler); //attack if (attackCellID != -1) { this.lastUsedCellID = attackCellID; return(attackCellID); } //if this is returning then there is some error return(-1); }
public void GridHandlerLeftPosLessThanZero() { GridHandler grid = new GridHandler(); Vector2 left = grid.GetWorldCoordsOfCell(new Vector2(-1, 0)); Assert.IsTrue(left.x < 0 && left.y == 0, left.ToString()); }
private void Start() { gh = Camera.main.GetComponent <GridHandler>(); coords = transform.position; if (transform.eulerAngles.z >= 85 && transform.eulerAngles.z <= 95) { vertical = false; } else { vertical = true; } //find the keys if (vertical == true) { int yCode = (int)(coords.y + 0.5f + (gh.height / 2f)); int xCodeOne = (int)(coords.x + (gh.width / 2f)); int xCodeTwo = (int)(coords.x + 1f + (gh.width / 2f)); keyOne = xCodeOne.ToString() + "." + yCode.ToString(); keyTwo = xCodeTwo.ToString() + "." + yCode.ToString(); } else { int xCode = (int)(coords.x + 0.5f + (gh.width / 2f)); int yCodeOne = (int)(coords.y + (gh.height / 2f)); int yCodeTwo = (int)(coords.y + 1f + (gh.height / 2f)); keyOne = xCode.ToString() + "." + yCodeOne.ToString(); keyTwo = xCode.ToString() + "." + yCodeTwo.ToString(); } //print("Boundaries: " + keyOne + ", " + keyTwo); }
public void GridHandlerMultiply() { GridHandler grid = new GridHandler(150, 3); Vector2 pos = grid.GetWorldCoordsOfCell(new Vector2(1, 0)); Assert.IsTrue(pos.y == 0 && pos.x == (150 / 3), pos.ToString()); }
//Moves unit randomly to any space it can travel public override void Move() { _myMoves = GridHandler.WhereCanIMove(_gridPos, _myMovement); int randNum = UnityEngine.Random.Range(0, _currMovement); GridHandler.MoveEnemy(this, _myMoves[randNum]); }
public void GridHandlerStartPosIsZero() { GridHandler grid = new GridHandler(); Vector2 zero = grid.GetWorldCoordsOfCell(new Vector2(0, 0)); Assert.IsTrue(zero.x == 0 && zero.y == 0, zero.ToString()); }
public void GridHandlerTopPosLessThanZero() { GridHandler grid = new GridHandler(); Vector2 bottom = grid.GetWorldCoordsOfCell(new Vector2(0, -1)); Assert.IsTrue(bottom.x == 0 && bottom.y < 0, bottom.ToString()); }
// Use this for initialization void Start() { sources = GetComponents <AudioSource>(); colors = new Color[4]; colors[0] = new Color(1f, 0f, 0f); colors[1] = new Color(0f, 1f, 0f); colors[2] = new Color(0f, 0f, 1f); colors[3] = new Color(0f, 1f, 0.2f); deathParticle = (GameObject)Resources.Load("Prefabs/deathParticle"); prevPos = transform.position; light = (GameObject)Resources.Load("Prefabs/Lights/GunFlash"); gridParent = GameObject.Find("SceneSetup"); reloading = false; anim = GetComponentsInChildren <Animator>(); fireTime = 0; timer = 0; speed = 5; grid = (GridHandler)gridParent.GetComponentInChildren <GridHandler>(); int xGridLoc = (int)transform.position.x; int yGridLoc = (int)transform.position.y; gridPosition = new Vector2(xGridLoc, yGridLoc); transform.position = new Vector2(xGridLoc + .5f, yGridLoc + .5f); lastSpot = new Wall(true, true, true, true); grid.setTaken(xGridLoc, yGridLoc, lastSpot); moving = false; }
public void GridHandlerTopPosLargerThanZero() { GridHandler grid = new GridHandler(); Vector2 top = grid.GetWorldCoordsOfCell(new Vector2(0, 1)); Assert.IsTrue(top.x == 0 && top.y > 0, top.ToString()); }
public GridForm(Grid grid, Form parentForm, bool canEditGrid, User user) { InitializeComponent(); this.handler = new GridHandler(); this._user = user; this.parentForm = parentForm; this.ControlBox = false; this.grid = grid; this.pointArray = new List <System.Drawing.Point>(); this.graphic = this.gridPanel.CreateGraphics(); graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; gridPanel.AutoScroll = true; this.Hide(); SetupEnvironment(canEditGrid); wallBtn.MouseClick += new MouseEventHandler(changeOption); windowBtn.MouseClick += changeOption; doorBtn.MouseClick += changeOption; deleteWallBtn.MouseClick += changeOption; deleteWindowBtn.MouseClick += changeOption; deleteDoorBtn.MouseClick += changeOption; finishDesignBtn.MouseClick += changeOption; addDecorativeColumnBtn.MouseClick += changeOption; deleteDecorativeColumnBtn.MouseClick += changeOption; }
/*static void CreateEnemies(int numberOfTeams) * { * for (int v = 0; v < numberOfTeams; v++) * { * for (int i = 0; i < _enemiesToMake; i++) * { * Vector2 spawn = GridHandler.GetSpawn(); * Character newCharacter = new Character("Enemy", (i + 1 + (v *_enemiesToMake)).ToString(), v + 1, spawn); * GridHandler.PlaceEnemyOnBoard(newCharacter); * _spawnedCharacters.Add(newCharacter); * } * } * }*/ static void CreatePlayerTeam(List <DraggableCharacter> playerTeam) { for (int i = 0; i < playerTeam.Count; i++) { Vector2 spawn = GridHandler.GetSpawn(true); Character newCharacter; switch (playerTeam[i].GetClass) { case PlayerClasses.WARRIOR: newCharacter = new Warrior("Xavier", "0", TeamType.PLAYER, spawn); break; case PlayerClasses.MAGE: newCharacter = new Mage(); break; default: newCharacter = new Character(); break; } GridHandler.PlacePlayerOnBoard(newCharacter); _spawnedCharacters.Add(newCharacter); } }
void AbilityInteract(Ray mouse, RaycastHit point) { if (Physics.Raycast(mouse, out point)) { //if hits something //Debug.Log("hit something"); Collider objCollider = point.collider; if (objCollider.GetComponent <Tile>()) { Tile tile = objCollider.GetComponent <Tile>(); if (tile.IsTargetable && Input.GetMouseButtonDown(0)) { _abilityTarget = new Vector2(tile.GetXPosition, tile.GetYPosition); GridHandler.ShowReleventGrid(_abilityTarget, _selectedAbility.SplashRange, Color.red, Actions.ABILITY); _interactState = UIInteractions.ABILITYUSE; _battleCam.FocusPosition(tile.gameObject, CameraModes.ZOOMING); } } else if (objCollider.GetComponent <GridToken>()) { GridToken gt = objCollider.GetComponent <GridToken>(); if (gt.GetTile.IsTargetable && Input.GetMouseButtonDown(0)) { _abilityTarget = new Vector2(gt.GetTile.GetXPosition, gt.GetTile.GetYPosition); GridHandler.ShowReleventGrid(_abilityTarget, _selectedAbility.SplashRange, Color.red, Actions.ABILITY); _interactState = UIInteractions.ABILITYUSE; _battleCam.FocusPosition(gt.gameObject, CameraModes.ZOOMING); } } } }
void Start() { _grid = gameObject.GetComponent <GridHandler> (); PrefabHandler.Instance.GearDetails.text = _startingSpeed + " RPM"; Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(Camera.main, new Vector3(0, 0, 0)); //PrefabHandler.Instance.GearDetails.GetComponent<RectTransform> ().anchoredPosition = screenPoint-PrefabHandler.Instance.UI.GetComponent<RectTransform>().sizeDelta/2+new Vector2(80,18); }
void Start() { canvasHandler = FindObjectOfType <CanvasHandler>(); gridHandler = FindObjectOfType <GridHandler>(); enemy = FindObjectOfType <Enemy>(); StartCoroutine(SelfDestruct()); }
public void GridHandlerRightPosLessThanZero() { GridHandler grid = new GridHandler(); Vector2 right = grid.GetWorldCoordsOfCell(new Vector2(1, 0)); Assert.IsTrue(right.x > 0 && right.y == 0, right.ToString()); }
private void InitGameplayHandler() { gridHandler = FindObjectOfType <GridHandler>(); gridHandler.InitGridHandler(); gridArray = gridHandler.GetGridArray(); rowCount = gridArray.GetLength(0); columnCount = gridArray.GetLength(1); }
public GridTest() { this.GRID_HANDLER = new GridHandler(); this.CLIENT_HANDLER = new ClientHandler(); this.dataStorage = DataStorage.GetStorageInstance(); this.client = new Client(USERNAME_OK, PASSWORD_OK, NAME_OK, SURNAME_OK, ID_OK, PHONE_OK, ADDRESS_OK, DATE_OK, null); this.grid = new Grid(GRID_NAME_OK, client, HEIGHT, WIDTH); }
void InitiateAttack(Tile tile) { if (tile.IsTargetable && Input.GetMouseButtonDown(0) && tile.PersonOnMe != null) { _battleCam.CameraFullStop(); _timeRef.GetCurrentTurnCharacter.Attack(GridHandler.RetrieveCharacter(tile.GetXPosition, tile.GetYPosition)); } }
public MyAccountOwnedGrids(Client client) { InitializeComponent(); this.gridHandler = new GridHandler(); this.client = client; this.AccessibleName = "Mis Planos"; this.titleTxt.Text = "Mis Planos"; }
public MapLoader(TileHandler tileHandler, GridHandler gridHandler, TilesetLoader tilesetLoader, MapData mapData) { _tileHandler = tileHandler; _gridHandler = gridHandler; _tilesetLoader = tilesetLoader; _mapData = mapData; Reset(); }
public UIInformation(Character myChar, GridHandler map, List<List<Node>> options, int affectedFaction, AbilityAddition selectFunction) { this.myChar = myChar; this.map = map; this.options = options; this.affectedFaction = affectedFaction; this.selectFunction = selectFunction; }
void Start() { _grid = GameObject.Find("GameHandler").GetComponent <GridHandler> (); PrefabHandler.Instance.GearDetails.text = _speed + " RPM"; Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(Camera.main, new Vector3(_pos.x, _pos.y, _pos.z) / 2); PrefabHandler.Instance.GearDetails.GetComponent <RectTransform> ().anchoredPosition = screenPoint - PrefabHandler.Instance.UI.GetComponent <RectTransform>().sizeDelta / 2 + new Vector2(80, 18); }
//Tell the GridHandler where we want to move private void SendMove(int xMove, int zMove) { GridHandler.AttemptMovePlayer(coords[0], coords[1], xMove, zMove); facing = new int[2] { xMove, zMove }; transform.LookAt(new Vector3(transform.position.x + xMove, transform.position.y, transform.position.z + zMove)); }
public ABMGridScreenModify(User user) { InitializeComponent(); this._user = user; this.gridHandler = new GridHandler(); this.AccessibleName = "Modificar"; this.titleTxt.Text = "Modificar Plano"; }
public MainWindow() { InitializeComponent(); networkModel = GridHandler.LoadNetworkModel(networkModel, grid, myCanvas, MouseClickPoint); DrawLines(); }
void Awake() { th = GetComponent <TurnHandling>(); gh = GetComponent <GridHandler>(); curFloor = fg.floorGen(curFloorInfo); spawnedObjects = fg.populateTheFloor(curFloorInfo); th.CollectActors(); }
public void GridHandler_SetsDefaultValues_DefaultValues() { var gridHandler = new GridHandler(new CameraHandler()); Assert.AreEqual(16, gridHandler.TileSize); Assert.AreEqual(16, gridHandler.GridWidth); Assert.AreEqual(16, gridHandler.GridHeight); }
private void OnEnable() { gridHandler = transform.parent.gameObject.GetComponent <GridHandler>(); snappingTags = new HashSet <string>(); snappingTags.Add("NPCFigurine"); snappingTags.Add("PlayerFigurine"); }
public static void ExamplePartTwo(Character myChar, GridHandler map, int affectedFaction, List<Node> affectedNodes) { for (int i = 0; i < affectedNodes.Count; ++i) { Debug.Log("Attacking with Example at " + affectedNodes[i].X + ", " + affectedNodes[i].Y); if (affectedNodes[i].myCharacter != null && affectedFaction == affectedNodes[i].myCharacter.Faction) { affectedNodes[i].myCharacter.DamageCharacter(10, DamageType.Fire); } } }
public static void TakeDamageEffect(Character myChar, GridHandler map, int affectedFaction, List<Node> affectedNodes) { for (int i = 0; i < affectedNodes.Count; ++i) { if (affectedNodes[i].myCharacter != null && affectedFaction == affectedNodes[i].myCharacter.Faction) { affectedNodes[i].myCharacter.DamageCharacter(TakeDamageDamage,DamageType.Electric); } } UIInformationHandler.InformationStack.Clear(); myChar.canAct = false; }
public static void HealEffect(Character myChar, GridHandler map, int affectedFaction, List<Node> affectedNodes) { for (int i = 0; i < affectedNodes.Count; ++i) { if (affectedNodes[i].myCharacter != null && affectedFaction == affectedNodes[i].myCharacter.Faction) { affectedNodes[i].myCharacter.HealCharacter(HealDamage); } } UIInformationHandler.InformationStack.Clear(); myChar.canAct = false; }
/// <summary> /// Stomp Ability, hurts enemies within a 2 tile radius of the player /// </summary> /// <param name="myChar"></param> /// <param name="map"></param> public static void Stomp(Character myChar, GridHandler map) { //create a list of the possible moves, and the nodes they affect List<List<Node>> choices = new List<List<Node>>(); //Add a list of nodes to the previous list, representing a set of new affected nodes; choices.Add(new List<Node>()); //add all of the nodes within 2 Moves of the player choices[0] = myChar.MyLocation.FindPossibleMoves(-1, StompSplash); choices[0].Remove(myChar.MyLocation); UIInformationHandler.InformationStack.Push(new UIInformation(myChar, map, choices, 1, StompEffect)); }
public static void AxeThrowEffect(Character myChar, GridHandler map, int affectedFaction, List<Node> affectedNodes) { for (int i = 0; i < affectedNodes.Count; ++i) { if (affectedNodes[i].myCharacter != null && affectedFaction == affectedNodes[i].myCharacter.Faction) { myChar.DamageOtherCharacter(affectedNodes[i].myCharacter, AxeThrowDamage, DamageType.Physical); } } UIInformationHandler.InformationStack.Clear(); myChar.canAct = false; }
/// <summary> /// Example Ability Implementation. All ablities must be part of the static partial class Abilities. /// </summary> public static void Example(Character myChar, GridHandler map) { List<List<Node>> choices = new List<List<Node>>(); choices.Add(new List<Node>()); choices[0].Add(myChar.MyLocation); choices[0].Add(map.map[myChar.MyLocation.Y, myChar.MyLocation.X -1]); choices.Add(new List<Node>()); if(myChar.MyLocation.X + 1 < map.Width) choices[1].Add(map.map[myChar.MyLocation.Y, myChar.MyLocation.X + 1]); if (myChar.MyLocation.X + 2 < map.Width) choices[1].Add(map.map[myChar.MyLocation.Y, myChar.MyLocation.X + 2]); UIInformationHandler.InformationStack.Push(new UIInformation(myChar, map, choices, 1, ExamplePartTwo)); }
/// <summary> /// Heal Ability /// </summary> /// <param name="myChar"></param> /// <param name="map"></param> public static void Heal(Character myChar, GridHandler map) { //create a list of the possible moves, and the nodes they affect List<List<Node>> choices = new List<List<Node>>(); //Add a list of nodes to the previous list, representing a set of new affected nodes; choices.Add(new List<Node>()); //add all of the nodes within 2 Moves of the player foreach(Node tile in map.map) { if(tile.myCharacter != null && tile.myCharacter.Faction == myChar.Faction) { choices[0].Add(tile); } } UIInformationHandler.InformationStack.Push(new UIInformation(myChar, map, choices, myChar.Faction, HealEffect)); }
/// <summary> /// Life Wither /// </summary> /// <param name="myChar"></param> /// <param name="map"></param> public static void LongShot(Character myChar, GridHandler map) { //create a list of the possible moves, and the nodes they affect List<List<Node>> choices = new List<List<Node>>(); //add all of the nodes within 2 Moves of the player foreach(Node tile in map.map) { if(tile.myCharacter != null && tile.myCharacter.Faction != myChar.Faction) { //Add a list of nodes to the previous list, representing a set of new affected nodes; choices.Add(new List<Node>() { tile} ); } } //IMPORTANT //push this so that the UI can access your stuff <3 -Sean UIInformationHandler.InformationStack.Push(new UIInformation(myChar, map, choices, 1, LongShotEffect)); }
/// <summary> /// Any unit on the map /// </summary> /// <param name="map">The map the character is on</param> /// <param name="name">The characters name, for use in the lookup dictionary</param> public Character(GridHandler map, string name) { this.y = 0; this.x = 0; this.canAct = false; this.canMove = false; this.myLocation = null; this.map = map; this.myAbilities = null; this.name = name; this.myAbilities = null; this.health = 0; this.speed = 0; this.movement = MovementType.Ground; this.myConditions = null; this.faction = 0; this.characterList = null; this.canAct = false; this.traitNames = new List<string>(); }
/// <summary> /// Axe Throw /// </summary> /// <param name="myChar"></param> /// <param name="map"></param> public static void AxeThrow(Character myChar, GridHandler map) { //create a list of the possible moves, and the nodes they affect List<List<Node>> choices = new List<List<Node>>(); //Add a list of nodes to the previous list, representing a set of new affected nodes; choices.Add(new List<Node>()); //add all of the nodes within 2 Moves of the player List<Node> allSpace = myChar.MyLocation.FindPossibleMoves(-1, AxeThrowRange); foreach(Node tile in allSpace) { if(tile.myCharacter != null && tile.myCharacter.Faction != myChar.Faction) { List<Node> target = tile.FindPossibleMoves(-1, AxeThrowSplash); choices.Add(target); } } //push this so that the UI can access your stuff UIInformationHandler.InformationStack.Push(new UIInformation(myChar, map, choices, 1, AxeThrowEffect)); }
public void uGridManuInit() { FHelperHandler = new GridHandler(this.uGridManu); uGridManuInitColumn(); uGridManuBind(); uGridManuStyleInit(); uGridEventInit(); }
public void InitMap() { BackUI = new List<GameObject>(); AttackUI = new List<GameObject>(); HomeUI = new List<GameObject>(); MoveUI = new List<GameObject>(); Moves = new List<Node>(); PlanningUI = new List<GameObject>(); BackUI.AddRange(GameObject.FindGameObjectsWithTag("BackUI")); AttackUI.AddRange(GameObject.FindGameObjectsWithTag("AttackUI")); HomeUI.AddRange(GameObject.FindGameObjectsWithTag("HomeUI")); MoveUI.AddRange(GameObject.FindGameObjectsWithTag("MoveUI")); PlanningUI.AddRange(GameObject.FindGameObjectsWithTag("PlanningUI")); CharTraits = GameObject.Find("TraitsText").GetComponent<Text>(); Portrait = GameObject.Find("Portrait").GetComponent<Image>(); CharacterUI = new List<GameObject>(); gm = gameObject.GetComponent<GameManager>(); map = gm.map; Tiles = new GameObject[map.Height,map.Width]; StandbyButtonYPos = GameObject.Find("StandbyButton").GetComponent<RectTransform>().anchoredPosition.y; for (int y = 0; y < map.Height; y++) { for (int x = 0; x < map.Width; x++) { GameObject tempTile = Instantiate(Resources.Load("tile")) as GameObject; tempTile.transform.position = new Vector3(x - 3.0f, y - 4.5f, 0); tempTile.GetComponent<TileScript>().x = x; tempTile.GetComponent<TileScript>().y = y; TerrainHeight tileHeight = map.map[y, x].height; switch (tileHeight) { case TerrainHeight.Empty: tempTile.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("houseTile"); tempTile.GetComponent<TileScript>().baseColor = Color.white; break; case TerrainHeight.Ground: tempTile.GetComponent<TileScript>().baseColor = Color.white; break; case TerrainHeight.Wall: tempTile.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("wallTile"); tempTile.GetComponent<TileScript>().baseColor = Color.white; break; } Tiles[y, x] = tempTile; if (map.map[y, x].myCharacter != null) { GameObject character = Instantiate(Resources.Load("Character")) as GameObject; character.name = map.map[y, x].myCharacter.Name; character.GetComponent<CharacterSpriteScript>().moveTo(x, y); character.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("CharacterSprites/" + map.map[y, x].myCharacter.Name); if (map.map[y, x].myCharacter.Faction == 0) { character.GetComponent<CharacterSpriteScript>().X = x; character.GetComponent<CharacterSpriteScript>().Y = y; SpriteRenderer charSprite = character.transform.FindChild("CharacterOutline").GetComponent<SpriteRenderer>(); charSprite.color = Color.blue; charSprite.sprite = Resources.Load<Sprite>("CharacterOutlines/" + map.map[y, x].myCharacter.Name + "_OUTLINE"); } else { SpriteRenderer charSprite = character.transform.FindChild("CharacterOutline").GetComponent<SpriteRenderer>(); charSprite.color = Color.red; charSprite.sprite = Resources.Load<Sprite>("CharacterOutlines/" + map.map[y, x].myCharacter.Name + "_OUTLINE"); } CharacterUI.Add(character); } } } currentState = UIState.Default; UIUpdate(); messages = new Text[] { Message1.GetComponent<Text>(), Message2.GetComponent<Text>(), Message3.GetComponent<Text>(), Message4.GetComponent<Text>(), Message5.GetComponent<Text>(), Message6.GetComponent<Text>(), Message7.GetComponent<Text>(), Message8.GetComponent<Text>() }; }
/// <summary> /// Finds a path to get to point B from here. /// </summary> /// <param name="endPoint">The point to head to</param> /// <param name="map">The overall map</param> /// <param name="movementType">The movement type</param> /// <returns>The path from here to there.</returns> public List<Node> FindPathTo(Node endPoint, GridHandler map, MovementType movementType) { // Get all the nodes into a list. List<Node> allNodes = new List<Node>(map.map.Length); for (int y = 0; y < map.map.GetLength(0); ++y) { for (int x = 0; x < map.map.GetLength(1); ++x) { allNodes.Add(map.map[y, x]); map.map[y, x].gScore = int.MaxValue; map.map[y, x].fScore = int.MaxValue; } } // Create a dictionary we can use to trace the path to any steps we've taken. Dictionary<Node, Node> path = new Dictionary<Node, Node>(); // setup some default scoring. this.gScore = 0; this.fScore = (int)(new Vector2(endPoint.X, endPoint.Y) - new Vector2(this.X, this.Y)).magnitude; // Utilize the distance from point A to B as a heuristic. // List of nodes to evaluate List<Node> toEvaluate = new List<Node>(); toEvaluate.Add(this); // List of evaluated nodes. List<Node> evaluatedNodes = new List<Node>(); // If you are out of nodes to evaluate and haven't found a solution then there isn't one. while (toEvaluate.Count != 0) { // Get the node with the lowest fscore to search off of. Node current = toEvaluate[0]; int lowest = toEvaluate[0].fScore; for (int i = 0; i < toEvaluate.Count; ++i) { int temp; if((temp = toEvaluate[i].fScore) < lowest){ lowest = temp; current = toEvaluate[i]; } } // if it's the endpoint then we're done. if (current == endPoint) { // Reconstruct the path from the dictionary. List<Node> finalPath = new List<Node>(); Node prevNode = endPoint; while (path.ContainsKey(prevNode)) { finalPath.Insert(0, prevNode); prevNode = path[prevNode]; } return finalPath; } // We're looking at this node then, so remove it from the ones we have to evaluate. toEvaluate.Remove(current); evaluatedNodes.Add(current); // If any of these cases are true then you can't walk off of this node. Skip it. if (current.height == TerrainHeight.Empty || (current.height == TerrainHeight.Wall && movementType == MovementType.Ground) || (current.myCharacter != null && current != this)) { continue; } // Check all neighbors (only commenting one since they're otherwise identical) if (current.left != null && !evaluatedNodes.Contains(current.left)) { // Increase scores to count movement. int tempGScore = current.gScore + 1; int neighborIndex = allNodes.IndexOf(current.left); //If we haven't evaluated the side yet, then we need to look at it. if (!toEvaluate.Contains(current.left)) { // Add it to the list and remember how we got here. toEvaluate.Add(current.left); path.Add(current.left, current); current.left.gScore = tempGScore; current.left.fScore = tempGScore + (int)(new Vector2(endPoint.X, endPoint.Y) - new Vector2(current.left.X, current.left.Y)).magnitude; }// If we have, this way may still have a better score. else if (current.left.gScore < tempGScore) { if (path.ContainsKey(current.left)) // store the info. { path[current.left] = current; } else { path.Add(current.left, current); current.left.gScore = tempGScore; current.left.fScore = tempGScore + (int)(new Vector2(endPoint.X, endPoint.Y) - new Vector2(current.left.X, current.left.Y)).magnitude; } } } if (current.right != null && !evaluatedNodes.Contains(current.right)) { int tempGScore = current.gScore + 1; int neighborIndex = allNodes.IndexOf(current.right); if (!toEvaluate.Contains(current.right)) { toEvaluate.Add(current.right); path.Add(current.right, current); current.right.gScore = tempGScore; current.right.fScore = tempGScore + (int)(new Vector2(endPoint.X, endPoint.Y) - new Vector2(current.right.X, current.right.Y)).magnitude; } else if (current.right.gScore < tempGScore) { if (path.ContainsKey(current.right)) { path[current.right] = current; } else { path.Add(current.right, current); current.right.gScore = tempGScore; current.right.fScore = tempGScore + (int)(new Vector2(endPoint.X, endPoint.Y) - new Vector2(current.right.X, current.right.Y)).magnitude; } } } if (current.down != null && !evaluatedNodes.Contains(current.down)) { int tempGScore = current.gScore + 1; int neighborIndex = allNodes.IndexOf(current.down); if (!toEvaluate.Contains(current.down)) { toEvaluate.Add(current.down); path.Add(current.down, current); current.down.gScore = tempGScore; current.down.fScore = tempGScore + (int)(new Vector2(endPoint.X, endPoint.Y) - new Vector2(current.down.X, current.down.Y)).magnitude; } else if (current.down.gScore < tempGScore) { if (path.ContainsKey(current.down)) { path[current.down] = current; } else { path.Add(current.down, current); current.down.gScore = tempGScore; current.down.fScore = tempGScore + (int)(new Vector2(endPoint.X, endPoint.Y) - new Vector2(current.down.X, current.down.Y)).magnitude; } } } if (current.up != null && !evaluatedNodes.Contains(current.up)) { int tempGScore = current.gScore + 1; int neighborIndex = allNodes.IndexOf(current.up); if (!toEvaluate.Contains(current.up)) { toEvaluate.Add(current.up); path.Add(current.up, current); current.up.gScore = tempGScore; current.up.fScore = tempGScore + (int)(new Vector2(endPoint.X, endPoint.Y) - new Vector2(current.up.X, current.up.Y)).magnitude; } else if (current.up.gScore < tempGScore) { if (path.ContainsKey(current.up)) { path[current.up] = current; } else { path.Add(current.up, current); current.up.gScore = tempGScore; current.up.fScore = tempGScore + (int)(new Vector2(endPoint.X, endPoint.Y) - new Vector2(current.up.X, current.up.Y)).magnitude; } } } } // We didn't find a solution. Return null return null; }
// Use this for initialization void Start() { MessageLog.Initialize (); Toast.Initialize (toastTextPrefab); CharacterInfoList.Initialize(); map = new GridHandler(10, 10); //map.PrintTest(); //map.PrintNode(4, 4); for (int i = 0; i < 8; i++) { map.map[2, i].height = TerrainHeight.Wall; } map.map[3, 4].height = TerrainHeight.Empty; map.map[3, 6].height = TerrainHeight.Empty; map.map[4, 4].height = TerrainHeight.Empty; map.map[4, 5].height = TerrainHeight.Empty; map.map[4, 6].height = TerrainHeight.Empty; PaulBunyan = new Character(map, "PaulBunyan"); Wink = new Character (map, "Wink"); Technomancer = new Character (map, "Technomancer"); Nox = new Character (map, "Nox"); GreyDeath = new Character(map, "GreyDeath"); Swarm = new Character(map, "Swarm"); if (PaulBunyan.Create(3, 0, 0, Characters) == CHAR_INIT.CHAR_AT_LOC_ERROR) { } //if (PaulBunyan2.Create(4, 0, 0, Characters) == CHAR_INIT.CHAR_AT_LOC_ERROR) //{ // } Wink.Create (4, 0, 0, Characters); Technomancer.Create (5, 0, 0, Characters); GreyDeath.Create (3, 8, 1, Characters); Nox.Create (4, 8, 1, Characters); Swarm.Create (5, 8, 1, Characters); List<Character> heroes = new List<Character>(); List<Character> villains = new List<Character>(); heroes.Add(PaulBunyan); heroes.Add (Wink); heroes.Add (Technomancer); villains.Add(GreyDeath); villains.Add(Nox); villains.Add (Swarm); factions.Add(new Faction(heroes)); factions.Add(new Faction(villains)); possibleSpots = PaulBunyan.MyLocation.FindPossibleMoves(0, 4, null, null); path = PaulBunyan.MyLocation.FindPathTo(map.map[5, 6], map, MovementType.Ground); Debug.Log(PaulBunyan.Name); Debug.Log(PaulBunyan.Health); gameObject.GetComponent<UIManager>().InitMap(); TurnManager.Initialize(factions); foreach(Character character in Characters) { character.OnDamaged += new EventHandler(gameObject.GetComponent<UIManager>().ShowDamage); character.OnHealed += new EventHandler(gameObject.GetComponent<UIManager>().ShowHeal); character.OnKilled += new EventHandler(RemoveCharacter); } Debug.Log("Map in start: " + map); Toast.SendToast ("Game Start!"); }
void abilityClicked(Ability script, Character myChar, GridHandler map) { Debug.Log(script.Method.Name); script(myChar, map); History.Push(currentState); currentState = UIState.Planning; CleanMap(); selectedAbility = script; UIUpdate(); }