Пример #1
0
        private void ItemCollected()
        {
            if (--itemCount != 0)
            {
                PublisherSubscriber.Publish(new CollectedItemArgs()
                {
                    groundIndex      = currentGroundIndex,
                    currentItemCount = ++currentItemCount,
                    totalItemCount   = totalItemCount
                });
            }
            else
            {
                PublisherSubscriber.Publish(new CollectedItemArgs()
                {
                    groundIndex      = currentGroundIndex,
                    currentItemCount = 1,
                    totalItemCount   = 1
                });

                PublisherSubscriber.Publish(currentGroundIndex == 1
                    ? GameEventType.GroundCompleted
                    : GameEventType.LevelComplete);
            }
        }
Пример #2
0
 private void FindCollectibleItemCount()
 {
     PublisherSubscriber.Publish(new CollectibleItemArgs()
     {
         index = currentGroundIndex
     });
 }
Пример #3
0
 private void CheckPossibleMoveCount()
 {
     if (totalPossibleMoveCount == 0)
     {
         PublisherSubscriber.Publish(GameEventType.GameOver);
     }
 }
Пример #4
0
        public override void Construct(CharacterModel model, bool isLoad = false)
        {
            heroControllers = FindObjectsOfType <HeroController>().ToList();
            var heroModels = heroControllers.Select(controller => controller.HeroModel).ToList();

            enemyModel = model as EnemyModel;

            if (enemyModel == null)
            {
                Debug.Log("Enemy Model could not resolve in EnemyController");
                return;
            }

            if (!isLoad)
            {
                enemyModel.Construct(heroModels);
                enemyModel.CurrentHealth = enemyModel.Health;
            }

            characterGraphicsController.Construct(enemyModel.Sprite);

            healthBarController.Construct(enemyModel.name);
            PublisherSubscriber.Publish(new ProgressBarData
            {
                Id            = enemyModel.name,
                BarType       = ProgressBarType.HealthProgression,
                TotalAmount   = enemyModel.Health,
                CurrentAmount = enemyModel.CurrentHealth
            });
        }
Пример #5
0
        public void OnPointerUp(PointerEventData eventData)
        {
            currentScreenPosition = eventData.position;
            currentPosition       = cameraMain.GetWorldPositionIn3D(currentScreenPosition, -1f * cameraMain.transform.position.z);

            var distance = Vector3.Distance(initialPosition, currentPosition);

            if (distance >= 1f)
            {
                //Try to Swipe
                if (initialScreenPosition.x > currentScreenPosition.x)
                {
                    PublisherSubscriber.Publish(SwipeDirection.Left);
                }
                else
                {
                    PublisherSubscriber.Publish(SwipeDirection.Right);
                }
                return;
            }

            var hit = Physics2D.Raycast(initialPosition, cameraMain.transform.forward, Mathf.Infinity, layerToHit);

            if (hit.transform == null)
            {
                return;
            }
            if (hit.transform.GetComponent <GridItem>(out var gridItem))
            {
                gridItem.Select(hit.point);
            }
        }
Пример #6
0
        private void GameEventHandler(GameEventType gameEventType)
        {
            switch (gameEventType)
            {
            case GameEventType.GameStart:
                var level = playerData.GetLevel();
                currentGround1TransformIndex = (level - 1) % ground1Transforms.Length;
                currentGround2TransformIndex = (level - 1) % ground2Transforms.Length;

                LoadLevel();

                onGameStartEvent?.Invoke();
                PublisherSubscriber.Publish(GameEventType.LevelStart);
                break;

            case GameEventType.LevelStart:
                currentGroundIndex = 1;
                FindCollectibleItemCount();
                break;

            case GameEventType.ItemCollected:
                ItemCollected();
                break;

            case GameEventType.LevelComplete:
                playerData.SetLevel(playerData.GetLevel() + 1);
                playerData.SetGold(playerData.GetGold() + 50);
                PublisherSubscriber.Publish(GameEventType.GameStart);
                Debug.Log("Level Completed");
                break;

            case GameEventType.GroundCompleted:
                itemCount = 0;
                PublisherSubscriber.Publish(new GroundCompletedEventArgs()
                {
                    currentGroundIndex = currentGroundIndex
                });
                currentGroundIndex++;
                FindCollectibleItemCount();
                break;

            case GameEventType.IncrementCollectibleItemCount:
                currentItemCount = 0;
                itemCount++;
                totalItemCount = itemCount;
                break;

            case GameEventType.LevelReload:
                itemCount = 0;
                PublisherSubscriber.Publish(GameEventType.GameStart);
                break;

            default:
                //do nothing;
                break;
            }
        }
Пример #7
0
 private void GameEventHandler(GameEventType gameEventType)
 {
     if (gameEventType != GameEventType.UpdateMoveCount)
     {
         return;
     }
     countdown--;
     text.text = countdown.ToString();
     if (countdown == 0)
     {
         PublisherSubscriber.Publish(GameEventType.GameOver);
     }
 }
Пример #8
0
 private void Start()
 {
     playerCollider = GetComponent <SphereCollider>();
     playerCollider.OnCollisionEnterAsObservable().Subscribe(collision =>
     {
         if (!collision.collider.GetComponent <IGetColor>(out var getColor))
         {
             return;
         }
         if (getColor.GetColor() != playerGraphicsController.GetColor())
         {
             PublisherSubscriber.Publish(GameEventType.LevelFailed);
         }
     });
 }
Пример #9
0
        public void Generate()
        {
            ClearGridItems();

            ClearRemainingChildren();

            CalculateScreenView();
            CalculateScaleFactor();
            CalculateStartingPosition();

            if (gridItemTransforms == null)
            {
                gridItemTransforms = new List <Vector3>();
            }
            gridItemTransforms.Clear();

            for (var i = 0; i < gridRowCount; i++)
            {
                for (var j = 0; j < gridColumnCount; j++)
                {
                    var tempItem = Instantiate(gridItemPrefab);
                    tempItem.name = $"GridItem [{i},{j}]";

                    var tempItemTransform = tempItem.transform;
                    tempItemTransform.position   = startingPosition + CalculatePosition(i, j);
                    tempItemTransform.localScale = Vector3.one * scaleFactor;
                    tempItemTransform.SetParent(transform);

                    gridItemTransforms.Add(tempItemTransform.position);

                    var tempGridItem = tempItem.GetComponent <GridItem>();
                    tempGridItem.Deselect();
                    tempGridItem.Position = new GridPosition()
                    {
                        rowPosition    = i,
                        columnPosition = j
                    };

                    gridItems.Add(tempGridItem);
                }
            }

            PublisherSubscriber.Publish(GameEventType.CheckNeighbors);
        }
Пример #10
0
        public override void Attack()
        {
            var initialPosition = transform.position;

            var randomIndex            = Random.Range(0, heroControllers.Count);
            var selectedHeroController = heroControllers[randomIndex];

            while (selectedHeroController.HeroModel.CurrentHealth <= 0f)
            {
                heroControllers.RemoveAt(randomIndex);
                randomIndex            = Random.Range(0, heroControllers.Count);
                selectedHeroController = heroControllers[randomIndex];
            }

            TimeSystem.CreateTimer(
                $"{enemyModel.name}'s Attack",
                1f,
                new []
            {
                new TimerActionData
                {
                    ActionType  = TimerActionType.OnStart,
                    TimerAction = () =>
                    {
                        transform.DOMove(selectedHeroController.transform.position, 0.5f).OnComplete(() =>
                        {
                            selectedHeroController.TakeDamage(enemyModel.AttackPower);
                            transform.DOMove(initialPosition, 0.5f).OnComplete(() =>
                            {
                                PublisherSubscriber.Publish(GameEventType.EnemyFinishedTurn);
                            });
                        });
                    }
                }
            }
                );
        }
Пример #11
0
        public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
        {
            if (placementId != rewardedAdPlacementId)
            {
                return;
            }
            switch (showResult)
            {
            case ShowResult.Failed:
                //do nothing.
                break;

            case ShowResult.Skipped:
                PublisherSubscriber.Publish(GameEventType.LevelReload);
                break;

            case ShowResult.Finished:
                //do nothing.
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(showResult), showResult, null);
            }
        }
Пример #12
0
 public void NoThanks()
 {
     //Do some Inter ad action;
     PublisherSubscriber.Publish(GameEventType.LevelReload);
 }
Пример #13
0
 public void Continue()
 {
     //Do some rewarded ad action;
     PublisherSubscriber.Publish(GameEventType.LevelContinue);
 }
Пример #14
0
 private void Start()
 {
     PublisherSubscriber.Publish(GameEventType.GameStart);
 }
Пример #15
0
 // ReSharper disable once ParameterHidesMember
 public void ChangeGameState(GameState gameState)
 {
     this.gameState = gameState;
     PublisherSubscriber.Publish(this.gameState);
 }