Esempio n. 1
0
        static void Main(string[] args)
        {
            //6,6 as dimensions because end position is 5,1 and as array is 0 based it has to be 6
            LawnField field = new LawnField(6, 6);

            Position mower1Position = new Position(new Ubication(1, 2), new Direction("N"));
            Position mower2Position = new Position(new Ubication(3, 3), new Direction("E"));

            InstructionList mower1ListOfInstructions = new InstructionList("LMLMLMLMM");
            InstructionList mower2ListOfInstructions = new InstructionList("MMRMMRMRRM");

            Mower mower1 = new Mower(mower1Position, mower1ListOfInstructions);
            Mower mower2 = new Mower(mower2Position, mower2ListOfInstructions);

            mower1.NewFieldToBeOperated(field);
            mower2.NewFieldToBeOperated(field);

            mower1.OperateField();
            Console.WriteLine(mower1.GetPosition());

            ACMEMower ACMEmower = new Mower();

            ACMEmower.SaySomething();

            mower1.AskTheField();

            mower2.OperateField();
            Console.WriteLine(mower2.GetPosition());
            mower1.SaySomething();
            mower2.AskTheField();


            Console.Read();
        }
Esempio n. 2
0
        public void WhenMowerMoves_OutsideOfFieldBounds_ExceptionShouldBeThrown()
        {
            // Yep, You're right. there was suposed to be code there but for some unkown reason the project was made in .Net Core and i have no idea about net core testin'

            // Arrange
            LawnField field = new LawnField(5, 5);

            Position mower2Position = new Position(new Ubication(3, 3), new Direction("E"));

            InstructionList mower2ListOfInstructions = new InstructionList("MMRMMRMRRM");

            Mower mower2 = new Mower(mower2Position, mower2ListOfInstructions);

            mower2.NewFieldToBeOperated(field);

            // Act
            Exception ex = Assert.Throws <IndexOutOfRangeException>(() => mower2.OperateField());

            // Assert
            Assert.Equal("Woops, You have got out of bounds and cutted the rare plants, you're fired BTW", ex.Message);
        }
Esempio n. 3
0
        internal void ChangeUbication(CardinalDirection direction, LawnField field)
        {
            Tuple <int, int> fieldBounds;

            fieldBounds = field.GetBounds();

            CardinalDirectionToArray directionToHeadOfInTheField = Directions.GetCardinalDirectionToArrayEquivalent(direction);

            if ((direction == CardinalDirection.North || direction == CardinalDirection.South) && fieldBounds.Item1 >= xAxis)
            {
                yAxis = yAxis + (int)directionToHeadOfInTheField;
            }
            else if ((direction == CardinalDirection.East || direction == CardinalDirection.West) && fieldBounds.Item2 >= yAxis)
            {
                xAxis = xAxis + (int)directionToHeadOfInTheField;
            }
            else
            {
                throw new Exception("You can't go in that direction, you getting out of the field bonds");
            }
        }
Esempio n. 4
0
 public MowerOperator(Mower mower, LawnField field)
 {
     this.mower = mower;
     this.field = field;
 }
Esempio n. 5
0
 public void ChangePosition(LawnField field)
 {
     ubication.ChangeUbication(direction.GetDirection(), field);
 }
Esempio n. 6
0
 public void NewFieldToBeOperated(LawnField newField)
 {
     fieldToBeOperated = newField;
 }