public LightyButtonModel(ButtonIdentifier identifier) { this.ButtonIdentifier = identifier; this.buttonAction = new Subject <bool>(); this.Button = this.buttonAction.Select(value => new ButtonPressedEventArgs(this.ButtonIdentifier, value)); this.ButtonUp = this.buttonAction.Where(value => !value).Select(v => this.ButtonIdentifier); this.ButtonDown = this.buttonAction.Where(value => value).Select(v => this.ButtonIdentifier); }
private async void ChooseGame(ButtonIdentifier buttonPressed) { Log.Information($"Game chosen: {buttonPressed.Player} / {buttonPressed.Color}"); this.wakeupOrIdleSubscription.Dispose(); await this.Box.SetAll(false); Log.Information("Firing button pressed"); await this.stateMachine.FireAsync(this.buttonPressedWithParameter, buttonPressed); }
private async Task CreateAndStartGame(ButtonIdentifier button) { this.CleanRunningGame(); if (this.registeredGames.TryGetValue(button, out var gameFactory)) { Log.Information("Creating game..."); this.game = gameFactory(); } await this.StartGame(); }
private async void PlayerTwoButtonDown(ButtonIdentifier buttonIdentifier) { if (this.ignoreTwos) { return; } this.ignoreTwos = true; this.indexTwo = await this.HandlePlayerButton(buttonIdentifier, this.indexTwo, this.playerTwoButtons); await this.ProceedOrGameFinished(this.indexTwo, this.playerTwoButtons); this.ignoreTwos = false; }
private void ButtonDown(ButtonIdentifier buttonIdentifier) { switch (buttonIdentifier.Player) { case Player.One: this.PlayerOneButtonDown(buttonIdentifier); break; case Player.Two: this.PlayerTwoButtonDown(buttonIdentifier); break; default: throw new ArgumentOutOfRangeException(); } }
private async Task <int> HandlePlayerButton(ButtonIdentifier buttonIdentifier, int index, IEnumerable <ButtonIdentifier> buttonIdentifiers) { var color = this.GetColor(index); if (buttonIdentifier.Color == color) { // correct! Thus turn light off, increase index and turn next light on: await this.Box.Set(buttonIdentifier, false); index++; } else { await this.Box.Blink(buttonIdentifiers, 2, TimeSpan.FromMilliseconds(100)); } return(index); }
public void SetButtonCallback(ButtonIdentifier buttonIdentifier, System.Action <int> callback) { if (!initialized) { return; } if (callback == null) { return; } if (buttonCallbacks.ContainsKey((int)buttonIdentifier)) { buttonCallbacks[(int)buttonIdentifier] = callback; } else { buttonCallbacks.Add((int)buttonIdentifier, callback); } }
private async Task ButtonPressed(ButtonIdentifier identifier) { Log.Information("ButtonPressed: {@Identifier}", identifier); if (this.Status.ExpectedButton.Equals(identifier)) { // correct! :) this.Status.IncreaseInputIndex(); if (this.Status.InputIndex >= this.Status.Chain.Count) { // finished! await this.stateMachine.FireAsync(SimpleGameEvent.ChainCorrectlyRepeated); } } else { // wrong! :( await this.stateMachine.FireAsync(SimpleGameEvent.ChainWronglyRepeated); } }
public void setUpOptions(HackOptions[] options) { if (isMenuUp) { takeDownOptions(); } else { isMenuUp = true; //add the frame GameObject frame = Instantiate(optionFrameSprite); frame.transform.parent = transform; frame.transform.position = new Vector2( Input.mousePosition.x + xOffset, Input.mousePosition.y); tempHolder.Add(frame); for (int i = 0; i < options.Length; i++) { GameObject option = Instantiate(optionSprite); option.transform.parent = transform; option.transform.position = new Vector2( Input.mousePosition.x + xOffset, Input.mousePosition.y - distance * i + yOffset); tempHolder.Add(option); ButtonIdentifier Button = option.GetComponent <ButtonIdentifier>(); Button.HBH = this; Button.UE = options[i].optionFunctions; Button.transform.GetComponentInChildren <Text>().text = options[i].optionText; //} } } }
public void SetButtonCallback(ButtonIdentifier buttonIdentifier, System.Action<int> callback) { if(!initialized) return; if(callback == null) return; if(buttonCallbacks.ContainsKey((int)buttonIdentifier)) buttonCallbacks[(int)buttonIdentifier] = callback; else buttonCallbacks.Add((int)buttonIdentifier, callback); }
private static LightyButtonModel GetLightableButton(IBox box, ButtonIdentifier buttonIdentifier) { return(box[buttonIdentifier] as LightyButtonModel); }
private async void LightUp(ButtonIdentifier args) { await this.Box.Set(args, true); }
private async void LightOut(ButtonIdentifier args) { await this.Box.Set(args, false); }
public override ILightableButton this[ButtonIdentifier buttonIdentifier] => this.lookup[buttonIdentifier];
public override async Task Set(ButtonIdentifier button, bool enabled, TimeSpan?duration = null) { var lightableButton = this.lookup[button]; await lightableButton.SetLight(enabled, duration); }