コード例 #1
0
        public ManagerMessage AddPerson(ref Person person, Location location)
        {
            ManagerMessage response = new ManagerMessage();

            int personId = actors.Count;

            person.Id      = personId;
            person.Manager = this;
            actors.Add(personId, person);
            positions.Add(personId, location);

            response.Code    = personId;
            response.Message = $"{person} added at location {location}";

            return(response);
        }
コード例 #2
0
        public ManagerMessage MovePerson(int personId, Location newPosition)
        {
            ManagerMessage response     = new ManagerMessage();
            Location       oldPosition  = positions[personId];
            Person         person       = actors[personId];
            int            moveDistance = Location.GetDistance(oldPosition, newPosition);

            if (moveDistance <= person.MoveRange)
            {
                positions[personId] = newPosition;
                response.Success    = true;
                response.Message    = $"Moved {person} from {oldPosition} to {newPosition}";
            }
            else
            {
                response.Success = false;
                response.Message = $"Move range for {person} exceeded. (Moving from {oldPosition} to {newPosition}.  Calculated Range: {moveDistance})";
            }

            return(response);
        }