void CursorInspectCell() { // Mouse function // Show information on a highlighted cell or unit in a UI window Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) // Find a cell or unit from mouse over { CellClass cell = GridClass.instance.GetCellFromTransform(hit.transform); if (cell != null) { string uiText = ""; if (cell.Occupied == true) { UnitClass unit = UnitManager.instance.FindUnitFromCell(cell); if (unit == null) { uiText = "Fallen warrior"; } else { uiText = InspectUnitText(uiText, unit); } } else { uiText = cell.Name; } // Display info in UI window UIManager.instance.SetInspectorText(uiText); } } }
// TODO: public UnitClass FindUnitFromCell(CellClass cell) { UnitClass unit = units.Find((UnitClass u) => u.Cell == cell); // UnitClass unit = Controller.instance.units.Find( (UnitClass u) => u.Cell == cell ); return(unit); }
public void CreateGridFunction() { GameObject referenceTile = GameObject.Instantiate(Resources.Load <GameObject>("Grid")); GameObject referenceCell = GameObject.Instantiate(Resources.Load <GameObject>("Cell")); for (int r = 0; r < row; r++) { for (int c = 0; c < col; c++) { int rand = Random.Range(0, 2); GameObject tile = GameObject.Instantiate(referenceTile, transform); GameObject cell = GameObject.Instantiate(referenceCell, transform); CellClass cellClass = cell.GetComponent <CellClass>(); GameManager.Instance.cellGrid.Add(cellClass); GameManager.Instance.tileGrid.Add(tile); cellClass.InitializeCell(r, c, row, col); float posX = r * tileSize; float posY = c * -tileSize; tile.transform.position = new Vector3(posX, posY, 0); cell.transform.position = new Vector3(posX, posY, -1); } } float gridW = col * tileSize; float gridH = row * tileSize; transform.position = -new Vector2(gridW / 2 + tileSize / 2, -gridH / 2 - tileSize / 2); SetCellNeighbours(); Destroy(referenceCell); Destroy(referenceTile); }
/// <summary> /// 거리 가져오기. /// </summary> /// <param name="nodeA"></param> /// <param name="nodeB"></param> /// <returns></returns> private int GetDistance(CellClass nodeA, CellClass nodeB) { int distX = Mathf.Abs(nodeA.GetCellX() - nodeB.GetCellX()); int distY = Mathf.Abs(nodeA.GetCellY() - nodeB.GetCellY()); return(10 * distX + 10 * distY); }
/// <summary>Used as a predicate by List.Sort(), this method compares the distance of cells A and B </summary> static int SortByDistance(CellClass cellA, CellClass cellB) { int a = cellA.Distance; int b = cellB.Distance; return(a.CompareTo(b)); }
/// <summary> /// 타워 짓는 함수. /// </summary> /// <param name="cell"></param> /// <param name="cellData"></param> /// <returns></returns> public virtual bool Build(CellClass cell, string cellData) { transform.localPosition = Vector3.zero; mOriginScale = Vector3.one * 2.0f; mObjectPool = GameManager.Instance.GetObjectPool(); if (mObjectPool == null) { Debug.Log("Failed Get Object Pool"); return(false); } mTowerData = null; if (!mObjectPool.TowerDataDictionary.ContainsKey(cellData)) { Debug.Log("Failed Find TowerData in TowerDataDictionary"); return(false); } mTowerData = mObjectPool.TowerDataDictionary[cellData]; mPrice = mTowerData.Price; mTowerType = mTowerData.TOWERTYPE; cell.GetMap().SetMapData(cell.GetCellX(), cell.GetCellY(), mTowerData.Towerkey); StopCoroutine(ApperanceAnim()); StartCoroutine(ApperanceAnim()); return(true); }
private void ProcessNote(CellClass targetCell, CellClass sourceCell) { if (sourceCell.CellState == CellStateEnum.Answer) // Is the cell state Answer? { targetCell.Notes[sourceCell.Answer - 1].State = false; // Yes, then turn off the note. } }
public void TestGetCellFromIndexMethod() { CellClass cell = this.dataBase.GetCellFromIndex("B1"); Assert.AreEqual(0, cell.GetRowIndexValue()); Assert.AreEqual(1, cell.GetColumnIndexValue()); }
/// <summary> /// 타워 파괴 함수. /// </summary> /// <param name="cell"></param> public virtual void DestroyTower(CellClass cell) { cell.GetMap().SetMapData(cell.GetCellX(), cell.GetCellY(), null); cell.GetMap().RemoveTower(this); GameManager.Instance.GetPlayerInfo().Gold += Mathf.RoundToInt(mPrice * 0.5f); StartCoroutine(DestoryCoroutine()); }
private void CheckNotes(CellClass cell, Int32 index) { // If the cell state is Notes and the specified note state is set if ((cell.CellState == CellStateEnum.Notes) && (cell.Notes[index].State)) { cell.Notes[index].State = false; // Clear the note state } }
private void GenerateGrid() { List <Int32>[] available = InitializeArray(); // Initialize the list Int32 index = 0; // Set the index pointer to zero do { if (available[index].Count > 0) // If more number available { Int32 i = RandomClass.GetRandomInt(available[index].Count); // Get a random number CellClass item = new CellClass(index, available[index][i]); // Create a new if (Conflicts(item)) // Any conflicts with existing cells? { available[index].RemoveAt(i); // Yes, remove it from the available list item = null; // Clear the CellClass pointer } else { // No conflicts _cells[index] = item; // Save the CellClass to the array item = null; // Clear the CellClass pointer available[index].RemoveAt(i); // Remove it from the available list index++; // Increment the index pointer } } else { // No more number available available[index] = InitArray(); // Re-initialize the available list index--; // To back one spot _cells[index] = null; // Clear the array pointer } } while (index < 81); // Keep looping until there are no more cells to process }
/// <summary> /// 버프 타워 파괴 함수. /// </summary> /// <param name="cell"></param> public override void DestroyTower(CellClass cell) { mTargetTowers = GetTargetTowers(mTargetPositions); for (int i = 0; i < mTargetTowers.Length; i++) { switch (mTowerData.BUFFTYPE) { case BuffType.Damage: mTargetTowers[i].DownGrade(0.0f, mIBuffAmount, 0.0f); break; case BuffType.AttackSpeed: mTargetTowers[i].DownGrade(0.0f, 0, mBuffAmount); break; case BuffType.AttackRange: mTargetTowers[i].DownGrade(mBuffAmount, 0, 0.0f); break; default: continue; } } for (int i = 0; i < mEffectObjects.Count; i++) { mObjectPool.HideTowerEffect(mTowerData.BUFFTYPE, mEffectObjects[i]); } base.DestroyTower(cell); }
/// <summary> /// 주변 이웃 Cell가져오기. /// </summary> /// <param name="node"></param> /// <returns></returns> public List <CellClass> GetNeighbours(CellClass node) { List <CellClass> neighbours = new List <CellClass>(); // Left if (node.GetCellX() - 1 >= 0) { neighbours.Add(mMap[node.GetCellX() - 1, node.GetCellY()]); } // Right if (node.GetCellX() + 1 < mMapSizeX) { neighbours.Add(mMap[node.GetCellX() + 1, node.GetCellY()]); } // Up if (node.GetCellY() - 1 >= 0) { neighbours.Add(mMap[node.GetCellX(), node.GetCellY() - 1]); } // Down if (node.GetCellY() + 1 < mMapSizeY) { neighbours.Add(mMap[node.GetCellX(), node.GetCellY() + 1]); } return(neighbours); }
/// <summary> /// 버프 타워 초기화 함수. /// </summary> /// <param name="cellData"></param> /// <returns></returns> public override bool Initialize(string cellData) { if (!base.Initialize(cellData)) { return(false); } CellClass currentCell = GetComponentInParent <CellClass>(); if (currentCell == null) { Debug.Log("Failed to Get current Cell"); return(false); } mCurrentCellX = currentCell.GetCellX(); mCurrentCellY = currentCell.GetCellY(); mMapSizeX = currentCell.GetMap().GetMapSizeX(); mMapSizeY = currentCell.GetMap().GetMapSizeY(); mObjectPool = GameManager.Instance.GetObjectPool(); mEffectObjects = new List <GameObject>(); mTargetPositions = GetTargetPositions(); return(true); }
void HighLightCell(CellClass cell) { //colour and highlight the cell cursor.SetActive(true); cursor.transform.position = cell.CellGO.transform.position; currentCell = cell; GridClass.instance.ColourCell(cell, Color.yellow); }
public void TestGetCellMethod() { // normal case.// CellClass cell = this.dataBase.GetCell(50, 50); Assert.AreEqual(49, cell.GetRowIndexValue()); Assert.AreEqual(49, cell.GetColumnIndexValue()); }
private CellClass[,] TransferGameToGrid() { CellClass[,] cells = new CellClass[9, 9]; // Initialize a new cell array foreach (CellClass item in _cells) // Loop the cell list { cells[item.Col, item.Row] = item; // Save the pointer } return(cells); // Return the cell array }
// Show valid attack target cells and attack units IEnumerator CursorFindAttack() { // Mouse function if (UnitManager.instance.unitHasAttacked) { yield break; // If the unit has attacked, exit } if (waitForUI == true) { yield break; } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; InspectorActionText(); // Sets info about current unit TODO: WHY THE F**K IS THIS HERE? if (Input.GetMouseButtonDown(0) && Physics.Raycast(ray, out hit)) { CellClass cell = GridClass.instance.GetCellFromTransform(hit.transform); UnitClass targetUnit; if (cell != null && cells.Contains(cell) && cell != currentUnit.Cell && cell.Occupied == true) { targetUnit = UnitManager.instance.units.Find((UnitClass u) => u.Cell == cell); } else { yield break; } // if ( cell != null && cells.Contains(cell) && cell != currentUnit.Cell // && cell.Occupied == true && targetUnit !=null && targetUnit.playerSide != currentUnit.playerSide // && targetUnit.CurrentHealth >= 0 ) if (targetUnit != null && targetUnit.playerSide != currentUnit.playerSide && targetUnit.CurrentHealth >= 0) { if (cell != currentCell) // select cell { FindUnitAttack(); HighLightCell(cell); currentCell = cell; } else // attack cell //TODO: Add attack animation or something { Debug.Log("Hit! " + currentUnit.Name + " has attacked " + targetUnit.Name); ClearLastCell(); ClearPath(); UnitManager.instance.unitHasAttacked = true; StartCoroutine(AttackAction(targetUnit)); } } } yield return(null); }
// Returns a cell with a given transform. Used to find cells by raycast from player input public CellClass GetCellFromTransform(Transform cellTransform) { CellClass cell = FindCellInArray((CellClass c ) => c.CellGO.transform.GetChild(0).transform == cellTransform); if (cell != null) { return(cell); } return(null); }
// This is where players place their units at the start of the battle // TODO: Rework this stupid placement system. It is janky proof of concept code void SetPlacementCells() { foreach (Vector2 position in placementCells) { CellClass cell = FindCellInArray((CellClass c) => c.GridPosition == position); if (cell != null) { placingList.Add(cell); } } }
public SudokuArena() { Model = new CellClass[GridSize, GridSize]; for (var i = 0; i < GridSize; i++) { for (var j = 0; j < GridSize; j++) { Model[i, j] = new CellClass(); } } }
private void AddCell(CellClass cell) { if (cell != null) // Is input a valid object? { // Yes. CellList.Add(cell); // Add the cell to the main list. _regionList[cell.Region].Add(cell); // Add the cell the corresponding region list. } else { throw new Exception("Cell cannot be null."); // TODO: Maybe add this to the event log instead? } }
/// <summary> /// 길찾기 코루틴 /// </summary> /// <param name="start"></param> /// <param name="goal"></param> /// <returns></returns> private IEnumerator FindPath(CellClass start, CellClass goal) { CellClass[] wayPoints = new CellClass[0]; mPathSuccess = false; if (start.GetWalkable() && goal.GetWalkable()) { Heap <CellClass> openSet = new Heap <CellClass>(mMap.GetMaxSize()); HashSet <CellClass> closeSet = new HashSet <CellClass>(); openSet.Add(start); while (openSet.Count > 0) { CellClass currentNode = openSet.RemoveFirst(); closeSet.Add(currentNode); if (currentNode == goal) { mPathSuccess = true; break; } foreach (CellClass neighbour in mMap.GetNeighbours(currentNode)) { if (!neighbour.GetWalkable() || closeSet.Contains(neighbour)) { continue; } int newMovementCostToNeighbour = currentNode.GetGCost() + GetDistance(currentNode, neighbour); if (newMovementCostToNeighbour < neighbour.GetGCost() || !openSet.Contains(neighbour)) { neighbour.SetGCost(newMovementCostToNeighbour); neighbour.SetHCost(GetDistance(neighbour, goal)); neighbour.SetParent(currentNode); if (!openSet.Contains(neighbour)) { openSet.Add(neighbour); } } } } } yield return(null); if (mPathSuccess) { wayPoints = RetracePath(start, goal); OnPathFound(wayPoints, true); } }
/// <summary> /// Valid attack cells /// </summary> /// <returns>List of cells in attack range</returns> public static List <CellClass> FindPath(CellClass startCell, GridClass grid, int attackRange, UnitClass currentUnit) { List <CellClass> openList; List <CellClass> closedList; openList = new List <CellClass>(); closedList = new List <CellClass>(); Debug.Log("hello?"); startCell.Distance = 0; startCell.ParentCell = null; CellClass curCell = startCell; openList.Add(curCell); while (curCell.Distance <= attackRange) { closedList.Add(curCell); openList.Remove(curCell); foreach (CellClass cell in curCell.adjacentCells) { cell.Distance = curCell.Distance + cell.Cost; if (cell.Cost != 0 && cell.Distance <= attackRange && !openList.Contains(cell) && !closedList.Contains(cell)) { // UnitClass unit = UnitManager.instance.units.Find( (UnitClass u) => u.Cell == cell); // // if ( unit != null){ // if ( unit.playerSide != currentUnit.playerSide ) { // cell.ParentCell = curCell; // openList.Add( cell ); // } // } // else { cell.ParentCell = curCell; openList.Add(cell); // } } } if (openList.Count == 0) { break; } openList.Sort(SortByDistance); curCell = openList[0]; } Debug.Log(closedList.Count); closedList.TrimExcess(); return(closedList); }
public void TestGetCellEdgeCaseMethod() { CellClass cell = this.dataBase.GetCell(102, 121); Assert.IsNull(cell); cell = this.dataBase.GetCell(0, 0); Assert.IsNull(cell); cell = this.dataBase.GetCell(100, 100); Assert.AreEqual(99, cell.GetRowIndexValue()); Assert.AreEqual(99, cell.GetColumnIndexValue()); }
///<summary> Find the path between a pathfinder origin cell and a valid target cell </summary> public static List <CellClass> TracePath(CellClass startCell, CellClass endCell) { List <CellClass> pathList = new List <CellClass>(); CellClass curCell = startCell; while (curCell != endCell || curCell.ParentCell != null) // Null clause is superfluous infinite loop protection { pathList.Add(curCell); curCell = curCell.ParentCell; } pathList.Reverse(); return(pathList); }
/// <summary> /// 선택된 Cell을 설정. /// </summary> /// <param name="cell"></param> public void SetSelectedCell(CellClass cell) { if (mSelectedCell != null) { mSelectedCell.ReleaseSelected(); mSelectedCell.HideBuffArea(); } mSelectedCell = cell; if (mSelectedCell != null) { mSelectedCell.ShowBuffArea(); } }
private bool Conflicts(CellClass check) { // If the answer already exists in the column, row, or region, return true. foreach (CellClass item in _cells) // Loop through the list of cells { if (item != null) // If it's not null, check it { if ((item.IsSameRow(check) || item.IsSameCol(check) || item.IsSameRegion(check)) && (item.Answer == check.Answer)) { return(true); // Return true if the answer already exists along the column, row, or region } } } return(false); // Return false if the answer does not exist }
private void ProcessNotes(CellClass cell, Int32 index) { switch (cell.CellState) // What is the cell state? { case CellStateEnum.Notes: // Already showing notes? cell.Notes[index].State = !cell.Notes[index].State; // Yes, then toggle the state of the specified note break; case CellStateEnum.Blank: // Blank? cell.ClearNotes(); // Clear all notes cell.CellState = CellStateEnum.Notes; // Set the state to notes cell.Notes[index].State = !cell.Notes[index].State; // Toggle the state of the specified note break; } }
/// <summary> /// Find valid unit move cells /// </summary> /// <returns>List of cells in move range</returns> /// <param name="moveRange">How far the unit can move</param> public static List <CellClass> FindPath(CellClass startCell, GridClass grid, int moveRange) { List <CellClass> openList; List <CellClass> closedList; openList = new List <CellClass>(); closedList = new List <CellClass>(); startCell.Distance = 0; startCell.ParentCell = null; CellClass curCell = startCell; openList.Add(curCell); while (curCell.Distance <= moveRange) { closedList.Add(curCell); openList.Remove(curCell); if (curCell.adjacentCells.Count == 0) { Debug.Log("Uh.. no adjacent cells. Whee!"); } else { foreach (CellClass cell in curCell.adjacentCells) { // System.Predicate<CellClass> listPredicate = c => c == cell; cell.Distance = curCell.Distance + cell.Cost; if (cell.Cost != 0 && cell.Occupied == false && cell.Distance <= moveRange && !openList.Contains(cell) && !closedList.Contains(cell)) { cell.ParentCell = curCell; openList.Add(cell); } } } if (openList.Count == 0) { break; } openList.Sort(SortByDistance); curCell = openList[0]; } // Debug.Log( closedList.Count); closedList.TrimExcess(); return(closedList); }