public void Update() { if (this.pairs.Count > 0) { for (int i = 0; i < this.pairs.Count; i++) { if (this.pairs[i].elapsedTime < 1f) { MoveTo(i); Scale(i, 0f, 1f); MergeUpdate(i); } else { MergePair pair = this.pairs[i]; if (pair.second != null) { Network.Destroy(pair.second); } if (pair.first != null) { Selectable select = pair.first.GetComponent <Selectable>(); if (select) { select.EnableSelection(); select.Deselect(); } Divisible div = pair.first.GetComponent <Divisible>(); if (div != null) { div.SetDivisible(false); } } if (pair.first == null || pair.second == null || pair.confirmedDestroyed) { this.pendingToRemove.Add(pair); break; } } } } if (this.pendingToRemove.Count > 0) { foreach (MergePair pair in this.pendingToRemove) { if (this.pairs.Contains(pair)) { Selectable select = pair.first.GetComponent <Selectable>(); if (select != null) { select.EnableSelection(); select.Deselect(); } this.pairs.Remove(pair); } } this.pendingToRemove.Clear(); } }
private void DivisibleInput() { if (this.playerNetworkView.isMine) { if (Input.GetKeyDown(KeyCode.S) && this.ownerSelectable.isSelected && this.isReady && (!this.ownerAttackable.isReadyToAttack || !this.ownerAttackable.isAttacking) && this.canDivide) { Analytics.Instance.AddEvent("S key pressed to split selected units. Count: " + Selectable.selectedObjects.Count.ToString()); for (int j = 0; j < Selectable.selectedObjects.Count; j++) { Selectable ownerSelectable = Selectable.selectedObjects[j]; if (ownerSelectable == null) { continue; } ownerSelectable.Deselect(); Divisible ownerDivisible = ownerSelectable.gameObject.GetComponent <Divisible>(); ownerDivisible.SetDivisibleNotReady(); for (int i = 0; i < this.numberOfUnitsPerSpawn; i++) { Vector3 spawnedLocation = ownerSelectable.gameObject.transform.position; GameObject unit = (GameObject)Network.Instantiate(Resources.Load("Prefabs/Player"), spawnedLocation, Quaternion.identity, 0); //Clones will not have parentheses around the remote node label (client, or server). unit.name = (Network.isClient ? "client " : "server ") + System.Guid.NewGuid(); HealthBar foo = unit.GetComponent <HealthBar>(); HealthBar bar = this.gameObject.GetComponent <HealthBar>(); if (foo != null && bar != null) { foo.currentHealth = bar.currentHealth; foo.maxHealth = bar.maxHealth; foo.healthPercentage = bar.healthPercentage; } Selectable spawnedSelectable = unit.GetComponentInChildren <Selectable>(); spawnedSelectable.Deselect(); ownerSelectable.Deselect(); if (!Debugging.debugEnabled) { NetworkView view = unit.GetComponent <NetworkView>(); if (this.playerNetworkView != null && view != null) { float randomValue = Random.Range(-180f, 180f); this.playerNetworkView.RPC("RPC_Add", RPCMode.AllBuffered, ownerSelectable.GetComponent <NetworkView>().viewID, view.viewID, randomValue); } } else { Debug.LogWarning("Debug flag is enabled."); } } } } } }
public void TestDivisibleBasic() { string expectedResult = "OUI"; int N = 6; string elements = "15478 8452 8232 874 985 4512"; string actualResult = ""; actualResult = Divisible.BasicImplementation(N, elements); Assert.AreEqual(expectedResult, actualResult); }
private void RPC_Add(NetworkViewID first, NetworkViewID second, float randomValue) { NetworkView firstView = NetworkView.Find(first); NetworkView secondView = NetworkView.Find(second); Divisible div = firstView.gameObject.GetComponent <Divisible>(); div.SetDivisibleNotReady(); div = secondView.gameObject.GetComponent <Divisible>(); div.SetDivisibleNotReady(); HealthBar foo = firstView.gameObject.GetComponent <HealthBar>(); HealthBar bar = secondView.gameObject.GetComponent <HealthBar>(); foo.Copy(bar); //Debug.Log((Network.isClient ? "(client)" : "(server)") + " is now making SpawnUnit struct object."); this.splitManager.spawnGroups.Add(new SpawnGroup(firstView.gameObject, secondView.gameObject, this.cooldownTimer, randomValue)); }
static void Main() { int number; //class instances Program program = new Program(); Divisible divisible = new Divisible(); ThirdDigit thirdDigit = new ThirdDigit(); IntToBinary intToBinary = new IntToBinary(); //convert user input from string to number string input = Console.ReadLine(); int.TryParse(input, out number); //output when calling method Console.WriteLine(intToBinary.FindBit(number)); Console.ReadLine(); Console.ReadLine(); }
private void Update() { if (this.spawnGroups.Count > 0) { for (int i = 0; i < this.spawnGroups.Count; i++) { MoveToPosition(i); Cooldown(i); UpdateGroup(i); } foreach (SpawnGroup group in this.spawnGroups) { if (group.elapsedTime > 1f) { this.remove.Add(group); } } } if (this.remove.Count > 0) { foreach (SpawnGroup group in this.remove) { Divisible div = group.owner.GetComponent <Divisible>(); if (!div.IsDivisibleStateReady()) { div.SetDivisibleReady(); } div = group.spawnedUnit.GetComponent <Divisible>(); if (!div.IsDivisibleStateReady()) { div.SetDivisibleReady(); } this.spawnGroups.Remove(group); } this.remove.Clear(); } }
private void AttackEnemies() { if (this.attackTargetUnits.Count > 0) { GameObject enemy = this.attackTargetUnits[0]; if (enemy == null) { this.attackTargetUnits.RemoveAt(0); return; } Selectable enemySelect = enemy.GetComponent <Selectable>(); if (enemySelect == null) { this.attackTargetUnits.RemoveAt(0); return; } if (enemySelect.UUID.Equals(this.selectable.UUID)) { this.attackTargetUnits.RemoveAt(0); return; } DeathCheck check = enemy.GetComponent <DeathCheck>(); if (check != null && !check.isDead) { if (Vector3.Distance(enemy.transform.position, this.gameObject.transform.position) <= 2.5f) { if (this.gameObject != null && enemy.gameObject != null) { BattlePair p = new BattlePair(this.gameObject, enemy); if (!DeathCheck.pairs.Contains(p)) { //TODO: Swap this to another script that keeps track of strength and HP. Attackable attack = enemy.GetComponent <Attackable>(); if (attack != null) { if (attack.attackCooldown <= 0f) { NetworkViewID viewID = enemy.GetComponent <NetworkView>().viewID; this.attackableNetworkView.RPC("RPC_DecreaseHealth", RPCMode.AllBuffered, viewID); HealthBar bar = enemy.GetComponent <HealthBar>(); Divisible div = enemy.GetComponent <Divisible>(); if (bar.currentHealth <= 0f || bar.healthPercentage <= 0f || !div.IsDivisibleStateReady()) { check.Kill(); DeathCheck.pairs.Add(p); } attack.attackCooldown = 1.414f; } else { attack.attackCooldown -= Time.deltaTime; } } } } } else { Vector3 unitVector = (enemy.transform.position - this.gameObject.transform.position).normalized; if (this.attackableNetworkView != null && !this.receivedAttackCommand) { this.receivedAttackCommand = true; this.attackableNetworkView.RPC("RPC_Attack", RPCMode.AllBuffered, this.gameObject.transform.position + unitVector); } } } } }
public void IsIsDivisible_DividingBy5_True() { Divisible testDivisible = new Divisible(15); Assert.AreEqual(true, testDivisible.IsDivisible()); }