Beispiel #1
0
        public SurvivalViewModel(float progress, Mission mission, Resource resource)
        {
            Progress = progress;
            Mission  = mission;
            Resource = resource;
            Minutes  = 0;
            SurvivalType type = (SurvivalType)(mission.MissionType);

            Seconds = Convert.ToInt32(Math.Round((Progress * (type.Time.Minute * 60 + type.Time.Second) / 100), MidpointRounding.ToEven));
        }
Beispiel #2
0
        public override void StartMission()
        {
            SurvivalType type = new SurvivalType();

            type = (SurvivalType)(Mission.MissionType);
            cancelTokenSource = new CancellationTokenSource();
            token             = cancelTokenSource.Token;
            timerTask         = new Task(() => Count());
            timerTask.Start();
        }
Beispiel #3
0
        public override void StopMission()
        {
            StopTimer();
            SurvivalType type = (SurvivalType)(Mission.MissionType);

            Progress = (float)(Minutes * 60 + Seconds) / (float)(type.Time.Minute * 60 + type.Time.Second) * 100;
            paused   = new PausedMission
            {
                Progress  = Progress,
                MissionId = Mission.Id
            };
            base.StopMission();
        }
Beispiel #4
0
        private void Count()
        {
            SurvivalType type = (SurvivalType)(Mission.MissionType);
            int          less = (type.Time.Minute * 60 + type.Time.Second) - (Minutes * 60 + Seconds);

            for (int i = 0; i <= less; i++)
            {
                Thread.Sleep(1000);
                if (token.IsCancellationRequested)
                {
                    return;
                }
                Seconds++;
            }
            StopMission();
            return;
        }