void Update() { if (Input.GetMouseButtonDown(0)) { var ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; var didHit = Physics.Raycast(ray, out hit); if (didHit) { var ball = hit.collider.gameObject.GetComponent <IBall>(); if (ball == null) { return; } if (Controller == null) { Controller = Di.Get <IMouseManagerController>(); } Controller.BallClicked(ball); } } }
public void StartReaction(IBall original) { var config = Di.Get <IGameConfig>(); var all = new List <IBall>(GameController.BallCollection.Where(x => x.MaterialName == original.MaterialName)); var consumables = new List <IBall>(); var consumed = new List <IBall>(); consumables.Add(original); all.Remove(original); while (consumables.Count > 0) { var tester = consumables[0]; consumables.RemoveAt(0); consumed.Add(tester); for (int i = all.Count - 1; i > -1; i--) { var b = all[i]; var distance = Vector3.Distance(tester.TransformPosition, b.TransformPosition); if (distance > config.BallTouchRange) { continue; } consumables.Add(b); all.Remove(b); } } var score = 0f; var triggerIn = 0f; var reactorChoice = config.GetReactor(); IReactor reactor = null; foreach (var b in consumed) { if (reactorChoice == ReactorTypes.Fade) { reactor = b.GetComponent <IFadeReactor>(); } if (reactorChoice == ReactorTypes.Shrink) { reactor = b.GetComponent <IShrinkReactor>(); } if (reactorChoice == ReactorTypes.Slip) { reactor = b.GetComponent <ISlipReactor>(); } reactor.ActivateDestructionIn(triggerIn); triggerIn += config.TimeBetweenReactions; score += config.ScorePerBall; score *= config.CountMultiplier; } Di.Get <IScore>().TotalScore += (int)score; }
public void StartReaction_GivenRedBallWithAnotherRedBall_WillTriggerTwice() { // Arrange var moqGameController = new Mock <IGameController>(); var moqBallList = BallHelper.CreateMoqBallList(10); moqBallList = moqBallList.SetPositionsInRow(distance: 1f); moqBallList = moqBallList.SetAllMaterialNames("red"); moqBallList[0].SetupGet(x => x.MaterialName).Returns("blue"); moqBallList[1].SetupGet(x => x.MaterialName).Returns("blue"); var moqFade = new Mock <IFadeReactor>(); moqFade.Setup(x => x.ActivateDestructionIn(It.IsAny <float>())); moqBallList.SetReactorCommands(fade: moqFade); var ballList = moqBallList.CreateBallList(); moqGameController.SetupGet(x => x.BallCollection).Returns(ballList); Di.Bind <IGameController>().AsSingleton(moqGameController.Object); var moqGameConfig = new Mock <IGameConfig>(); moqGameConfig.SetupGet(x => x.BallTouchRange).Returns(1.5f); moqGameConfig.SetupGet(x => x.CountMultiplier).Returns(1.01f); moqGameConfig.SetupGet(x => x.ScorePerBall).Returns(1); moqGameConfig.SetupGet(x => x.TimeBetweenReactions).Returns(0.02f); moqGameConfig.Setup(x => x.GetReactor()).Returns(ReactorTypes.Fade); Di.Bind <IGameConfig>().AsSingleton(moqGameConfig.Object); var moqScore = new Mock <IScore>(); moqScore.SetupAllProperties(); Di.Bind <IScore>().AsSingleton(moqScore.Object); var ballController = Di.Get <IBallController>(); // Act ballController.StartReaction(ballList[0]); // Assert moqFade.Verify(x => x.ActivateDestructionIn(It.IsAny <float>()), Times.Exactly(2)); }
public void BallClicked(IBall ball) { Di.Get <IBallController>().StartReaction(ball); }