public void PlayerUnitMouseUp(int pixelX, int pixelY) { var cube = HexGridMath.HexToCube(HexGridMath.PixelToHex(pixelX, pixelY)); var offset = HexGridMath.CubeToOffset(cube.X, cube.Y, cube.Z); var enemyUnit = _units.FindUnit(offset.Col, offset.Row); if (enemyUnit != null && _alliedEnemyMatrix.AreEnemies(NATIONALITY.USA, enemyUnit.Nationality)) { AttackUnit(enemyUnit); return; } //TODO: need to tweak algorithm so an allied unit cannot slide past an enemy unit. Can only back away to a square that has no enemy _units in any surrounding hex. // user just dropped the unit var unit = _units.FindSelectedUnit(); if (unit != null) { if (unit.Movement < 0.1) { return; } _units.IdleUnit = unit; //check to see if this is a new hex location if (unit.Col != offset.Col || unit.Row != offset.Row) { //TODO: need to account for coordinates that are off the map (negatives, etc.) int endCol = offset.Col; int endRow = offset.Row; // find the path unit.FindShortestPath(_terrainMap, unit.Col, unit.Row, endCol, endRow, unit.UnitType); _nextAlliedUnitToMove = unit; } else { // user clicked on unit, wake unit and make this unit the active unit if (!unit.TurnComplete) { unit.Sleep = false; } } return; } _units.UnselectUnits(); }
//TODO: this is a duplicate method (also in GameBoard.cs) private bool IsCellBlocked(Unit unit, int endCol, int endRow) { // check to see if this unit cannot cross this terrain if (_map[endCol, endRow].Blocked(unit.UnitType)) { return(true); } // check to see if the destination cell is already occupied by another unit if (_units.FindUnit(endCol, endRow) != null) { return(true); } return(false); }
public void AddUnit(int Col, int Row, int unitType, NATIONALITY nationality) { _units.Add(Col, Row, unitType, nationality); if (nationality == NATIONALITY.USA) { var newUnit = _units.FindUnit(Col, Row); _terrainMap.UnmaskBoard(Col, Row, newUnit.ViewRange); _terrainMap.SetView(Col, Row, newUnit.ViewRange); } }
public static bool IsPlayerMaximumReached(IUnitList unitList) { var players = unitList.FindUnit(typeof(Player)); return(players.Any()); }
public static bool IsLocationOccupied(Location location, IUnitList unitList) { IUnit unit = unitList.FindUnit(location); return(unit != null); }