public override string ToString() { return(string.Format("{0} {1} {2}{3}", location.x, location.y, WorldHelper.RotationToCompass(rotation), alive ? "" : " LOST")); }
public void Forward() { //we may need the old location for recording a movement that places us out of bounds later Coordinates oldCoords = location; //check if we have danger location recorded string direction = WorldHelper.RotationToCompass(rotation).ToString(); if (WorldHelper.IsMovementSafe(location.x, location.y, direction)) { //we do not want to move forward! return; } //move ship forward in direction switch (WorldHelper.RotationToCompass(rotation)) { case WorldHelper.Compass.N: location.y += 1; break; case WorldHelper.Compass.E: location.x += 1; break; case WorldHelper.Compass.S: location.y -= 1; break; case WorldHelper.Compass.W: location.x -= 1; break; } //check ship is in bounds if (location.x <= world.x && location.y <= world.y && location.x >= 0 && location.y >= 0) { return; } //ship went out of bounds - record the movement for future ships if (alive) { DangerMovement dm = new DangerMovement() { coords = oldCoords, direction = direction }; WorldHelper.DangerMovements.Add(dm); } alive = false; }