// ---------------------------------------------------------------------------------------------------------------------------------------- // Handle Movement entity public void ChangeObjectPositionHandler(List <Entity> Entities) { string ObjectiveText = ""; string Origin = ""; string Destiny = ""; Node OriginPositions; Node DestinyPositions; // Extract the entities foreach (Entity entity in Entities) { switch (entity.type) { case "objetivo": ObjectiveText = entity.entity; break; case "Desde": Origin = entity.entity; break; case "Hacia": Destiny = entity.entity; break; } } List <Node> Positions = new List <Node>(); Node ActualPosition; switch (ObjectiveText) { // Change agent's position case "agente": case "gente": ActualPosition = new Node() { X = Board.Agent.Position.Item1, Y = Board.Agent.Position.Item2 }; DestinyPositions = ExtractCoordinates(Destiny, "destino"); if (Board.IsValidMovement(DestinyPositions)) { Positions.Add(ActualPosition); Positions.Add(DestinyPositions); MainFrame.UpdateItemPosition(Positions); Board.ChangeAgentPosition(DestinyPositions); TextToSpeech("¡Wow!, ¿me has teletransportado?"); } else { TextToSpeech("No puedo moverme " + Destiny + ". Fíjate que esté libre y dentro del tablero."); } break; // Change agent's goal case "meta": ActualPosition = new Node() { X = Board.Agent.Goal.Item1, Y = Board.Agent.Goal.Item2 }; DestinyPositions = ExtractCoordinates(Destiny, "destino"); if (Board.IsValidMovement(DestinyPositions)) { Positions.Add(ActualPosition); Positions.Add(DestinyPositions); MainFrame.UpdateItemPosition(Positions); Board.ChangeAgentGoal(DestinyPositions); TextToSpeech("¡Vaya!, ¡que indeciso eres!"); } else { TextToSpeech("No podemos ir " + Destiny + ". Fíjate que esté libre y dentro del tablero."); } break; case "obstáculo": case "obstáculos": // This means delete object if (!Origin.Equals("") && Destiny.Equals("")) { OriginPositions = ExtractCoordinates(Origin, "origen"); if (Board.DeleteObstacle(new Tuple <int, int>(OriginPositions.X, OriginPositions.Y))) { MainFrame.UpDateMatrix(OriginPositions.X, OriginPositions.Y, 0); TextToSpeech("¡Bien! Tengo más claro mi camino!"); } else { TextToSpeech("No hay obstáculo en esa posición"); } } // Add obstacle else if (Origin.Equals("") && !Destiny.Equals("")) { DestinyPositions = ExtractCoordinates(Destiny, "destino"); if (Board.AddObstacle(DestinyPositions)) { MainFrame.UpDateMatrix(DestinyPositions.X, DestinyPositions.Y, 1); TextToSpeech("¡Demonios! Ahora la tengo más difícil!"); } } break; } Board.Show(); }