コード例 #1
0
ファイル: CountDownTimer.cs プロジェクト: lebrice/Rewind
    // Update is called once per frame
    void Update()
    {
        if (Rewinding)
        {
            TimeLeft += Time.deltaTime;
        }
        else
        {
            TimeLeft -= Time.deltaTime;
        }

        if (TimeLeft < HurryUpThreshold && !hurryUpEventWasRaised)
        {
            OnHurryUp?.Raise();
            hurryUpEventWasRaised = true;
        }
        if (TimeLeft < 0 && !timerEndedEventWasRaised)
        {
            OnTimerEnded?.Raise();
            timerEndedEventWasRaised = true;
        }

        text.color = TimeLeft > HurryUpThreshold ? NormalColor : HurryUpColor;
        TimeLeft   = Mathf.Clamp(TimeLeft, 0, StartingTimeSeconds);
        text.text  = TimeLeft.ToString("0.00");
    }
コード例 #2
0
ファイル: DayBlock.xaml.cs プロジェクト: amrahm/Impromptu
        public DayBlock()
        {
            InitializeComponent();
            PropertyChanged += (sender, args) => {
                switch (args.PropertyName)
                {
                case nameof(TimeLeft):
                    TimeRemainingHeader.Text = Day == 0 ? "Time Remaining:" : "Total Time:";
                    TimeRemainingLabel.Text  = TimeLeft.ToString("#.#") + " hour" + (TimeLeft.ToString("#.#") == "1" ? "" : "s");
                    break;

                case nameof(DayName):
                    DayNameLabel.Text = DayName;
                    break;

                case nameof(Day):
                case nameof(Tasks):
                    TimeRemainingHeader.Text = Day == 0 ? "Time Remaining:" : "Total Time:";
                    for (int i = TasksLayout.Children.Count - 1; i >= 0; i--)
                    {
                        //Unsub from TouchedEvent
                        if (TasksLayout.Children[i] is TaskSlider task)
                        {
                            task.TouchedEvent -= WasTouched;
                        }
                        TasksLayout.Children.RemoveAt(i);
                    }
                    Constraint xConstraint = Constraint.Constant(0);
                    TasksLayout.Children.Add(new BoxView {
                        Color = Color.FromHex("#60000000"), HeightRequest = 1, Margin = 0
                    },
                                             xConstraint,
                                             Constraint.Constant(0),
                                             Constraint.RelativeToParent(parent => parent.Width));
                    if (Tasks != null)
                    {
                        for (int i = 0; i < Tasks.Count; i++)
                        {
                            TaskSlider taskSlider = Tasks[i];
                            taskSlider.TouchedEvent += WasTouched;
                            taskSlider.Day           = Day;
                            taskSlider.Priority      = i;
                            View last = TasksLayout.Children[TasksLayout.Children.Count - 1];
                            double PosAfterLastYConstraint(RelativeLayout parent, View view) => view.Y + view.Height + 10;

                            TasksLayout.Children.Add(taskSlider, xConstraint, Constraint.RelativeToView(last, PosAfterLastYConstraint));
                        }
                    }
                    break;
                }
            };
        }
コード例 #3
0
        public void SetTimeLeft()
        {
            if (TimeLeft == 0)
            {
                Active = false;
            }

            else
            {
                TimeLeft = TimeLeft - 1;
                if (TimeLeft <= 3)
                {
                    for (int i = 0; i < Subscribers.Count; i++)
                    {
                        Subscribers[i].Gavel("Time left: " + TimeLeft.ToString());
                    }
                }
            }
        }
コード例 #4
0
ファイル: AuctionHub.cs プロジェクト: IIMullahmetov/Auction
        public async Task <string> AuctionStart(string product_name)
        {
            IsRunning = true;
            Clients.Caller.DisableButtons();
            end            = Models.Timer.GetTimer();
            auctionInfo    = context.AuctionInfos.Where(a => a.Product == product_name).First();
            CurrentAuction = new Models.Auction()
            {
                AuctionStart = DateTime.Now, Price = 100, AuctionInfo = auctionInfo
            };
            Clients.All.ReceiveInfo(CurrentAuction.Price, "", auctionInfo.Product);
            while (TimeLeft > TimeSpan.Zero)
            {
                Clients.All.TimeReceiver(TimeLeft.ToString().Substring(0, 8));
                Thread.Sleep(1000);
            }
            string info;

            if (participant.Email == "")
            {
                info = "Никто не приобрел продукт " + CurrentAuction.AuctionInfo.Product;
                Models.Timer.ResetTimer();
                Clients.AllExcept(Context.ConnectionId).AuctionEnd(info);
                Clients.Caller.EnableButtons();
                return(info);
            }
            await End();

            info = new StringBuilder().Append("Пользователь ")
                   .Append(CurrentAuction.User.Email)
                   .Append(" приобрел ")
                   .Append(CurrentAuction.AuctionInfo.Product)
                   .Append(" за ")
                   .Append(CurrentAuction.Price)
                   .ToString();
            Clients.AllExcept(Context.ConnectionId).AuctionEnd(info);
            Clients.Caller.EnableButtons();
            return(info);
        }
コード例 #5
0
 private void Timer1_Tick(object sender, EventArgs e)
 {
     timeLabel.ForeColor = Color.White;
     timeLabel.Font      = new Font("Calibri", 25, FontStyle.Bold);
     timeLabel.BackColor = Color.Black;
     if (TimeLeft > 0)
     {
         if (!timeLabel.Visible)
         {
             timeLabel.Visible = true;
         }
         TimeLeft      -= 1;
         timeLabel.Text = TimeLeft.ToString();
     }
     else
     {
         timer1.Stop();
         timeLabel.Text    = "0";
         timeLabel.Visible = false;
         GameCycle.ChangeGame();
     }
 }
コード例 #6
0
 public override string ToString()
 {
     return(TimeLeft.ToString());
 }
コード例 #7
0
        public void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            string scoreHUDText = ScoreHUDCounter.ToString();
            string coinHUDText  = CoinHUDCounter.ToString();
            string worldHUDText = CurrentWorld.ToString() + "-" + CurrentStage.ToString();

            // Sets our timeCounter such that our HUD Timer decrements every half of a second.
            if (gameTime.TotalGameTime.Milliseconds % GameValues.HUDDrawDelay == 0 && !FreezeHUD)
            {
                if (timeCounter < TimerLife)
                {
                    if (timeCounter == GameValues.HUDTimeWarningAmount)
                    {
                        TimeIsLow = true;
                        SoundManager.Instance.PlayTimeWarning();
                    }
                    timeCounter++;
                }
                else
                {
                    new TimeUpCommand(GameStateMachine.Instance.PlayableObjects).Execute();
                }
            }

            string timerHUDText = "";

            if (GameStateMachine.Instance.GameState.ToString() == "SuperMario.GameStates.TimeScoreAnimationState")
            {
                timerHUDText = TimeLeft.ToString();
            }
            else if (GameStateMachine.Instance.GameState.ToString() == "SuperMario.GameStates.ExitGameState" || GameStateMachine.Instance.GameState.ToString() == "SuperMario.GameStates.GameWonState")
            {
                timerHUDText = GameValues.HUDEmptyTimeCounter;
            }
            else
            {
                timerHUDText = (TimerLife - timeCounter).ToString();
            }


            // Pads all our HUD values with 0's.
            for (int i = 1; scoreHUDText.Length < GameValues.HUDScoreMaxLength; i++)
            {
                scoreHUDText = "0" + scoreHUDText;
            }

            for (int i = 1; coinHUDText.Length < GameValues.HUDCoinMaxLength; i++)
            {
                coinHUDText = "0" + coinHUDText;
            }

            for (int i = 1; timerHUDText.Length < GameValues.HUDTimerMaxLength; i++)
            {
                timerHUDText = "0" + timerHUDText;
            }

            //if (GameStateMachine.Instance.GameState.ToString() == "SuperMario.GameStates.GameOverState")
            if (GameStateMachine.Instance.GameState.ToString() == "SuperMario.GameStates.MarioRespawnState")
            {
                if (!(Mario.Instance.Lives > GameValues.MarioStartingLives))
                {
                    UpdateGameStats(scoreHUDText, coinHUDText, worldHUDText, timerHUDText, Mario.Instance.Lives - 1);
                }
            }
            else if (GameStateMachine.Instance.GameState.ToString() == "SuperMario.GameStates.GameOverState" && gameOver)
            {
                UpdateGameStats(scoreHUDText, coinHUDText, worldHUDText, timerHUDText, Mario.Instance.Lives);
                gameOver = false;
            }

            scoreHUDText = "MARIO\n" + scoreHUDText;
            coinHUDText  = "\nx" + coinHUDText;
            worldHUDText = "WORLD\n  " + worldHUDText;
            timerHUDText = "TIME\n " + timerHUDText;

            Vector2 scoreHUDOrigin = HudFont.MeasureString(scoreHUDText) / 2;
            Vector2 coinHUDOrigin  = HudFont.MeasureString(coinHUDText) / 2;
            Vector2 worldHUDOrigin = HudFont.MeasureString(worldHUDText) / 2;
            Vector2 timerHUDOrigin = HudFont.MeasureString(timerHUDText) / 2;

            int xPositionPadding = (int)Position.X / 4;
            int yPositionPadding = (int)Position.Y;

            // Sets the distance between each line of text on the HUD.
            HudFont.LineSpacing = 3 * ((int)HudFont.MeasureString(scoreHUDText).Y / 7);

            sprite.UpdateSpritePosition(new Vector2(Position.X - HudFont.MeasureString(coinHUDText).X - xPositionPadding, yPositionPadding + 5));
            sprite.Draw(spriteBatch, gameTime);
            spriteBatch.DrawString(HudFont, scoreHUDText, new Vector2(Position.X - (3 * xPositionPadding), yPositionPadding), Color.White, 0, scoreHUDOrigin, 1.0f, SpriteEffects.None, 0.5f);
            spriteBatch.DrawString(HudFont, scoreHUDText, new Vector2(Position.X - (3 * xPositionPadding), yPositionPadding), Color.White, 0, scoreHUDOrigin, 1.0f, SpriteEffects.None, 0.5f);
            spriteBatch.DrawString(HudFont, coinHUDText, new Vector2(Position.X - xPositionPadding, yPositionPadding), Color.White, 0, coinHUDOrigin, 1.0f, SpriteEffects.None, 0.5f);
            spriteBatch.DrawString(HudFont, worldHUDText, new Vector2(Position.X + xPositionPadding, yPositionPadding), Color.White, 0, worldHUDOrigin, 1.0f, SpriteEffects.None, 0.5f);
            spriteBatch.DrawString(HudFont, timerHUDText, new Vector2(Position.X + (3 * xPositionPadding), yPositionPadding), Color.White, 0, timerHUDOrigin, 1.0f, SpriteEffects.None, 0.5f);
        }
コード例 #8
0
        public String GetScript()
        {
            StringBuilder sb = new StringBuilder();

            String scriptCallBackTimerDeclaration =
                #region Call Back Timer Public Declaration
                @"
//Define a custom object 'Timer' 
Timer = new Object();
Timer.Interval={0};
Timer.TimeOut={1};
Timer.TimeLeft={1};
Timer.SynchronizeStopWatch={2};
Timer.CountDown=
{{    
    Async:0,
    Sync:1    
}};
Timer.RefCallBackTimer;
Timer.RefCountDownTimer;
Timer.Display;                         
Timer.MilliSecond=0; 
Timer.Second=0; 
Timer.Minute=0; 
Timer.Hour=0;
Timer.IsPostBackOnTimeOut='{3}';
";

            #endregion

            //String Format Error: To work around the method, simply replace each curly brace "{" with double braces "{{".
            //After String.Format the double braces will be converted into single braces.
            scriptCallBackTimerDeclaration = String.Format(scriptCallBackTimerDeclaration, (Interval * 1000).ToString(), TimeLeft.ToString(), ServerSideTimeSynchronize ? 1 : 0, DoPostBackOnTimeOut.ToString().ToLower());

            String scriptCountDownTimer =
                #region Count Down Timer
                @"
Timer.Initialize=function()
{
   Timer.StopCountDownTimer();
   Timer.UpdateCountDownTimer();
   Timer.RefCountDownTimer=setTimeout('Timer.ShowCountDownTimer()',100);
   Timer.StopCallBackTimer();
   Timer.StartCallBackTimer();
} 

Timer.StopCountDownTimer=function()
{
    clearTimeout(Timer.RefCountDownTimer);
}

Timer.UpdateCountDownTimer=function ()
{    
    Timer.Hour=Math.floor(Timer.TimeLeft/3600);         
    Timer.Minute = Math.floor((Timer.TimeLeft -(Timer.Hour*3600)) / 60);
    Timer.Second = Timer.TimeLeft - ((Timer.Minute * 60)+(Timer.Hour*3600));
    Timer.MilliSecond=0;  

} 
Timer.ShowCountDownTimer = function()
{
if(Timer.Hour>0 || Timer.Minute>0 || Timer.Second>0)
{
    if (Timer.MilliSecond<=0)
    { 
        Timer.MilliSecond=9;    
        Timer.Second-=1;
        Timer.TimeLeft-=1; 
    } 
    else
	    Timer.MilliSecond-=1; 
    if (Timer.Second<=0)
    { 
        Timer.MilliSecond=9; 
        Timer.Second=59; 
        Timer.Minute-=1;
        Timer.TimeLeft-=1;
    } 
    if (Timer.Minute<=-1)
    {    
        Timer.Minute=59; 
        Timer.Hour-=1;   
    } 
    if(Timer.Hour<=-1)
    {
        Timer.MilliSecond=0; 
        Timer.Second=0;
        Timer.Minute=0;
        Timer.Hour=0;       
    }
}
else
{
   Timer.TimeLeft=-9;   
   if(Timer.IsPostBackOnTimeOut=='true')
    Timer.CallTimeOutHandler();
   else 
   Timer.CallServer();    
   Timer.StopCallBackTimer();
}

Timer.Display=document.getElementById('__DControls__Timer__Display');   
Timer.Display.innerHTML =Timer.Hour+':'+ Timer.Minute+':'+Timer.Second+'.'+Timer.MilliSecond;
if(Timer.TimeLeft>0)
    Timer.RefCountDownTimer=setTimeout('Timer.ShowCountDownTimer()',100);
else
{
if(Timer.IsPostBackOnTimeOut=='true')
    Timer.CallTimeOutHandler();
}
} 
";
            #endregion

            String scriptCallBackTimerMembers =
                #region Call Back Timer Members
                @"
Timer.CallTimeOutHandler=function()
{
    __doPostBack('TimeOutPostBack','-9');
}

Timer.StopCallBackTimer=function()
{
    clearTimeout(Timer.RefCallBackTimer);   
}

Timer.StartCallBackTimer=function()
{    
    if(Timer.TimeLeft>0)
    {        
        if(Timer.TimeLeft*1000<Timer.Interval || Timer.Interval<=0)
            Timer.RefCallBackTimer=window.setTimeout('Timer.CallServer()', Timer.TimeLeft*1000);
        else if(Timer.Interval>0)
            Timer.RefCallBackTimer=window.setTimeout('Timer.CallServer()', Timer.Interval);  
    }
    else
    {
        Timer.StopCallBackTimer();
    }
}

Timer.CallServer=function()
{
    CallTheServer(Timer.TimeLeft, ''); 
}

function ReceiveServerData(Result, context)
{  
    if(Timer.SynchronizeStopWatch==Timer.CountDown.Sync)
    {
        Timer.TimeLeft=Result;       
        Timer.Initialize();       
    }       
    else
    {
        Timer.StartCallBackTimer();
    }        
}

function ProcessCallBackError(arg, context)
{
    Timer.StopCallBackTimer();
    alert('Error : Call Back Method Failed'+'  Arg : '+arg+'   Context : '+context);
}

Timer.Initialize();
";
            #endregion

            //  sb.Append("<script type=\"text/javascript\">");
            if (DisableRightClick)
            {
                sb.Append("document.oncontextmenu = new Function('return false');");
            }
            sb.Append(scriptCallBackTimerDeclaration);
            sb.Append(scriptCountDownTimer.Replace("__DControls__Timer__Display", this.ClientID));
            sb.Append(scriptCallBackTimerMembers);
            //  sb.Append("</script>");

            return(sb.ToString());
        }
コード例 #9
0
 public string GetRestrictionText()
 {
     return("Time per turn: " + TimeLeft.ToString("0.00"));
 }
コード例 #10
0
ファイル: TaskSlider.xaml.cs プロジェクト: amrahm/Impromptu
        public TaskSlider()
        {
            InitializeComponent();
            PropertyChanged += (sender, args) => {
                switch (args.PropertyName)
                {
                case nameof(Priority):
                case nameof(Day):
                    switch (Priority)
                    {
                    case -1:
                        break;

                    case 0:
                        FilledColor = Color.FromHex("e04242");
                        EmptyColor  = Color.FromHex("ee9696");
                        break;

                    case 1:
                        FilledColor = Color.FromHex("de7b4a");
                        EmptyColor  = Color.FromHex("edb79c");
                        break;

                    case 2:
                        FilledColor = Color.FromHex("dead4a");
                        EmptyColor  = Color.FromHex("f0daad");
                        break;

                    default:
                        FilledColor = Color.FromHex("aead4a");
                        EmptyColor  = Color.FromHex("c0aa8d");
                        break;
                    }
                    double sideMargin = Priority * 10 + Day * 20;
                    Margin = new Thickness(sideMargin, -3);
                    double barHeight = DefaultSliderHeight - (Priority * 3 + Day * 5);
                    SliderView.HeightRequest = barHeight;
                    _shouldRedrawCircle      = true;
                    CanvasView.InvalidateSurface();
                    break;

                case nameof(TotalProgress):
                    CanvasView.InvalidateSurface();
                    break;

                case nameof(FilledColor):
                    _colorPaint.Color   = FilledColor.ToSKColor();
                    _shouldRedrawCircle = true;
                    CanvasView.InvalidateSurface();
                    break;

                case nameof(EmptyColor):
                    _lightColorPaint.Color = EmptyColor.ToSKColor();
                    _shouldRedrawCircle    = true;
                    CanvasView.InvalidateSurface();
                    break;

                case nameof(TimeLeft):
                    ETALabel.Text = "ETA: " + TimeLeft.ToString("#.#") + " hour" + (TimeLeft.ToString("#.#") == "1" ? "" : "s");
                    break;

                case nameof(Name):
                    NameLabel.Text = Name;
                    break;
                }
            };
        }