public ListeningState(ICommunicationDeviceAsync device, IDataStreamSplitter streamSplitter, CommandTranslator commandTranslator) { _device = device; _streamSplitter = streamSplitter; _commandTranslator = commandTranslator; }
private static void Main(string[] args) { string input = string.Empty; var translator = new CommandTranslator(); Grid grid = new Grid(10, 10, new Position(0, 0)); DirectionMove direction = new DirectionMove(grid); OrientationMove orientation = new OrientationMove(); var movementService = new MovementService(grid, direction, orientation); var rover = new Rover(movementService); PrintStatus(movementService); while (input != "x") { input = Console.ReadLine(); var command = translator.Parse(input); var result = rover.Move(command); if (result.IsFail) { Console.WriteLine("Obstacle detected."); } PrintStatus(movementService); } }
public void Close() { m_client.Close(); m_cmdTranslator.Dispose(); m_cmdTranslator = null; foreach (ProfilePluginConfiguration config in m_activePlugins.Keys) { IJinxBotPlugin plugin = m_activePlugins[config]; IMultiClientPlugin mcp = plugin as IMultiClientPlugin; if (mcp != null) { mcp.RemoveClient(this); } ISingleClientPlugin scp = plugin as ISingleClientPlugin; if (scp != null) { scp.UnregisterEvents(this); scp.DestroyPluginWindows(this.ProfileDocument); } PluginFactory.ClosePluginInstance(config, plugin); JinxBotConfiguration.Instance.Save(); } }
public void Translate_CommandWasFound_ReturnInstance() { var command = new CommandTranslator(Mock.Of <ILoggerFactory>()).Translate(service: "movistar", command: "datos"); Assert.IsNotNull(command); Assert.IsNull(command.Response); Assert.IsInstanceOfType(command, typeof(MovistarDataUsageCommand)); }
/// <summary> /// Receives the events and translates them into Game Commands. /// </summary> /// <param name="EventType">Event type.</param> /// <param name="sender">Sender.</param> /// <param name="param">Parameter.</param> public void OnEvent(EVENT_TYPE EventType, Component sender, object param = null) { GameCommand gameCommand = CommandTranslator.TranslateEventToGameCommand(EventType, sender, param); if (gameCommand != null) { SendCommand(gameCommand); } }
public void When_Rover_Extends_Solar_Panel_Battery_Is_Charged_And_Battery_Is_Consumed() { var startingPosition = new Position(1, 1, Direction.East); var startingBattery = 10; var coordinates = CreateMap(1, 1); var testMap = new PlanetMap(coordinates); ICommandTranslator commandTranslator = new CommandTranslator(); var rover = new Rover(startingPosition, startingBattery, testMap, commandTranslator); rover.RunCommands("E"); rover.BatteryCharge.ShouldBe(startingBattery - 1 + 10); }
public void When_Rover_Turns_Facing_Direction_New_Direction_Is_Expected_And_Battery_Is_Consumed(Direction startDirection, Direction expectedDirection, string command, int batteryExpense) { var startingPosition = new Position(1, 1, startDirection); var startingBattery = 10; var coordinates = CreateMap(1, 1); var testMap = new PlanetMap(coordinates); ICommandTranslator commandTranslator = new CommandTranslator(); var rover = new Rover(startingPosition, startingBattery, testMap, commandTranslator); rover.RunCommands(command); rover.CurrentPosition.Facing.ShouldBe(expectedDirection); rover.BatteryCharge.ShouldBe(startingBattery - batteryExpense); }
public void When_Rover_Collects_Sample_Sample_Is_Collected_And_Battery_Is_Consumed() { var startingPosition = new Position(0, 0, Direction.East); var startingBattery = 10; var coordinates = CreateMap(1, 1); var testMap = new PlanetMap(coordinates); ICommandTranslator commandTranslator = new CommandTranslator(); var rover = new Rover(startingPosition, startingBattery, testMap, commandTranslator); rover.RunCommands("S"); rover.CollectedSamples.Count.ShouldBe(1); rover.CollectedSamples[0].ShouldBe(MapCellResource.Ferrum); rover.BatteryCharge.ShouldBe(startingBattery - 8); }
public void When_Rover_Moves_Forward_Facing_Direction_New_Position_Is_Expected_And_Battery_Is_Consumed(Direction direction, int expectedX, int expectedY, string command, int batteryExpense) { var expectedCoordinate = new Location(expectedX, expectedY); var startingPosition = new Position(1, 1, direction); var startingBattery = 10; Dictionary <Location, MapCellResource> coordinates = CreateMap(3, 3); var testMap = new PlanetMap(coordinates); ICommandTranslator commandTranslator = new CommandTranslator(); var rover = new Rover(startingPosition, startingBattery, testMap, commandTranslator); rover.RunCommands(command); rover.CurrentPosition.Coordinate.ShouldBe(expectedCoordinate); rover.BatteryCharge.ShouldBe(startingBattery - batteryExpense); }
public JinxBotClient(ClientProfile profile) { m_activePlugins = new Dictionary <ProfilePluginConfiguration, IJinxBotPlugin>(); if (profile.SimulateClient) { m_client = new SimulatedBattleNetClient(profile); } else { m_client = new BattleNetClient(profile); } m_profile = profile; m_resourceProvider = ProfileResourceProvider.RegisterProvider(m_client); m_cmdTranslator = new CommandTranslator(this); bool hasSetCommandQueue = false; if (m_database == null) { m_database = new JinxBotDefaultDatabase(); } // finally, initialize ui m_window = new ProfileDocument(this); // initialize plugins m_commandHandlers = new List <ICommandHandler>(); foreach (ProfilePluginConfiguration pluginConfig in profile.PluginSettings) { hasSetCommandQueue = ProcessPlugin(hasSetCommandQueue, pluginConfig); } ProfilePluginConfiguration jsConfig = new ProfilePluginConfiguration { Assembly = "JinxBot.Plugins.Script.dll", Name = "JavaScript Plugin", Settings = new ProfilePluginSettingConfiguration[0], Type = "JinxBot.Plugins.Script.JinxBotJavaScriptPlugin" }; hasSetCommandQueue = ProcessPlugin(hasSetCommandQueue, jsConfig); if (!hasSetCommandQueue) { m_client.CommandQueue = new TimedMessageQueue(); } }
public void When_Rover_Moves_Towards_Obstacle_A_Backoff_Strategy_Is_Played_Instead() { //First backoff is ERF var startingPosition = new Position(5, 5, Direction.East); var startingBattery = 10; var coordinates = CreateMap(10, 10); coordinates.Remove(new Location(6, 5)); coordinates.Add(new Location(6, 5), MapCellResource.Obstacle); var testMap = new PlanetMap(coordinates); ICommandTranslator commandTranslator = new CommandTranslator(); var rover = new Rover(startingPosition, startingBattery, testMap, commandTranslator); rover.RunCommands("F"); rover.BatteryCharge.ShouldBe(startingBattery - 1 + 10 - 2 - 3); rover.CurrentPosition.Facing.ShouldBe(Direction.South); rover.CurrentPosition.Coordinate.ShouldBe(new Location(5, 6)); }
private void WriteForCommand() { Token token; TraderState state = SessionManager.Default.GetTokenAndState(this._Id, out token); if (state == null || token == null) { Write(); return; } byte[] data = CommandTranslator.GetDataForCommand(token, state, this._CurrentCommand.Command); if (data == null) { Write(); return; } this._CurrentPacket = SerializeManager.Default.SerializeCommand(data); this.BeginWrite(this._CurrentPacket, 0, this._CurrentPacket.Length); }
public void When_Rover_Plays_A_Backoff_Strategy_And_Finds_Another_Obstacle_Strategy_Is_Interrupted_And_Next_Strategy_Plays() { //First backoff is ERF //Second backoff is ELF //Third backoff is ELLF var startingPosition = new Position(5, 5, Direction.East); var startingBattery = 10; var coordinates = CreateMap(10, 10); coordinates.Remove(new Location(6, 5)); coordinates.Add(new Location(6, 5), MapCellResource.Obstacle); coordinates.Remove(new Location(5, 6)); coordinates.Add(new Location(5, 6), MapCellResource.Obstacle); var testMap = new PlanetMap(coordinates); ICommandTranslator commandTranslator = new CommandTranslator(); var rover = new Rover(startingPosition, startingBattery, testMap, commandTranslator); rover.RunCommands("F"); rover.BatteryCharge.ShouldBe(startingBattery - 1 + 10 - 2 - 1 + 10 - 2 - 1 + 10 - 2 - 2 - 3); rover.CurrentPosition.Facing.ShouldBe(Direction.West); rover.CurrentPosition.Coordinate.ShouldBe(new Location(4, 5)); }
/// <summary> /// Converts the commands into Events. The events are then dispatched. The listeners from these /// events react to them. /// </summary> /// <param name="gameCommand">Game command.</param> void PropagateCommand(GameCommand gameCommand) { Debug.Log("SERVER: Command " + gameCommand.CommandType + " received"); CommandTranslator.TranslateGameCommandToEventAndDispatch(gameCommand); }
public void Translate_CommandWasNotFound_ReturnNull() { var result = new CommandTranslator(Mock.Of <ILoggerFactory>()).Translate(service: "movistar", command: "thismethoddoesnotexist"); Assert.IsNull(result); }
public void Translate_ServiceWasNotFound_ReturnNull() { var result = new CommandTranslator(Mock.Of <ILoggerFactory>()).Translate(service: "thisservicedoesnotexist", command: "datos"); Assert.IsNull(result); }