You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Groyne.cs 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Buhnenrennen
  7. {
  8. class Groyne
  9. {
  10. public double YCoord { get; private set; }
  11. public char Type { get; private set; }
  12. public Groyne( double yCoord, char type )
  13. {
  14. this.YCoord = yCoord;
  15. this.Type = type;
  16. }
  17. /// <summary>
  18. /// returns if given dog fits through the groyne
  19. /// </summary>
  20. /// <param name="dog">the dog, that wants to fit through</param>
  21. public bool CanPass( Dog dog ) => dog.FitsThrough.Contains( Type );
  22. /// <summary>
  23. /// returns the distance between called and given groyne
  24. /// </summary>
  25. /// <param name="groyne">groyne to calculate the distance to</param>
  26. public double DistanceTo( Groyne groyne ) =>
  27. // distance: distance² = A² + B²
  28. // A: 70
  29. // B: difference of Y-Coordinates
  30. Math.Sqrt( Math.Pow( 70, 2 ) + Math.Pow( YCoord - groyne.YCoord, 2 ) );
  31. /// <summary>
  32. /// returns the time the given {dog} needs to get to given {groyne} starting at current groyne
  33. /// </summary>
  34. /// <param name="groyne">groyne the dog is running to</param>
  35. /// <param name="dog">the dog, thats running to the groyne</param>
  36. public double RequiredTimeTo( Groyne groyne, Dog dog ) => DistanceTo( groyne ) / dog.MeterPerSecond;
  37. public override string ToString() => Type + "( " + YCoord + " )";
  38. }
  39. }