Example #1
0
        public void levelPassed()
        {
            // update max level passed
            PlayerPrefs.SetInt("MaxLevelPassed", Mathf.Max(PlayerPrefs.GetInt("MaxLevelPassed"), currentLevel));

            // level completed
            PlayerPrefs.SetInt(TBUtil.LevelNumberToKey(currentLevel), (int)PlayerPrefsLevelKey.Completed);
            PlayerPrefs.SetInt(TBUtil.LevelNumberToKey(currentLevel + 1), (int)PlayerPrefsLevelKey.Open);
        }
Example #2
0
        void UpdateOnceASecond()
        {
            foreach (KeyValuePair <int, ShipPatrolProperties> i in shipPatrolModel.shipPatrolPropertiesDict)
            {
                foreach (KeyValuePair <int, ShipPatrolProperties> j in shipPatrolModel.shipPatrolPropertiesDict)
                {
                    // do not compare the same ship against itself
                    if (i.Key <= j.Key)
                    {
                        continue;
                    }

                    // do the line sections of the ShipPatrols cross each other
                    bool lineSectionsCrossEachOther = TBUtil.LineSegmentsIntersect(
                        i.Value.getLineSection(true),
                        i.Value.getLineSection(false),
                        j.Value.getLineSection(true),
                        j.Value.getLineSection(false));

                    // if the ships' line section do not cross each other then continue and the boat can speed up again
                    if (!lineSectionsCrossEachOther)
                    {
                        i.Value.slowDownAvoidCrash = j.Value.slowDownAvoidCrash = false;
                        continue;
                    }

                    // if one of them is already slowed down then continue
                    if (i.Value.slowDownAvoidCrash || j.Value.slowDownAvoidCrash)
                    {
                        continue;
                    }

                    // decide randomly which ship should slow down
                    int instanceId = (Random.Range(0, 2) == 1 ? i.Key : j.Key);

                    // set the bool variable in the model
                    shipPatrolModel.shipPatrolPropertiesDict[instanceId].slowDownAvoidCrash = true;
                }
            }
        }
        public override void Execute()
        {
            // only do anything if the game is running
            if (gameModel.pauseStatus != PauseStatus.RUN)
            {
                return;
            }

            // cache the current inventory item
            InvItem currentInvItem = inventoryModel.getCurrentInvItem();

            // if the current invetory item is smoke bomb and the action is at the start phase then spawn one
            if (currentInvItem.id == InvItem.IDType.SmokeBombActive &&
                startOrStop &&
                smokeBombCircleModel.isTouchWithinEllipse(touchScreenPosition) &&
                TBUtil.IsTouchOnWater(touchScreenPosition) &&
                inventoryModel.smokeBombsLeft > 0)
            {
                smokeBombExplodeSignal.Dispatch(touchScreenPosition);
            }

            // embark or disembark submarine
            if (currentInvItem.id == InvItem.IDType.UBoat && startOrStop)
            {
                playerUBoatEmbarkSignal.Dispatch(!playerModel.isEmbarkedUBoat);
            }

            // mount bomb
            if (currentInvItem.id == InvItem.IDType.TimeBombActive)
            {
                timeBombMountingSignal.Dispatch(startOrStop);
            }

            // drill
            if (currentInvItem.id == InvItem.IDType.DrillActive)
            {
                drillingSignal.Dispatch(startOrStop);
            }
        }