Exemplo n.º 1
0
 private void PrintAlert(CountdownItem item, TimeSpan alerttime, CountdownState state = CountdownState.PreCountdown)
 {
     if (item == CountdownItem.Empty)
     {
         OnMessageEvent($"No badimes queued.  Currently Idle.");
     }
     if (state == CountdownState.PostCountdown)
     {
         OnMessageEvent($"{item.Title} elapsed time is {DateTime.Now - item.Epoch}");
     }
     else if (state == CountdownState.PreCountdown)
     {
         if (alerttime >= TimeSpan.FromSeconds(10))
         {
             OnMessageEvent($"{item.Title} in {alerttime}");
         }
         else if (alerttime == TimeSpan.FromSeconds(0))
         {
             OnMessageEvent($"{item.Title} starting!");
         }
         else
         {
             OnMessageEvent($"{alerttime.TotalSeconds}");
         }
     }
     else
     {
         OnMessageEvent($"{item.Title} starting!");
     }
     //OnMessageEvent($"{item.Title} in {alerttime}");
 }
Exemplo n.º 2
0
    private void Start()
    {
        CountdownState countDownState = new CountdownState();
        State          game           = new TriggeringLambdaState <Trigger>(
            name: "game",
            onStateEnter: () =>
        {
            GameManager.Instance.ShowScoreUI();
            GameManager.Instance.RestartGame();
            return(null);
        });
        State scoreScreen = new LambdaState(
            name: "score screen",
            onStateEnter: () =>
        {
            int score = GameManager.Instance.Score;
            GameManager.Instance.HideScoreUI();
            GameManager.Instance.Reset();
            GameManager.Instance.gameObject.SetActive(false);
            this.scoreScreen.SetScore(score);
            this.scoreScreen.gameObject.SetActive(true);
        });

        countDownState.Text = scoreText;

        sm.AddEntryState(countDownState);
        sm.AddState(game);
        sm.AddState(scoreScreen);

        sm.AddTransition(countDownState, game, sm.CreateTriggerCondition(Trigger.NextState));
        sm.AddTransition(game, scoreScreen, sm.CreateTriggerCondition(Trigger.NextState));

        sm.Start();
    }
Exemplo n.º 3
0
        /// <summary>
        /// 只管秒数更替,不关注事件执行(关注了也执行不了。。。)
        /// </summary>
        private void _Tick()
        {
            lock (dic_countdown)
            {
                foreach (KeyValuePair <string, Countdown> _kv in dic_countdown)
                {
                    CountdownState state = _kv.Value.Tick();
                    //Debug.Log("UIClock正在tick  " + _kv.Key + "  " + state.ToString() + "  剩余秒数" + _kv.Value.seconds + "  单位剩余秒数" + _kv.Value.countdown_unit);
                    switch (state)
                    {
                    case CountdownState.Normal:
                        break;

                    case CountdownState.UnitReachEnd:
                        queue_updating.Enqueue(_kv.Value);
                        break;

                    case CountdownState.End:
                        queue_updating.Enqueue(_kv.Value);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 /// <returns>0:正常计数,1:已经走完一个单位,需要执行更新,-1:到达计时终点</returns>
 public CountdownState Tick()
 {
     state = CountdownState.Normal;
     if (seconds < 1)
     {
         state = CountdownState.End;
     }
     else
     {
         countdown_unit--;
         if (countdown_unit < 1)
         {
             countdown_unit = unit;
             if (laps < 1)
             {
                 //启动的首次刷新
             }
             else
             {
                 seconds -= unit;
             }
             laps++;
             state = CountdownState.UnitReachEnd;
         }
     }
     return(state);
 }
Exemplo n.º 5
0
        public GameMain()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory    = "Content";
            Window.AllowUserResizing = false;
            graphics.IsFullScreen    = true;
            Resolution.Init(ref graphics);
            Resolution.SetVirtualResolution(VIRTUAL_WIDTH, VIRTUAL_HEIGHT);

            Resolution.SetResolution(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width,
                                     GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height, true);

            gameStateManager = new GameStateManager(this);
            Components.Add(gameStateManager);

            TitleScreenState = new TitleScreenState(this);
            PlayState        = new PlayState(this);
            ScoreState       = new ScoreState(this);
            CountdownState   = new CountdownState(this);
            gameStateManager.ChangeState((TitleScreenState)TitleScreenState);

            Components.Add(new InputHandler(this));

            Window.ClientSizeChanged += new EventHandler <EventArgs>(Resize);
        }
Exemplo n.º 6
0
        public void Last_ReturnsFalseWhenEventsLess()
        {
            //Arrange
            Number         events       = new NumberOf(10);
            Number         counterValue = new NumberOf(11);
            MockCounter    mockCounter  = new MockCounter.Builder().Value(counterValue).Build();
            CountdownState subject      = new CountdownState(events, mockCounter);

            //Act
            bool actual = subject.Last();

            //Assert
            actual.Should().BeFalse();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Main countdown thread.
        /// </summary>
        private void CountdownThread()
        {
            while (ct.IsCancellationRequested == false)
            {
                switch (_state)
                {
                case CountdownState.Idle:
                    // Idle loop (waiting for items)
                    while (ct.IsCancellationRequested == false)
                    {
                        lock (_lockobject)
                        {
                            if (CountdownList.Count != 0)
                            {
                                _state = CountdownState.PreCountdown;
                                break;
                            }
                        }
                        System.Threading.Thread.Sleep(1000);
                    }
                    break;

                case CountdownState.PreCountdown:
                    CountdownItem _nextItem;
                    lock (_lockobject)
                    {
                        _nextItem = CountdownList.Dequeue();
                    }
                    _nextItem.Epoch = DateTime.Now.Add(_nextItem.PreCountdown);
                    CurrentItem     = _nextItem;

                    // This moves our alert index forward to where we initially should be
                    int _alertIndex = 0;
                    for (int i = 0; i < Alerts.Length; i++)
                    {
                        if (Alerts[i] <= CurrentItem.PreCountdown)
                        {
                            _alertIndex = i;
                            break;
                        }
                    }
                    // Main pre-countdown loop.
                    while (ct.IsCancellationRequested == false)
                    {
                        if ((CurrentItem.Epoch - DateTime.Now) < Alerts[_alertIndex])
                        {
                            // alart
                            //Console.WriteLine($"{(CurrentItem.Epoch - DateTime.Now).TotalSeconds} < {Alerts[_alertIndex]}");
                            PrintAlert(CurrentItem, Alerts[_alertIndex]);
                            if (_alertIndex == Alerts.Length - 1)
                            {       // Ran out of alerts, less than one second left
                                _state = CountdownState.PostCountdown;
                                break;
                            }
                            _alertIndex++;
                        }
                        System.Threading.Thread.Sleep(100);
                    }
                    break;

                case CountdownState.PostCountdown:
                    if (DateTime.Now > (CurrentItem.Epoch + CurrentItem.Length))
                    {
                        lock (_lockobject)
                        {
                            if (CountdownList.Count == 0)
                            {
                                // no more things to countdown
                                _state      = CountdownState.Idle;
                                CurrentItem = CountdownItem.Empty;
                                OnMessageEvent("THE END N SHIT");
                            }
                            else
                            {
                                // Move to next anime  (PreCountdown will dequeue)
                                _state = CountdownState.PreCountdown;
                            }
                        }
                    }
                    // Long sleep
                    System.Threading.Thread.Sleep(1000);
                    break;
                }
            }
            // end of loop
        }