public override void TouchesMoved(NSSet touches, UIEvent evt) { base.TouchesMoved(touches, evt); UITouch touch = touches.AnyObject as UITouch; if (touch != null) { if (this.circle.Frame.Contains(touch.LocationInView(this.View))) { var x = touch.GetPreciseLocation(this.View).X; var y = touch.GetPreciseLocation(this.View).Y; if (this.circle.DistanceFromOrigin(x, y) > this.circle.GetRadius()) { // doesn't work var newPoint = this.circle.PointOnCircle(x, y); this.touchCircle.Frame = new CGRect(newPoint.X, newPoint.Y, 50, 50); } else { // works right this.touchCircle.Frame = new CGRect(x, y, 50, 50); } // doesn't work var distance = this.circle.DistanceFromOrigin(this.touchCircle.Frame.X, this.touchCircle.Frame.Y); var weight = this.circle.GetWeight(distance); var rollCommand = new RollCommand(255 * (int)weight, 0, false); this.BluetoothDevice.SendCommand(Peripheral, rollCommand); } } }
/// <summary> /// Add a roll command to the stack of commands /// </summary> public void InvokeRollCommand() { RollCommand cmd = new RollCommand(Context); CommandsStack.Push(cmd); //Update(); }
public ConsoleApplication( ILogger <ConsoleApplication> logger, IOptions <AppSettings> config, IrcClient client, IrcMessageParser ircParser, TwitchCommandParser commandParser, PingHandler pingHandler, CatfactsCommand catfactCommand, IssLocationCommand iisLocationCommand, ExchangeRateCommand exchangeRateCommand, UrbanDictionaryCommand urbanDictionaryCommand, BrbCommand brbCommand, HiMarkCommand hiMarkCommand, SoundsCommand SoundsCommand, RollCommand RollCommand, TestCommand testCommand) { _logger = logger; _config = config; _client = client; _ircParser = ircParser; _commandParser = commandParser; _pingHandler = pingHandler; commandObservers.Add(testCommand); commandObservers.Add(iisLocationCommand); commandObservers.Add(exchangeRateCommand); commandObservers.Add(catfactCommand); commandObservers.Add(brbCommand); commandObservers.Add(urbanDictionaryCommand); commandObservers.Add(hiMarkCommand); commandObservers.Add(SoundsCommand); commandObservers.Add(RollCommand); }
public override void TouchesEnded(NSSet touches, UIEvent evt) { base.TouchesEnded(touches, evt); // doesn't work this.touchCircle.Frame = new CGRect(this.circle.Frame.Width / 2 - 25, this.circle.Frame.Height / 2 - 25, 50, 50); var rollCommand = new RollCommand(0, 0, true); this.BluetoothDevice.SendCommand(Peripheral, rollCommand); }
/// <summary> /// Roll the shells /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void rollButton_Click(object sender, EventArgs e) { RollResult rr = RollCommand.NextResult(); GameApp.Instance.Turn.Context.RollResults.Add(rr); GameApp.Instance.Turn.Context.RollAgain = rr.IsRepeatable; // MessageBox.Show(rr.ToString(), "Result", MessageBoxButtons.OK, MessageBoxIcon.Information); rollButton.Enabled = GameApp.Instance.Turn.Context.RollAgain; UpdateResultsLabel(GameApp.Instance.Turn.Context); if (!GameApp.Instance.Turn.Context.RollAgain) { GameApp.Instance.Turn.Update(); } }
protected void DoRoll(CartesianPositionParameters positionParameters) { // TODO - put the check back in for 'too close' //if (Position.AbsoluteDistance < DistanceThreshold) //{ // return; //} Position = positionParameters; int headingDegrees = positionParameters.HeadingDegrees; var speed = (int)((SpeedService.SpeedPercent * positionParameters.AbsoluteDistance) / 100.0); SpheroTrace.Trace("Rolling to {0} with speed {1})", headingDegrees, speed); var rollCommand = new RollCommand(speed, headingDegrees, false); SendCommand(rollCommand); }
public ICommand BuildCommand(string command, IUser author, IMessageChannel channel, IGuild guild, params string[] parameters) { ICommand _command = null; switch (command) { case CommandNames.exit: _command = new ExitCommand(author, _config, channel, _messageWriter, _validationHandler, parameters); break; case CommandNames.update: _command = new UpdateCommand(author, _config, channel, _messageWriter, _validationHandler, parameters); break; case CommandNames.restart: _command = new RestartCommand(author, _config, channel, _messageWriter, _validationHandler, parameters); break; case CommandNames.help: _command = new HelpCommand(author, _config, channel, _messageWriter, _commandsInfo, _validationHandler, parameters); break; case CommandNames.version: _command = new VersionCommand(author, _config, channel, _messageWriter, _validationHandler, parameters); break; case CommandNames.random: _command = new RandomCommand(author, _config, channel, _messageWriter, _validationHandler, parameters); break; case CommandNames.github: _command = new GithubCommand(author, _config, channel, _messageWriter, _validationHandler, parameters); break; case CommandNames.uptime: _command = new UptimeCommand(author, _config, channel, _messageWriter, _validationHandler, parameters); break; case CommandNames.color: _command = new ColorCommand(author, _config, channel, _messageWriter, _validationHandler, parameters); break; case CommandNames.flipcoin: _command = new FlipcoinCommand(author, _config, channel, _messageWriter, _validationHandler, parameters); break; case CommandNames.roll: _command = new RollCommand(author, _config, channel, _messageWriter, _validationHandler, parameters); break; case CommandNames.purge: _command = new PurgeCommand(author, _config, channel, _messageWriter, _connectionHandler, _validationHandler, parameters); break; case CommandNames.summon: _command = new SummonCommand(author, _config, channel, _messageWriter, _audioService, guild, _validationHandler, parameters); break; case CommandNames.dismiss: _command = new DismissCommand(author, _config, channel, _messageWriter, _audioService, guild, _validationHandler, parameters); break; case CommandNames.play: _command = new PlayCommand(author, _config, channel, _messageWriter, _audioService, guild, _validationHandler, parameters); break; default: break; } return(_command); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button btnStart = FindViewById <Button> (Resource.Id.btnStart); Button btnStop = FindViewById <Button> (Resource.Id.btnStop); Button btnDisconnect = FindViewById <Button> (Resource.Id.btnDisconnect); SeekBar sbVelocity = FindViewById <SeekBar> (Resource.Id.sbVelocity); // If the adapter is null, then Bluetooth is not supported if (robotProvider == null) { Toast.MakeText(this, "RobotProvider is not available", ToastLength.Long).Show(); Finish(); return; } robotProvider.BroadcastContext = this; //Connect to the Robot robotProvider.RobotConnected += (object sender, RobotProvider.RobotConnectedEventArgs e) => { Console.WriteLine("Robot Connected :" + e.P0.BluetoothName); connected = true; }; robotProvider.RobotDisconnected += (object sender, RobotProvider.RobotDisconnectedEventArgs e) => { Console.WriteLine("Robot Disconnected, Bye :" + e.P0.BluetoothName); connected = false; }; robotProvider.RobotFound += (object sender, RobotProvider.RobotFoundEventArgs e) => { mRobot = e.P0; Console.WriteLine("Robot Found (YEAH!!):" + e.P0.BluetoothName); //robotProvider.EndDiscovery(); }; if (robotProvider.IsAdapterEnabled) { robotProvider.StartDiscovery(); robotProvider.FindRobots(); } else { Intent intent = robotProvider.AdapterIntent; this.StartActivityForResult(intent, 0); } btnStart.Click += delegate { //Set speed. 60% of full speed float speed = 0.60f; float heading = 0; sbVelocity.Progress = (int)(speed * 100); //Roll robot if (mRobot != null) { RollCommand.SendCommand(mRobot, heading, speed); } }; btnStop.Click += delegate { //Stop if (mRobot != null) { RollCommand.SendCommand(mRobot, 0, 0); } }; btnDisconnect.Click += delegate { //Stop It Dead if (mRobot != null) { RollCommand.SendStop(mRobot); } }; sbVelocity.ProgressChanged += (object sender, SeekBar.ProgressChangedEventArgs e) => { float vel = (float)(e.Progress / 100.0f); if (mRobot != null) { RollCommand.SendCommand(mRobot, 0, vel); } }; }
public Command ParseCommand(string commandInput) { var commandArguments = commandInput.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // first check if it's a valid command var length = commandArguments.Length; Command command = null; var action = commandArguments[0]; var parameters = commandArguments.Skip(1).ToList(); // make it with reflection, if you hate your life switch (action) { case "append": ValidateCommandLength(length, Constants.AppendCommandLength); command = new AppendCommand(parameters); break; case "prepend": ValidateCommandLength(length, Constants.PrependCommandLength); command = new PrependCommand(parameters); break; case "reverse": ValidateCommandLength(length, Constants.ReverseCommandLength); command = new ReverseCommand(parameters); break; case "insert": ValidateCommandLength(length, Constants.InsertCommandLength); command = new InsertCommand(parameters); break; case "delete": ValidateCommandLength(length, Constants.DeleteCommandLength); command = new DeleteCommand(parameters); break; case "roll": ValidateCommandLength(length, Constants.RollCommandLength); command = new RollCommand(parameters); break; case "sort": ValidateCommandLength(length, Constants.SortCommandLength); command = new SortCommand(parameters); break; case "count": ValidateCommandLength(length, Constants.CountCommandLength); command = new CountCommand(parameters); break; case "end": this.logger.Write(Constants.FinishedMessage); command = new EndCommand(parameters); break; default: throw new ArgumentException(Constants.InvalidCommand); } return(command); }