void AjustPosition() { mapSCR.RemoveCharacterPosition(gameObject, isAlly); //mapSCR.RemoveCharacterPosition(gameObject, isAlly, tempCellPos); charMng.playerCell = null; ShipCell emptyCell = mapSCR.IsRoomEmpty(transform.position, isAlly); if (emptyCell != null) { Vector2 mypos = new Vector2(transform.position.x, transform.position.y); Vector2 mycellpos = new Vector2(emptyCell.position.x, emptyCell.position.y); float distance = Vector2.Distance(mypos, mycellpos); if (distance > 0.1f) // <=== { MoveToNode(emptyCell.position); } else { charMng.playerCell = mapSCR.SetCharacterPosition(gameObject, isAlly); } } else { goalList.Clear(); StartCoroutine(CalculateAllPath()); StartCoroutine(UrgentPathCorrect()); } }
bool RecalculateRecursive(ShipCell cell, HashSet <ShipCell> circle) { circle.Add(cell); var neigh = cell.GetNotSuccessors(circle); foreach (var best in neigh) { if (IsCircle(best.Pred, circle)) { continue; } cell.Pred = best; return(true); } var succ = cell.GetSuccessors(circle); foreach (var best in succ) { if (RecalculateRecursive(best, circle)) { cell.Pred = best; return(true); } } return(false); }
public void ContainCorrectShip() { var ship = A.Fake <IShip>(); var cell = new ShipCell(position, ship); cell.Ship.Should().Be(ship); }
private void UnlockWindowShowup(ShipCell genCell) { unlockWindow.gameObject.SetActive(true); unitToUnlock = genCell; unlockWindow.unitName.SetText(genCell.relatedUnit.unitName); unlockWindow.unitDescription.SetText("Blablabla12456"); unlockWindow.unitImage.sprite = genCell.relatedUnit.sprite; }
IEnumerator OperateCrt() { while (true) { bool operating = false; if (!isRepairing && !isMoving && playerCell != null) { if (playerCell.engine != null) { int opeLevel = GetOperateLevel(playerCell.engine.engine); if (opeLevel > 0 && playerCell.engine.currentPwr > 0) { if (isAlly) { if (playerCell.position.x < 0) { operating = true; playerCell.engine.Operate(opeLevel); playerCell.engine.operatedBy = gameObject; lastCell = playerCell; } } else { if (playerCell.position.x > 0) { operating = true; playerCell.engine.Operate(opeLevel); playerCell.engine.operatedBy = gameObject; lastCell = playerCell; } } } } } if (operating) { isOperating = true; } else { if (lastCell != null) { if (lastCell.engine != null) { if (lastCell.engine.operatedBy == gameObject) { lastCell.engine.Operate(0); lastCell.engine.operatedBy = null; } } } isOperating = false; } yield return(new WaitForSeconds(0.1f)); } }
private void UnlockConfirm() { unitToUnlock.relatedUnit.isLocked = false; me.availableMoney -= unitToUnlock.relatedUnit.cost; unitToUnlock = null; unlockWindow.gameObject.SetActive(false); OnClickHandler(false); RefreshStates(); }
public void Test_ShipCell_CanCreate() { // Arrange // Act var shipCell = new ShipCell(() => { }); // Assert Assert.IsNotNull(shipCell); }
public void EnterHullEdit() { UIData.BuildStatePanel.HullBuild.interactable = false; UIData.BuildStatePanel.CellBuild.interactable = true; if (selectedShipCell != null) { RevertSelectedShipCellTransform(); } selectedShipCell = default(ShipCell); SetStateBuildHullMode(); }
public void PlaceShip_WhenOneSegmentCrossesWithDifferentShip_ReturnsFalse(int x, int y, Direction direction) { var board = GenerateEmptyBoard(10); board[2, 2] = new ShipCell(ShipType.Destroyer, new List <ShipCell>()); var initialPosition = new Point(x, y); boardGenerator.PlaceShip(board, ShipType.Battleship, direction, initialPosition) .ShouldBe(false); }
public void Test_ShipCell_CallsOnDestroyedWhenAttacked() { // Arrange var attackedCalled = false; Action onAttacked = () => attackedCalled = true; var shipCell = new ShipCell(onAttacked); // Act shipCell.Attack(); // Assert Assert.IsTrue(attackedCalled); }
/* * void BuildObjectGroup(GameObject toBuild){ * for (int y = 0; y < gridDimensionY; y++) { * for (int x = 0; x < gridDimensionX; x++) { * Instantiate(toBuild,GridCells[x,y].cellPosition ,Quaternion.identity); * } * } * } */ #endregion void GenerateNewShipCell() { Vector3 currentMousePosition = ReturnCurrentMousePosition(); GridCoordinate gridCoord = ReturnCellGridCoordinate(currentMousePosition); if (IsValidGridCell(gridCoord)) { int gridElement = CoordToElement(gridCoord); GridCell localGridCell = GridCells[gridElement]; if (localGridCell.hasShipCell == false) { Vector3 spawnPos = localGridCell.gridPosition; GameObject newCell = new GameObject(); localGridCell.shipCell = newCell; localGridCell.hasShipCell = true; newCell.AddComponent <ShipCell>(); ShipCell localShipCell = localGridCell.shipCellComponent = newCell.GetComponent <ShipCell>(); localShipCell.SetHullColors(ColorData.HullColors); int listAdjustment = 0; for (int i = 0; i < 6; i++) { if (localGridCell.hasGridNeighborAt[i] == false) { listAdjustment++; continue; } GridCoordinate neighborCoord = localGridCell.neighborCoordinates[i - listAdjustment]; int gridElementOfNeighbor = CoordToElement(neighborCoord); GridCell neighborCell = GridCells[gridElementOfNeighbor]; if (neighborCell.hasShipCell) { localShipCell.neighborShipCells.Add(neighborCoord, neighborCell.shipCellComponent); neighborCell.shipCellComponent.neighborShipCells.Add(gridCoord, localShipCell); localShipCell.hasCellNeighborAt.Add(i); neighborCell.shipCellComponent.hasCellNeighborAt.Add((i + 3) % 6); neighborCell.shipCellComponent.UpdateHullSection((i + 3) % 6); } } localShipCell.InitializeShipCell(); newCell.transform.position = spawnPos; newCell.transform.SetParent(transform); newCell.name = "Ship Cell " + globalCellCount; globalCellCount++; } } }
private void SetDisconnected(ShipCell knoten) { knoten.Disconnected = true; foreach (var other in knoten.GetNeighbors()) { if (other.Disconnected) { continue; } SetDisconnected(other); } }
bool Recalculate(ShipCell cell) { var circle = new HashSet <ShipCell>(); if (!RecalculateRecursive(cell, circle)) { cell.Pred = null; SetDisconnected(cell); return(true); } return(false); }
public void ApplyCellCustomization(int i) { selectedShipCell.UpdateCellHubVisuals(ColorData.UpgradeColors[i]); if (selectedShipCell.hasCellUpgrade) { RemoveCustomization(selectedShipCell); AddCustomization((Customization)i); } else { AddCustomization((Customization)i); selectedShipCell.hasCellUpgrade = true; } RevertSelectedShipCellTransform(); selectedShipCell = default(ShipCell); }
public void MovePlayer(int roomIndex, int map) { // récupere une cell vide if (selectedPlayer == null) { return; } shipMapSCR.RemoveCharacterPosition(selectedPlayer, selectedPlayer.GetComponent <PlayerMovement>().isAlly); ShipCell freeCell = GetFreeCellInRoom(roomIndex, map); if (freeCell != null) { Vector3 targetPos = freeCell.position; selectedPlayer.GetComponent <PlayerMovement>().MoveToNode(targetPos); } }
void RemoveShipCell() { Vector3 currentMousePosition = ReturnCurrentMousePosition(); GridCoordinate gridCoord = ReturnCellGridCoordinate(currentMousePosition); if (IsValidGridCell(gridCoord)) { int gridElement = CoordToElement(gridCoord); GridCell localGridCell = GridCells[gridElement]; if (localGridCell.hasShipCell == true) { localGridCell.hasShipCell = false; List <GridCoordinate> neighborCoords = new List <GridCoordinate>(localGridCell.shipCellComponent.neighborShipCells.Keys); for (int i = 0; i < neighborCoords.Count; i++) { int neighborElement = CoordToElement(neighborCoords[i]); GridCell neighborCell = GridCells[neighborElement]; ShipCell neighborShipCell = neighborCell.shipCellComponent; Vector2 neighborCheck = localGridCell.gridCoordinate.SumCoordinatesAsVector2(neighborCell.gridCoordinate); for (int j = 0; j < 6; j++) { if (neighborDirection[j] == neighborCheck) { neighborShipCell.hasCellNeighborAt.Remove(j); neighborShipCell.UpdateHullSection(j); } } neighborShipCell.neighborShipCells.Remove(localGridCell.gridCoordinate); } if (localGridCell.shipCellComponent.hasCellUpgrade) { RemoveCustomization(localGridCell.shipCellComponent); } Destroy(localGridCell.shipCell); localGridCell.shipCell = default(GameObject); localGridCell.shipCellComponent = default(ShipCell); } } }
public void RemoveCharacterPosition(GameObject character, bool ally, Vector3 targetPosition) { Vector3 charPos = targetPosition; ShipCell cell = GetCellByPos(charPos); if (cell != null) { if (ally) { cell.crew = null; } else { cell.enemy = null; } } }
void SetNeighbors(ShipCell cell) { if ((cell.CellType & CellType.North) != 0) { var other = cells[cell.Index - width]; cell.SetNeighbor(CellType.North, other); other.SetNeighbor(CellType.South, cell); } if ((cell.CellType & CellType.West) != 0) { var other = cells[cell.Index - 1]; cell.SetNeighbor(CellType.West, other); other.SetNeighbor(CellType.East, cell); } }
bool IsCircle(ShipCell current, HashSet <ShipCell> circle) { if (current == null) { return(false); } do { if (circle.Contains(current)) { return(true); } current = current.Pred; } while (current != null); return(false); }
public void MoveToNode(Vector3 targetPos) { aiLerp.ResetToDefault(); mapSCR.RemoveCharacterPosition(gameObject, isAlly); //mapSCR.RemoveCharacterPosition(gameObject, isAlly, tempCellPos); charMng.playerCell = null; tempCellPos = targetPos; ShipCell cellToGo = mapSCR.SetCharacterPosition(gameObject, isAlly, tempCellPos); charMng.playerCell = cellToGo; StopAllCoroutines(); if (cellToGo == null) { moveCoroutine = Move(targetPos); } else { moveCoroutine = Move(cellToGo.position); } StartCoroutine(moveCoroutine); }
public void SetNeighbor(CellType type, ShipCell cell) { switch (type) { case CellType.North: neighbors[north] = cell; break; case CellType.East: neighbors[east] = cell; break; case CellType.South: neighbors[south] = cell; break; case CellType.West: neighbors[west] = cell; break; } }
void Idle() { if (Input.GetKeyDown(KeyCode.D)) { } if (Input.GetKeyDown(KeyCode.F)) { LaunchShipIntoSpace(); } if (Input.GetKeyDown(KeyCode.Alpha1)) { EnterHullEdit(); } if (Input.GetMouseButtonDown(0)) { Vector3 mousePos = ReturnCurrentMousePosition(); GridCoordinate gridCoord = ReturnCellGridCoordinate(mousePos); if (IsValidGridCell(gridCoord)) { GridCell gridCell = GridCells[CoordToElement(gridCoord)]; if (gridCell.hasShipCell) { if (selectedShipCell != gridCell.shipCellComponent) { if (selectedShipCell != null) { RevertSelectedShipCellTransform(); } selectedShipCell = gridCell.shipCellComponent; selectedShipCell.gameObject.transform.position += new Vector3(0f, 0f, -0.1f); selectedShipCell.gameObject.transform.localScale = new Vector3(1.5f, 1.5f); } } } } }
private void Init() { cells = new ShipCell[width * height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { CellType type = 0; if (y != 0) { type |= CellType.North; } if (y != height - 1) { type |= CellType.South; } if (x != 0) { type |= CellType.West; } if (x != width - 1) { type |= CellType.East; } var cell = new ShipCell(x, y, width, type); cells[cell.Index] = cell; SetNeighbors(cell); } } }
private static ICell[,] generateBoard(int size, IList <ShipType> ships) { var board = new ICell[size, size]; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { board[i, j] = new EmptyCell(); } } for (int i = 0; i < ships.Count; i++) { var wholeShip = new List <ShipCell>(); for (int j = 0; j < ships[i].ShipSize(); j++) { var shipCell = new ShipCell(ships[i], wholeShip); wholeShip.Add(shipCell); board[i, j] = shipCell; } } return(board); }
private void ReadShipsFromNode(XmlNode node) { if (node == null) { return; } foreach (XmlNode childNode in node.ChildNodes) { if (childNode.LocalName != "ships") { continue; } Ship newShip = new Ship(); newShip.id = uint.Parse(childNode.Attributes[IDATTR_NAME].Value); ReadLangStringFromNode(childNode, new LangStringPair(newShip.name, NAMENODE_NAME), new LangStringPair(newShip.description, DESCNODE_NAME)); newShip.backOffset.x = int.Parse(SafeGetNodeValue(FindFirstChildNode(node, "backoffs_x"), "0")); newShip.backOffset.y = int.Parse(SafeGetNodeValue(FindFirstChildNode(node, "backoffs_y"), "0")); newShip.inwardOffset.x = int.Parse(SafeGetNodeValue(FindFirstChildNode(node, "inwoffs_x"), "20")); newShip.inwardOffset.y = int.Parse(SafeGetNodeValue(FindFirstChildNode(node, "inwoffs_y"), "20")); newShip.textureId = uint.Parse(SafeGetNodeValue(FindFirstChildNode(node, "tex_id"), "0")); XmlNode gridNode = FindFirstChildNode(node, "grid"); List <ShipCell> cellLine = null; foreach (XmlNode rowNode in gridNode.ChildNodes) { switch (rowNode.LocalName) { case "row_L0": { cellLine = new List <ShipCell>(); List <uint> valuesList = StringToUintList(SafeGetNodeValue(rowNode, "")); foreach (uint value in valuesList) { ShipCell shipCell = new ShipCell(); shipCell.CellType = (ShipCellType)value; cellLine.Add(shipCell); } } break; case "row_L1": { if (cellLine == null) { Debug.Log("Row L1: cellLine is NULL"); break; } List <uint> valuesList = StringToUintList(SafeGetNodeValue(rowNode, "")); for (int valueInd = 0; valueInd < valuesList.Count; valueInd++) { cellLine[valueInd].InterType = (ShipInterierType)valueInd; cellLine[valueInd].CrewState = CrewState.CREW_STATE_NONE; } newShip.grid.Add(cellLine); cellLine = null; } break; } } ships.Add(newShip.id, newShip); } }
private void UnlockCancel() { unitToUnlock = null; unlockWindow.gameObject.SetActive(false); }
IEnumerator CrewPositionManagement() { while (true) { yield return(new WaitForSeconds(0.1f)); if (mapScr == null) { continue; } // Si un personnage est dans une salle, update sa priority à celle actuelle de la salle foreach (Crew2 crew2 in crew2List) { ShipCell playerCell = crew2.crew.GetComponent <CharacterManager>().playerCell; if (playerCell != null) { ShipRoom playerRoom = mapScr.GetRoomByPos(playerCell.position); if (playerRoom != null) { Engine myEng = playerRoom.engine; if (myEng != null) { foreach (Engine2 eng2 in eng2List) { if (eng2.engine == myEng) { crew2.priority = eng2.priority; } } } } } } yield return(new WaitForSeconds(0.1f)); foreach (Crew2 crew2 in crew2List) { CharacterManager charMng = crew2.crew.GetComponent <CharacterManager>(); float HpPercent = (charMng.currentHp * 100) / (float)charMng.maxHp; if (HpPercent < 40) { if (!crew2.isHealing) { crew2.isHealing = true; Vector3 tempPos = mapScr.GetEnginePos(Engine.engineType.medic, false); crew2.crew.GetComponent <PlayerMovement>().MoveToNode(tempPos); } } else { crew2.isHealing = false; } } // Si un salle est endommagée, change sa priority foreach (Engine2 eng2 in eng2List) { if (eng2.engine.currentHp < eng2.engine.maxHp) { eng2.priority = 0; } else { eng2.priority = eng2.basePriority; } } yield return(new WaitForSeconds(0.1f)); // envoi tous les personnages dans les salles par priorité foreach (Engine2 eng2 in eng2List) { Crew2 crewToMove = GetLowestPriorityMember(); Vector3 engPosition = mapScr.GetEnginePos(eng2.engine.engine, false); ShipRoom room = mapScr.GetRoomByPos(engPosition); bool emptyRoom = true; foreach (ShipCell cell in room.cells) { if (cell.enemy != null) { emptyRoom = false; } } if (crewToMove != null) { if (eng2.priority < crewToMove.priority && emptyRoom) { crewToMove.crew.GetComponent <PlayerMovement>().MoveToNode(engPosition); crewToMove.priority = eng2.priority; } } } } }
IEnumerator OperateCrt() { while(true) { bool operating = false; if(!isRepairing && !isMoving && playerCell != null) { if(playerCell.engine != null) { int opeLevel = GetOperateLevel(playerCell.engine.engine); if (opeLevel > 0 && playerCell.engine.currentPwr > 0) { if (isAlly) { if (playerCell.position.x < 0) { operating = true; playerCell.engine.Operate(opeLevel); playerCell.engine.operatedBy = gameObject; lastCell = playerCell; } } else { if (playerCell.position.x > 0) { operating = true; playerCell.engine.Operate(opeLevel); playerCell.engine.operatedBy = gameObject; lastCell = playerCell; } } } } } if (operating) { isOperating = true; } else { if(lastCell != null) { if(lastCell.engine != null) { if(lastCell.engine.operatedBy == gameObject) { lastCell.engine.Operate(0); lastCell.engine.operatedBy = null; } } } isOperating = false; } yield return new WaitForSeconds(0.1f); } }
private void DrawPred() { var g = GraphView.CreateGraphics(); var p = new Pen(Color.Green, 3); p.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; for (int i = 0; i < cells.Length; i++) { if (cells[i] == null) { continue; } ShipCell pred = cells[i].Pred; if (pred == null) { continue; } var pointS = IndexToPoint(i); var pointE = IndexToPoint(pred.Index); int startX, startY, endX, endY; if (pointS.Y == pointE.Y) { if (pointS.X > pointE.X) { startY = pointS.X - pointRadius; endY = pointE.X + pointRadius; startX = endX = pointS.Y; } else { startY = pointS.X + pointRadius; endY = pointE.X - pointRadius; startX = endX = pointS.Y; } } else { if (pointS.Y > pointE.Y) { startX = pointS.Y - pointRadius; endX = pointE.Y + pointRadius; startY = endY = pointS.X; } else { startX = pointS.Y + pointRadius; endX = pointE.Y - pointRadius; startY = endY = pointS.X; } } g.DrawLine(p, startY, startX, endY, endX); } }
public void RemoveCustomization(ShipCell shipCell) { currentUpgradeList[shipCell].RemoveUpgrade(playersShip); currentUpgradeList.Remove(shipCell); UpdateUIStats(); }