private void IterationsChanged() { if (Iterations >= AllSubBoardsInvolvedWithStacking.Count) { int NumberOfNewBoards = Iterations + 1 - AllSubBoardsInvolvedWithStacking.Count; for (int i = 0; i < NumberOfNewBoards; i++) { GameObject NewBoard = Instantiate(BoardBeingStackedCopy); NewBoard.transform.position = new Vector3(1000, -1000, 1000); // so RecalculateCluster can work unhindered NewBoard.transform.parent = AllSubBoardsInvolvedWithStacking[AllSubBoardsInvolvedWithStacking.Count - 1].transform; StuffPlacer.SetStateOfAllBoxCollidersIn(NewBoard, false); AllSubBoardsInvolvedWithStacking.Add(NewBoard); BoardFunctions.RecalculateClustersOfBoard(NewBoard); MegaMeshManager.RemoveComponentsImmediatelyIn(NewBoard); MegaMeshManager.AddComponentsIn(NewBoard); } } else if (Iterations < AllSubBoardsInvolvedWithStacking.Count) { //int NumberOfExtraBoards = AllSubBoardsInvolvedWithStacking.Count + 1 - Iterations; for (int i = AllSubBoardsInvolvedWithStacking.Count - 1; i > Iterations; i--) { GameObject oldboard = AllSubBoardsInvolvedWithStacking[i]; AllSubBoardsInvolvedWithStacking.Remove(oldboard); oldboard.transform.parent = null; // because the board is not destroyed immediately, this is done to prevent the old board from being used in the interesction test of UpdateHighlight Destroy(oldboard); } } SetAllBoardPositions(); }
// Funciton to set up regular & Metric TSP instance void SetTSP(GameManager.TSPInstance currentInstance) { // Display current distance DistanceText = GameObject.Find("DistanceText").GetComponent <Text>(); // Coordinate of the cities cox = currentInstance.coordinatesx; coy = currentInstance.coordinatesy; unitycoord = BoardFunctions.CoordinateConvertor(cox, coy); // Number of objects ncities = currentInstance.ncities; distances = currentInstance.distancematrix; solution = currentInstance.solution; // Store objects in a list items = new Item[ncities]; for (int i = 0; i < ncities; i++) { for (int j = i; j < ncities; j++) { if (distances[i, j] != 0) { DrawSlimLine(i, j, 0.01f); } } } for (int i = 0; i < ncities; i++) { items[i] = GenerateItem(i, unitycoord[i]); } }
public static void NewBoardBeingPlaced(GameObject NewBoard) { if (NewBoard == null) { return; } DestroyBoardBeingPlaced(); BoardBeingPlaced = NewBoard; NewBoard.transform.parent = ReferenceObject.transform; CircuitBoardBeingPlaced = NewBoard.GetComponent <CircuitBoard>(); SetRotationState(); CapPlacingOffset(); StuffPlacer.BoardRotationLockAngle = Mathf.Round(StuffPlacer.BoardRotationLockAngle / 90f) * 90; // fixes being able to place boards at non-right angles by locking rotation beforehand StuffPlacer.RotationAboutUpVector = Mathf.RoundToInt(StuffPlacer.RotationAboutUpVector / 90) * 90f; if (!BoardBeingPlaced.GetComponent <ObjectInfo>()) { BoardBeingPlaced.AddComponent <ObjectInfo>().ComponentType = ComponentType.CircuitBoard; } BoardFunctions.DestroyAllWiresConnectedToBoardButNotPartOfIt(NewBoard); StuffPlacer.NewThingBeingPlaced(ReferenceObject); }
public void Do() { var board = NetObject.GetByNetId(BoardID); if (board == null) { return; } BoardFunctions.DestroyAllWiresConnectedToBoardButNotPartOfIt(board.gameObject); MegaMeshManager.RemoveComponentsImmediatelyIn(board.gameObject); CircuitInput[] componentsInChildren = board.GetComponentsInChildren <CircuitInput>(); CircuitOutput[] componentsInChildren2 = board.GetComponentsInChildren <CircuitOutput>(); foreach (CircuitInput input in componentsInChildren) { StuffDeleter.DestroyInput(input); } foreach (CircuitOutput output in componentsInChildren2) { StuffDeleter.DestroyOutput(output); } GameObject.Destroy(board.gameObject); }
private void DeleteBoard() { if (Physics.Raycast(FirstPersonInteraction.Ray(), out var raycastHit, Settings.ReachDistance, 769) && StuffDeleter.AllowedToDoDeleting && raycastHit.collider.gameObject.tag == "CircuitBoard") { var board = raycastHit.collider.gameObject; BoardFunctions.SetMostRecentlyDeletedBoard(board); BoardFunctions.DestroyAllWiresConnectedToBoardButNotPartOfIt(board); MegaMeshManager.RemoveComponentsImmediatelyIn(board); CircuitInput[] componentsInChildren = board.GetComponentsInChildren <CircuitInput>(); CircuitOutput[] componentsInChildren2 = board.GetComponentsInChildren <CircuitOutput>(); foreach (CircuitInput input in componentsInChildren) { StuffDeleter.DestroyInput(input); } foreach (CircuitOutput output in componentsInChildren2) { StuffDeleter.DestroyOutput(output); } GameObject.Destroy(board); SoundPlayer.PlaySoundGlobal(Sounds.DeleteSomething); } }
/// <summary>Sets swapping animations and changes positions on the board if it is not gonna rewire </summary> /// <param name="firstElement"></param> /// <param name="secondElement"></param> /// <param name="positions">the board of elemetns</param> /// <param name="playingAnimations">list to add new animations</param> /// <param name="rewire">use if input is incorrect</param> /// <param name="shouldCheckMatches">should check for new matches after swap?</param> /// <param name="swappingSpeed">the speed of animation</param> /// <returns>Returns if should check</returns> public static void SwapElements(BoardElement firstElement, BoardElement secondElement, BoardManager board, bool rewire = false, float speed = -1) { if (speed == -1) { speed = ConstantValues.swappingSpeed; } KeyValuePair <int, int> firstElementPosOnBoard = GetBoardPositionOfElement(firstElement, board.elementsPositions); KeyValuePair <int, int> secondElementPosOnBoard = GetBoardPositionOfElement(secondElement, board.elementsPositions); board.currentMessageID += 1; board.messagesToClient.Add(new Messages.AnimationMessage(board.currentMessageID, -1, Messages.AnimationMessage.AnimationMessageTypes.MoveTo, firstElement.GetTransformIndex(), speed, secondElementPosOnBoard.Key, secondElementPosOnBoard.Value)); board.currentMessageID += 1; board.messagesToClient.Add(new Messages.AnimationMessage(board.currentMessageID, -1, Messages.AnimationMessage.AnimationMessageTypes.MoveTo, secondElement.GetTransformIndex(), speed, firstElementPosOnBoard.Key, firstElementPosOnBoard.Value)); if (!rewire) { BoardFunctions.SwapBoardElementNeighbours(firstElement, secondElement, ref board.elementsPositions); } else { board.currentMessageID += 1; board.messagesToClient.Add(new Messages.AnimationMessage(board.currentMessageID, board.currentMessageID - 2, Messages.AnimationMessage.AnimationMessageTypes.MoveTo, firstElement.GetTransformIndex(), speed, firstElementPosOnBoard.Key, firstElementPosOnBoard.Value)); board.currentMessageID += 1; board.messagesToClient.Add(new Messages.AnimationMessage(board.currentMessageID, board.currentMessageID - 2, Messages.AnimationMessage.AnimationMessageTypes.MoveTo, secondElement.GetTransformIndex(), speed, secondElementPosOnBoard.Key, secondElementPosOnBoard.Value)); } }
/// <summary>Receives input from client and handles it</summary> public void TakeInput(int firstElementIndexAtParent, int secondElementIndexAtParent) { // find first element based on gamePanel's child index firstElement = BoardFunctions.GetElementBasedOnParentIndex(elementsPositions, firstElementIndexAtParent); // find second element based on gamePanel's child index secondElement = BoardFunctions.GetElementBasedOnParentIndex(elementsPositions, secondElementIndexAtParent); currentStep = GameStep.CheckingInput; #region Debug // To use for cheats // if (BoardFunctions.GetIfNeighbours(firstElement, secondElement, elementsPositions)) { // AlexDebugger.GetInstance().AddMessage("Correct input: " + BoardFunctions.GetTransformByIndex(firstElement.GetTransformIndex()) + ", with " + BoardFunctions.GetTransformByIndex(secondElement.GetTransformIndex()), AlexDebugger.tags.Input); // // Remove tokens // MoneyManager.ChangeBalanceBy(-MoneyManager.GetSwapCost()); // // Swap the elements on the board // BoardFunctions.SwapElements(firstElement, secondElement, this, rewire : false, FixedElementData.swappingSpeed / 2); // // Allow Update() to check if matches are created // } // else { // // Swap elements, on rewire mode // BoardFunctions.SwapElements(firstElement, secondElement, this, rewire : true); // AddWaitMessage(); // SendMessagesToClient(); // currentMessageID += 1; // Server.GetServerInstance().SendMessageToClient(new Messages.ServerStatusMessage(currentMessageID, -1, true)); // } #endregion }
/// <summary>Checks each element on the board for matches and flags them</summary> public int CheckBoardForMatches() { AlexDebugger.GetInstance().AddMessage("Checking board for new matches...", AlexDebugger.tags.Aftermatch); int totalMatches = 0; // Search for matches and flag them for (int row = 0; row < elementsPositions.GetLength(1); row++) { for (int collum = 0; collum < elementsPositions.GetLength(0); collum++) { // case of cash element has reached bottom if (row == elementsPositions.GetLength(1) - 1 && elementsPositions[collum, row].GetElementClassType() == typeof(CashBoardElement)) { matchedElemPositions[collum, row] = true; AlexDebugger.GetInstance().AddMessage("A cash element has reached bottom at position: " + collum + ", " + row, AlexDebugger.tags.Aftermatch); totalMatches++; } else if (matchedElemPositions[collum, row] == true || !changedPotitions[collum, row]) { continue; } else { totalMatches += BoardFunctions.CheckElementForMatches(collum, row, elementsPositions, ref matchedElemPositions, ConstantValues.totalCollums, ConstantValues.totalRows, true); } } } return(totalMatches); }
private bool PlayEffectsStep() { BoardElement lastElementProcessed = secondElement; bool areThereChangesOnBoard = false; for (int row = 0; row < elementsPositions.GetLength(1); row++) { for (int collum = 0; collum < elementsPositions.GetLength(0); collum++) { if (matchedElemPositions[collum, row] == true) { BoardFunctions.PlayMatchEffectAnimations(collum, row, this); if (BoardFunctions.DestroyBoardElement(collum, row, this, lastElementProcessed)) { areThereChangesOnBoard = true; } } lastElementProcessed = elementsPositions[collum, row]; BoardFunctions.ToggleHighlightCell(collum, row, this, false); } } if (!areThereChangesOnBoard) { AlexDebugger.GetInstance().AddMessage("Step2 finished: -play effects for matched elements-, go to Step3: -reorient elements- " + messagesToClient.Count, AlexDebugger.tags.Step2); return(true); } else { AlexDebugger.GetInstance().AddMessage("Step2 finished: -play effects for matched elements-, new elements has been destroyed, repeating step ", AlexDebugger.tags.Step2); return(false); } }
private bool CheckForPossibleInputs() { bool hasPossibleInput = false; for (int row = 0; row < elementsPositions.GetLength(1); row++) { for (int collum = 0; collum < elementsPositions.GetLength(0); collum++) { changedPotitions[collum, row] = false; if (elementsPositions[collum, row].GetElementClassType() == typeof(CashBoardElement)) { continue; } else if (elementsPositions[collum, row].GetElementClassType() == typeof(BombBoardElement) || elementsPositions[collum, row].GetElementClassType() == typeof(BellBoardElement)) { hasPossibleInput = true; } else if (BoardFunctions.IsPotentialInput(collum, row, elementsPositions, matchedElemPositions, ConstantValues.totalCollums, ConstantValues.totalRows) > 0) { //AlexDebugger.GetInstance().AddMessage(BoardFunctions.GetTransformByIndex(elementsPositions[collum, row].GetTransformIndex()) + " is potential input", AlexDebugger.tags.Step5); BoardFunctions.ToggleHighlightCell(collum, row, this, true); hasPossibleInput = true; } else { BoardFunctions.ToggleHighlightCell(collum, row, this, false); } } } return(hasPossibleInput); }
public override bool OnElementDestruction(BoardManager board) { if (hasBeenDestroyed) { return(false); } KeyValuePair <int, int> pos = BoardFunctions.GetBoardPositionOfElement(this, board.elementsPositions); switch (thisBombStyle) { case BombExplosionStyle.CrossStyle: BoardFunctions.DestroyAllElementsCrossStyle(pos.Key, pos.Value, ref board.matchedElemPositions); break; case BombExplosionStyle.DoubleBombStyle: BoardFunctions.DestroyElementsDoubleBombStyle(pos.Key, pos.Value, ref board.matchedElemPositions); break; case BombExplosionStyle.NormalStyle: BoardFunctions.DestroyElementsBombStyle(pos.Key, pos.Value, ref board.matchedElemPositions); break; default: BoardFunctions.DestroyElementsBombStyle(pos.Key, pos.Value, ref board.matchedElemPositions); break; } board.matchedElemPositions[pos.Key, pos.Value] = true; hasBeenDestroyed = true; return(true); }
// Instantiates an Item and places it on the position from the input Item GenerateItem(int itemNumber, Vector2 itemPosition) { GameObject instance = Instantiate(CityItemPrefab, itemPosition, Quaternion.identity) as GameObject; if (itemNumber == GameManager.wcsppInstances[currInstance].startcity) { instance = Instantiate(StartCityPrefab, itemPosition, Quaternion.identity) as GameObject; } else if (itemNumber == GameManager.wcsppInstances[currInstance].endcity) { instance = Instantiate(EndCityPrefab, itemPosition, Quaternion.identity) as GameObject; } canvas = GameObject.Find("Canvas"); instance.transform.SetParent(canvas.GetComponent <Transform>(), false); Item itemInstance; itemInstance.gameItem = instance; itemInstance.CityButton = itemInstance.gameItem.GetComponent <Button>(); itemInstance.CityNumber = itemNumber; itemInstance.center = itemPosition; //itemInstance.CityButton.GetComponent<Image>().sprite = Resources.Load<Sprite>("CityVisited"); // Setting the position in a separate line is importatant in order to set it according to global coordinates. BoardFunctions.PlaceItem(itemInstance, itemPosition); return(itemInstance); }
/// <summary> /// Try to move the object on the board /// See <see cref="IBoardFunctions"/> /// <seealso cref="MyRandom"/> /// </summary> /// <param name="obj">The object trying to move</param> public virtual void TryToMove() { int x, y; do { if (rnd == null) { x = MyRandom.Next(Math.Max(0, X - Agility), Math.Min(info.Length, X + 1 + Agility)); y = MyRandom.Next(Math.Max(0, Y - Agility), Math.Min(info.Hight, Y + 1 + Agility)); } else { x = rnd.Next(Math.Max(0, X - Agility), Math.Min(info.Hight, X + 1 + Agility)); y = rnd.Next(Math.Max(0, Y - Agility), Math.Min(info.Hight, Y + 1 + Agility)); } } while (x == X && y == Y); int localX = X; int localY = Y; bool result = BoardFunctions.TryToMove(X, Y, x, y); if (result) { ProducerConsumer.Produce(String.Format("object number {0} moved from ({1},{2}) to ({3},{4})", Id, localX, localY, x, y)); } }
/// <summary> /// update the status of the object. /// in Read mode. /// <see cref="IBoardFunctions.GetNearObjects(int, int)"/> /// </summary> private void UpdateStatus() { if (DeBuff == DeBuff.Cocoon) { if (numberOfDaysCocooned < 2) { numberOfDaysCocooned++; } else { numberOfDaysCocooned = 0; DeBuff = DeBuff.UnAffected; } } var objectsNear = BoardFunctions.GetNearObjects(X, Y, 1); // count is the number of objects around the given object. int count = objectsNear.Count; /// if the count is not in the boundries given by the <see cref="Info"/> class, /// the object's state will become <see cref="State.Depressed"/>. if ((count < info.MinObjectsPerArea || count > info.MaxObjectsPerArea) && State == State.Alive) { ProducerConsumer.Produce(String.Format("Object number {0} became depressed!", Id)); SetState(State.Depressed); } }
private static BoardElement GetNewElementForPosition(int collum, int row, BoardManager board, ref bool[, ] searchedElements) { if (BoardFunctions.GetIfMatchCreatesBell(collum, row, board.elementsPositions, ref searchedElements)) { return(BoardFunctions.CreateNewElement(board.elementsPositions[collum, row], BoardElement.BoardElementTypes.Bell)); } else if (BoardFunctions.GetIfMatchCreatesBomb(collum, row, board.elementsPositions, ref searchedElements)) { return(BoardFunctions.CreateNewElement(board.elementsPositions[collum, row], BoardElement.BoardElementTypes.Bomb)); } else if (BoardFunctions.GetIfMatchCreatesCross(collum, row, board.elementsPositions, ref searchedElements)) { return(BoardFunctions.CreateNewElement(board.elementsPositions[collum, row], BoardElement.BoardElementTypes.Cross)); } else { int cashElementIndex = BoardFunctions.GetIfCashElement(); if (cashElementIndex > -1) { return(BoardFunctions.CreateNewCashElement(board.elementsPositions[collum, row], cashElementIndex)); } else { return(BoardFunctions.CreateNewElement(board.elementsPositions[collum, row], BoardElement.BoardElementTypes.Default)); } } }
// called once per frame public static void DoInteraction() { if (Input.GetButtonDown("BoardMenu")) { BoardMenu.Instance.InitializeBoardMenu(); Done(); return; } if (Input.GetButtonDown("PickComponent")) { SelectionMenu.Instance.PickComponent(); } if (Input.GetButtonDown("Interact")) { RaycastHit hit; if (Physics.Raycast(Ray(), out hit, Settings.ReachDistance, IgnorePlayerLayermask)) { if (hit.collider.tag == "Interactable") // if the cast hits an interactable such as a button or lever, interact with it { hit.collider.GetComponent <Interactable>().Interact(); return; // so we can't place stuff too, as they are bound to the same key } } } if (Input.GetButtonDown("Zoom")) { FirstPersonCamera.fieldOfView = 10; FirstPersonController.Instance.m_MouseLook.XSensitivity /= 3; FirstPersonController.Instance.m_MouseLook.YSensitivity /= 3; } if (Input.GetButtonUp("Zoom")) { SettingsApplier.Instance.LoadFOV(); SettingsApplier.Instance.LoadXSensitivity(); SettingsApplier.Instance.LoadYSensitivity(); } if (Input.GetButtonDown("Cancel")) { PauseMenu.Instance.PauseGame(); } if (Input.GetButtonDown("UndoBoardDelete")) { BoardFunctions.RestoreMostRecentlyDeletedBoard(); return; } ComponentPlacer.RunComponentPlacing(); WirePlacer.RunWirePlacing(); StuffDeleter.RunGameplayDeleting(); StuffRotater.RunGameplayRotation(); SelectionMenu.Instance.RunBuildMenu(); LookThroughBoard.Run(); }
/// <summary> Flags positions that belong to a match </summary> /// <param name="shouldFlag"> if false, elements wont be marked as matched (usefull when want to check possible matches)</param> /// <returns>returns an array where: /// position 0: number of matches that create a cross /// position 1: number of matches create a bomb /// position 2: number of matches create a bell</returns> public static int CheckElementForMatches(int startCollum, int startRow, BoardElement[, ] positions, ref bool[, ] matchedElemPositions, int collumsNumber, int rowsNumber, bool shouldFlag = true) { int upperMatches = BoardFunctions.CheckUpperNeighboursForMatches(startCollum, startRow, positions); int bottomMatches = BoardFunctions.CheckBottomNeighboursForMatches(startCollum, startRow, positions, rowsNumber); int leftMatches = BoardFunctions.CheckLeftNeighboursForMatches(startCollum, startRow, positions); int rightMatches = BoardFunctions.CheckRightNeighboursForMatches(startCollum, startRow, positions, collumsNumber); if (shouldFlag) { // if more than 2 element matches, add vertical mathced elements if (upperMatches + bottomMatches >= 2) { matchedElemPositions[startCollum, startRow] = true; for (int row = startRow - upperMatches; row <= startRow + bottomMatches; row++) { matchedElemPositions[startCollum, row] = true; // AlexDebugger.GetInstance().AddMessage(positions[startCollum, row].GetAttachedGameObject().name + "is an " + ((row < startRow) ? " on top" : "on bottom") + " match of " + positions[startCollum, row].GetAttachedGameObject().name, AlexDebugger.tags.Matches); } if (upperMatches > 0) { //AlexDebugger.GetInstance().AddMessage("Upper matches for element: " + GetTransformByIndex(positions[startCollum, startRow].GetTransformIndex()) + " are: " + upperMatches, AlexDebugger.tags.Matches); } if (bottomMatches > 0) { //AlexDebugger.GetInstance().AddMessage("Bottom matches for element: " + GetTransformByIndex(positions[startCollum, startRow].GetTransformIndex()) + " are: " + bottomMatches, AlexDebugger.tags.Matches); } } // if more than 2 element matches, add horizontal mathced elements if (leftMatches + rightMatches >= 2) { matchedElemPositions[startCollum, startRow] = true; for (int collum = startCollum - leftMatches; collum <= startCollum + rightMatches; collum++) { matchedElemPositions[collum, startRow] = true; } if (leftMatches > 0) { //AlexDebugger.GetInstance().AddMessage("Left matches for element: " + GetTransformByIndex(positions[startCollum, startRow].GetTransformIndex()) + " are: " + leftMatches, AlexDebugger.tags.Matches); } if (rightMatches > 0) { //AlexDebugger.GetInstance().AddMessage("Bottom matches for element: " + GetTransformByIndex(positions[startCollum, startRow].GetTransformIndex()) + " are: " + rightMatches, AlexDebugger.tags.Matches); } } if (upperMatches + bottomMatches >= 2 || leftMatches + rightMatches >= 2) { //AlexDebugger.GetInstance().AddMessage("Total matches found for: " + GetTransformByIndex(positions[startCollum, startRow].GetTransformIndex()) + " are: " + (upperMatches + bottomMatches + leftMatches + rightMatches).ToString(), AlexDebugger.tags.Matches); } } if (upperMatches + bottomMatches >= 2 || leftMatches + rightMatches >= 2) { return(upperMatches + bottomMatches + leftMatches + rightMatches); } else { return(0); } }
public static void CancelPlacement() { SoundPlayer.PlaySoundAt(Sounds.DeleteSomething, BoardBeingPlaced); BoardFunctions.SetMostRecentlyDeletedBoard(BoardBeingPlaced); DestroyBoardBeingPlaced(); GameplayUIManager.UIState = UIState.None; }
public override bool OnElementDestruction(BoardManager board) { if (hasBeenDestroyed) { return(false); } KeyValuePair <int, int> pos = BoardFunctions.GetBoardPositionOfElement(this, board.elementsPositions); BoardFunctions.DestroyAllElementsCrossStyle(pos.Key, pos.Value, ref board.matchedElemPositions); board.matchedElemPositions[pos.Key, pos.Value] = true; hasBeenDestroyed = true; return(true); }
// Updates the timer (including the graphical representation) // If time runs out in the trial or the break scene. It switches to the next scene. void StartTimer() { tiempo -= Time.deltaTime; if (showTimer) { BoardFunctions.UpdateTimer(); } // When the time runs out: if (tiempo < 0) { ChangeToNextScene(BoardManager.itemClicks, false); } }
protected override void ActDepressedObject() { var objects = BoardFunctions.GetNearObjects(X, Y, 1); foreach (var obj in objects) { if (obj.DeBuff == DeBuff.Cocoon) { Fight(obj); SetState(State.Alive); break; } } }
protected override void ActDepressedObject() { var dynamicObjects = BoardFunctions.GetNearObjects(X, Y, 1); /// if the number of adjacent objects are in the range of [info.MinObjectsPerArea,info.MaxObjectsPerArea] /// than the given object will no longer be depressed. if (dynamicObjects.Count >= info.MinObjectsPerArea && dynamicObjects.Count <= info.MaxObjectsPerArea) { ProducerConsumer.Produce(String.Format("Object number {0} is no longer depressed, found {1} objects near it", Id, dynamicObjects.Count)); SetState(State.Alive); } else { ProducerConsumer.Produce(String.Format("Object number {0} is still depressed, found {1} objects near it", Id, dynamicObjects.Count)); } }
public override bool OnElementDestruction(BoardManager board, BoardElement otherElement) { if (hasBeenDestroyed) { return(false); } // if (otherElement == null) { // Debug.LogError(BoardFunctions.GetTransformByIndex(otherElement.GetTransformIndex()) + " Bell OnElementDestruction() triggered with null as gameobject"); // } KeyValuePair <int, int> pos = BoardFunctions.GetBoardPositionOfElement(this, board.elementsPositions); BoardFunctions.ActivateBellFunction(board, otherElement); board.matchedElemPositions[pos.Key, pos.Value] = true; hasBeenDestroyed = true; return(true); }
private void ReorientElements() { bool hasSFXplayed = false; for (int collum = 0; collum < ConstantValues.totalCollums; collum++) { //AlexDebugger.GetInstance().AddMessage("Moving element: " + elementsPositions[collum, row].GetAttachedGameObject().transform.name + " upwards", AlexDebugger.tags.Step3); if (BoardFunctions.MoveMatchedElementUpwards(collum, ConstantValues.totalRows - 1, this) && !hasSFXplayed) { float randomNum = random.Next(5, 20) / 10; currentMessageID += 1; messagesToClient.Add(new Messages.AudioMessage(AssetLoader.GetCellDropSFX(), currentMessageID, currentMessageID - 1, 0.0f, 1)); hasSFXplayed = true; } } }
//Updates the timer (including the graphical representation) //If time runs out in the trial or the break scene. It switches to the next scene. void startTimer() { tiempo -= Time.deltaTime; //Debug.Log (tiempo); if (showTimer) { BoardFunctions.updateTimer(); } //When the time runs out: if (tiempo < 0) { //changeToNextScene(2,BoardManager.randomYes); changeToNextScene(BoardManager.itemClicks, BoardManager.answer, BoardManager.randomYes, 0); } }
/// <summary>Swaps to elements positions on the board </summary> public static void SwapBoardElementNeighbours(BoardElement oldElement, BoardElement newElement, ref BoardElement[, ] positions) { KeyValuePair <int, int> oldElementPosition = BoardFunctions.GetBoardPositionOfElement(oldElement, positions); KeyValuePair <int, int> newElementPosition = BoardFunctions.GetBoardPositionOfElement(newElement, positions); positions[oldElementPosition.Key, oldElementPosition.Value] = newElement; positions[newElementPosition.Key, newElementPosition.Value] = oldElement; #if UNITY_EDITOR //Debug.Log(newElementPosition.Key + ", " + newElementPosition.Value + " set to position " + oldElementPosition.Key + ", " + oldElementPosition.Value); //Debug.Log(oldElementPosition.Key + ", " + oldElementPosition.Value + " set to position " + newElementPosition.Key + ", " + newElementPosition.Value); if (positions[oldElementPosition.Key, oldElementPosition.Value] == positions[newElementPosition.Key, newElementPosition.Value]) { UnityEngine.Debug.LogError("Swap was not correct"); } #endif }
private void FightSpider(IDynamicObject spider) { if (spider.DeBuff == DeBuff.Cocoon) { agilityProgress = 0; Strength += 2; Agility++; spider.SetState(State.Dead); BoardFunctions.ClearDynamicObjectOnTile(spider.X, spider.Y); ProducerConsumer.Produce(String.Format("Spider number {0} ate another spider with id {1}", Id, spider.Id)); } else if (Agility > spider.Agility) { spider.DeBuff = DeBuff.Cocoon; ProducerConsumer.Produce(String.Format("Spider number {0} became a cocoone", spider.Id)); } }
/// <summary>Check if with input it can create matches. Returns best score found </summary> public static int IsPotentialInput(int collum, int row, BoardElement[, ] positions, bool[, ] matchedElemPositions, int totalCollums, int totalRows) { int possibleScore = 0; if (row - 1 > -1 && positions[collum, row - 1].GetElementClassType() != typeof(CashBoardElement)) { BoardFunctions.SwapBoardElementNeighbours(positions[collum, row], positions[collum, row - 1], ref positions); int matches = BoardFunctions.CheckElementForMatches(collum, row - 1, positions, ref matchedElemPositions, totalCollums, totalRows, false); if (matches > 0) { possibleScore = matches; } BoardFunctions.SwapBoardElementNeighbours(positions[collum, row], positions[collum, row - 1], ref positions); } if (row + 1 < totalRows && positions[collum, row + 1].GetElementClassType() != typeof(CashBoardElement)) { BoardFunctions.SwapBoardElementNeighbours(positions[collum, row], positions[collum, row + 1], ref positions); int matches = BoardFunctions.CheckElementForMatches(collum, row + 1, positions, ref matchedElemPositions, totalCollums, totalRows, false); if (matches > 0 && possibleScore < matches) { possibleScore = matches; } BoardFunctions.SwapBoardElementNeighbours(positions[collum, row], positions[collum, row + 1], ref positions); } if (collum - 1 > -1 && positions[collum - 1, row].GetElementClassType() != typeof(CashBoardElement)) { BoardFunctions.SwapBoardElementNeighbours(positions[collum, row], positions[collum - 1, row], ref positions); int matches = BoardFunctions.CheckElementForMatches(collum - 1, row, positions, ref matchedElemPositions, totalCollums, totalRows, false); if (matches > 0 && possibleScore < matches) { possibleScore = matches; } BoardFunctions.SwapBoardElementNeighbours(positions[collum, row], positions[collum - 1, row], ref positions); } if (collum + 1 < totalCollums && positions[collum + 1, row].GetElementClassType() != typeof(CashBoardElement)) { BoardFunctions.SwapBoardElementNeighbours(positions[collum, row], positions[collum + 1, row], ref positions); int matches = BoardFunctions.CheckElementForMatches(collum + 1, row, positions, ref matchedElemPositions, totalCollums, totalRows, false); if (matches > 0 && possibleScore < matches) { possibleScore = matches; } BoardFunctions.SwapBoardElementNeighbours(positions[collum, row], positions[collum + 1, row], ref positions); } return(possibleScore); }
// Funciton to set up WCSPP instance void SetWCSPP(GameManager.WCSPPInstance currentInstance) { // Display Max distance Text quest = GameObject.Find("Question").GetComponent <Text>(); quest.text = "Max cost: $" + GameManager.wcsppInstances[currInstance].maxweight; // Display current distance DistanceText = GameObject.Find("DistanceText").GetComponent <Text>(); DistanceText.color = Color.yellow; // Display current weight WeightText = GameObject.Find("WeightText").GetComponent <Text>(); WeightText.color = Color.cyan; // Coordinate of the cities cox = currentInstance.coordinatesx; coy = currentInstance.coordinatesy; unitycoord = BoardFunctions.CoordinateConvertor(cox, coy); // Number of objects ncities = currentInstance.ncities; distances = currentInstance.distancematrix; weights = currentInstance.weightmatrix; solution = currentInstance.solution; // Store objects in a list items = new Item[ncities]; for (int i = 0; i < ncities; i++) { for (int j = i; j < ncities; j++) { if (distances[i, j] != 0) { DrawSlimLine(i, j, 0.01f); } } } for (int i = 0; i < ncities; i++) { items[i] = GenerateItem(i, unitycoord[i]); } }
/// <summary> /// Try to fight another object /// </summary> public virtual void TryToFight() { ProducerConsumer.Produce(String.Format("Object number {0} is looking for a fight!", Id)); // get all objects near the given object var dynamicObjects = BoardFunctions.GetNearObjects(X, Y, Agility); if (dynamicObjects.Count == 0) { ProducerConsumer.Produce(String.Format("Object number {0} found no one around him to fight", Id)); return; } // fight a random object int index = MyRandom.Next(0, dynamicObjects.Count); Fight(dynamicObjects[index]); }