public TV() { OffState = new OffState(this); OnState = new OnState(this); StandbyState = new StandbyState(this); StartState = new StartState(this); currentState = OffState; }
public static void Run() { // The TV's remote control is an ISignalling<Tuple<TVEvent, int>>, // and also an IObservable<Tuple<TVEvent, int>> (see Simulation 4 below): ISignalling<TVEvent, int> remote = new TVRemote(); // The TV is in fact an IMachine<TVState, TVStatus, TVEvent, int>, // here shortened to its base type IMachine<TVStatus> for simple enumeration purpose: IMachine<TVStatus> television = new Television(); // The state of the TV is in fact an IState<TVStatus, TVEvent, int>, // here shortened to its base type IState<TVStatus> for simple enumeration purpose: IState<TVStatus> state = new TVState(); // Enumerating over the IEnumerable<TVEvent> (SampleSimulation1), // which is the source of triggers for state transitions: Console.WriteLine("Simulation 1:"); foreach (TVStatus value in state.Using(SampleSimulation1).Start(TVStatus.Unplugged)) ;// not interested in doing anything special after each successful transition... // Enumerating over the IEnumerable<TVEvent> (SampleSimulation2), // which is the source of triggers for state transitions: Console.WriteLine("Simulation 2:"); foreach (TVStatus value in state.Using(SampleSimulation2).Start(TVStatus.Unplugged)) // Just echo the state that we transitioned TO on the console: Console.WriteLine("\t{0}", value); // Anti-pattern: // this coding style does work but isn't recommended: Console.WriteLine("Simulation 3:"); if (!state.Start(TVStatus.Unplugged).IsFinal) { Console.WriteLine("\t... Done? {0}", state.IsFinal); if (state.Consume(TVEvent.Plug) && !state.IsFinal) { Console.WriteLine("\t... Done? {0}", state.IsFinal); if (state.Consume(TVEvent.SwitchOn) && !state.IsFinal) { Console.WriteLine("\t... Done? {0}", state.IsFinal); if (state.Consume(TVEvent.SwitchOff) && !state.IsFinal) { Console.WriteLine("\t... Done? {0}", state.IsFinal); if (state.Consume(TVEvent.Destroy) && !state.IsFinal) Console.WriteLine("(not executed)"); else Console.WriteLine("\t... Done? {0}", state.IsFinal); } } } } Console.WriteLine("Simulation 4:"); // Ensure we are back in the start state: state = television.Using(remote).Start(TVStatus.Unplugged); // Now use the various remote control's Emit signatures: remote.Emit(TVEvent.Plug); remote.Emit(TVEvent.SwitchOn, 1); remote.Emit(new Tuple<TVEvent, int>(TVEvent.SwitchOff, 2)); remote.Emit(new KeyValuePair<TVEvent, int>(TVEvent.Unplug, 3)); remote.Emit(TVEvent.Destroy, 4); }
public override void Initialize() { if (this._testMode) { this._endOfHighlights = true; Options.Data.sfxVolume = 0.0f; DuckStory duckStory = new DuckStory(); duckStory.text = "|SUAVE||RED|John Mallard|WHITE| here dancing|CALM| for you |EXCITED|and wearing ties!"; HighlightLevel._stories = new List <DuckStory>(); for (int index = 0; index < 9999; ++index) { HighlightLevel._stories.Add(duckStory); } } HighlightLevel._cancelSkip = false; this._tv = new Sprite("bigTV"); this._duck = new SpriteMap("newsDuck", 140, 100); this._duckBeak = new SpriteMap("newsDuckBeak", 140, 100); this._tie = new SpriteMap("ties", 12, 21); this._pumpkin = new Sprite("pump"); this._pumpkin.CenterOrigin(); this._newsTable = new Sprite("newsTable"); this._logo = new Sprite("duckGameTitle"); this._logo.CenterOrigin(); this._background = new Sprite("duckChannelBackground"); this._blurLayer = new Layer("BLUR", Layer.HUD.depth + 5, Layer.HUD.camera); Layer.Add(this._blurLayer); this._blurLayer.effect = Content.Load <Effect>("Shaders/blur"); this._transition = new DuckChannelLogo(); Level.Add((Thing)this._transition); this._tl = new Vec2(30f, 32f); this._size = new Vec2(207f, 141f); this._rockImage2 = new Sprite(RockScoreboard.finalImage, 0.0f, 0.0f); this._talker = new Teleprompter(0.0f, 0.0f, this._duck); this._talker.active = this._talker.visible = false; Level.Add((Thing)this._talker); if (HighlightLevel.didSkip) { this._skip = true; } if (this._endOfHighlights) { this._state = TVState.ShowNewscaster; this._desiredState = this._state; } else { HighlightLevel._image = (Sprite)null; HighlightLevel.currentTie = Rando.Int(15); Music.Play("SportsCap"); HighlightLevel._stories = DuckNews.CalculateStories(); } this._hotness = new HotnessAnimation(); this._tie.frame = HighlightLevel.currentTie; for (int index = 0; index < HighlightLevel._stories.Count; index = index - 1 + 1) { bool flag = HighlightLevel._stories[index].text == "%CUEHIGHLIGHTS%"; if (HighlightLevel._stories[index].text == "CUE%HOTNESSIMAGE%") { HighlightLevel._stories[index].OnStoryBegin += new DuckStory.OnStoryBeginDelegate(this.OnHotnessImage); } if (HighlightLevel._stories[index].text == "CUE%CUEHOTNESS%") { HighlightLevel._stories[index].OnStoryBegin += new DuckStory.OnStoryBeginDelegate(this.OnHotnessStory); } if (HighlightLevel._stories[index].text == "CUE%ENDHOTNESS%") { HighlightLevel._stories[index].OnStoryBegin += new DuckStory.OnStoryBeginDelegate(this.OnHotnessEnd); } if (HighlightLevel._stories[index].text == "CUE%INTERVIEWIMAGE%") { HighlightLevel._stories[index].OnStoryBegin += new DuckStory.OnStoryBeginDelegate(this.OnInterviewImage); } if (HighlightLevel._stories[index].text == "CUE%CUEINTERVIEW%") { this._interviewIndex = index; HighlightLevel._stories[index].OnStoryBegin += new DuckStory.OnStoryBeginDelegate(this.OnInterview); } if (!flag) { this._talker.ReadLine(HighlightLevel._stories[index]); } HighlightLevel._stories.RemoveAt(index); if (flag) { break; } } Vote.OpenVoting("SKIP", "START"); }
public void OnInterview(DuckStory story) { story.OnStoryBegin -= new DuckStory.OnStoryBeginDelegate(this.OnHotnessStory); this._desiredState = TVState.ShowInterview; this._talker.Pause(); }
public void OnHotnessEnd(DuckStory story) { story.OnStoryBegin -= new DuckStory.OnStoryBeginDelegate(this.OnHotnessEnd); this._desiredState = TVState.ShowNewscaster; HighlightLevel._image = (Sprite)null; }
public override void Update() { if (this._testMode) { this._wait += Maths.IncFrameTimer(); if (Keyboard.Pressed(Keys.F5) || (double)this._wait > 0.1) { this._wait = 0.0f; try { this._tie = new SpriteMap((Tex2D)ContentPack.LoadTexture2D("tieTest.png"), 64, 64); this._tie.center = new Vec2(26f, 27f); } catch (Exception ex) { } } } DuckGame.Graphics.fadeAdd = Lerp.Float(DuckGame.Graphics.fadeAdd, 0.0f, 0.01f); if (Main.isDemo && this._skip && !this._firedSkipLogic) { this._firedSkipLogic = true; Vote.CloseVoting(); HUD.CloseAllCorners(); this.DoSkip(); } if ((double)DuckGame.Graphics.fade > 0.990000009536743 && !this._skip && Vote.Passed(VoteType.Skip)) { this._skip = true; } if (this._talker.finished || !HighlightLevel._cancelSkip && this._skip && !Main.isDemo) { this._done -= 0.04f; } DuckGame.Graphics.fade = Lerp.Float(DuckGame.Graphics.fade, (double)this._done < 0.0 ? 0.0f : 1f, 0.02f); if ((double)DuckGame.Graphics.fade < 0.00999999977648258 && (this._talker.finished || this._skip)) { if (this._endOfHighlights || this._skip) { Vote.CloseVoting(); Level.current = (Level) new RockScoreboard(RockScoreboard.returnLevel, ScoreBoardMode.ShowWinner, true); } else { Level.current = (Level) new HighlightPlayback(4); } } if (this._state == TVState.ShowPedestals) { this._waitZoom -= 0.008f; if ((double)this._waitZoom < 0.00999999977648258) { this._waitZoom = 0.0f; this._desiredState = TVState.ShowNewscaster; } } if (this._state == TVState.ShowHotness && this._hotness.ready) { this._talker.Resume(); } if (this._state == TVState.ShowInterview) { this._interviewWait -= 0.02f; if ((double)this._interviewWait < 0.0 && !this._askedQuestion) { this._talker.InsertLine(Script.winner() + "! To what do you attribute your success?", this._interviewIndex); this._talker.Resume(); this._askedQuestion = true; } } this._cameraOffset.x = Lerp.Float(this._cameraOffset.x, HighlightLevel._image != null ? 20f : 0.0f, 2f); this._talker.active = this._talker.visible = this._state != TVState.ShowPedestals; if (this._state == this._desiredState) { return; } this._talker.active = false; this._transition.PlaySwipe(); if (!this._transition.doTransition) { return; } this._state = this._desiredState; }
/// <summary> /// 刷新电视 /// </summary> /// <param name="tvSN">电视序列号</param> /// <param name="state">电视状态</param> public void RefreshTV(string tvSN, TVState state) { foreach (var tV in MockTVs) { if (tV.Sn.Equals(tvSN)) { tV.LastConnectTime = DateTime.Now; tV.State = state; } } }
public void SetState(TVState tVState) { currentState = tVState; Console.WriteLine($"State changed to \"{tVState}\""); }
public TVHeartBeatEventArgs(string tvSN, TVState state) { TVSn = tvSN; State = state; }
/// <summary> /// 设置电视机状态 /// </summary> /// <param name="state"></param> public void SetState(TVState state) { var msg = BuildActionSignal(ActionType.HIBERNATE); SendMessage(msg); }
private void Initial() { conTimes = 0; //conTimes:ContinuousTimes in Web.Config conPeriod = 0; //conPeriod:ContinuousPeriodInSecond in Web.Config sleepInterval = 0; //sleepInterval:MonitorIntervalInMilliSecond in Web.Config isMonitoring = false; //isMonitoring indicates whether start monitoring. true: Monitoring, false: Not Monitoring Timer1.Enabled = false; lastCapture = false; //lastCapture indicates whether capture a photo last time. true: Captured last time, false: Not Captured last time curCaptureTimes = 0; //curCaptureTimes indicates the current continuously times when capture a photo. firstCaptureTime = DateTime.Now; //firstCaptureTime indicates the time when the first capture happened in continuous captures //capturePeriod = new TimeSpan(); //capturePeriod indicates the TimeSpan of continuous captures tvState = TVState.OFF; lastTime = DateTime.Now; personId = string.Empty; personName = string.Empty; imageUrl = string.Empty; }
protected void btnTV_Click(object sender, EventArgs e) { try { if (tvState == TVState.OFF) { tvState = TVState.ON; firstCaptureTime = DateTime.Now; } else { tvState = TVState.OFF; curCaptureTimes = 0; } DisplayInfo(); } catch(Exception exc) { lblException.Text = exc.Message; } //DisplayInfo(); }