< Summary

Information
Class: Safarimacik.Model.Jeep
Assembly: Safarimacik
File(s): /builds/szofttech-ab-2025/group-03/safarimacik/model/Jeep.cs
Line coverage
100%
Covered lines: 32
Uncovered lines: 0
Coverable lines: 32
Total lines: 73
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Position()100%11100%
Safarimacik.Model.Purchasable.get_Price()100%11100%
get_Speed()100%11100%
Move()100%66100%
AnimalSeen(...)100%11100%
OnFinished()100%22100%
OnMoving()100%22100%

File(s)

/builds/szofttech-ab-2025/group-03/safarimacik/model/Jeep.cs

#LineLine coverage
 1using Godot;
 2
 3
 4namespace Safarimacik.Model;
 5
 6
 7/// <summary>
 8/// Jeeps are purchasable vehicles that can move along a path.
 9/// </summary>
 10/// <remarks>
 11/// Jeeps are used to transport passengers and can spot animals along their route. Each jeep has a path it follows, a st
 12/// </remarks>
 13public class Jeep : Purchasable {
 14  private int _passengers;
 15  private List<Vector2> _path;
 16  private Vector2 _position;
 17  private HashSet<Animal> _animalsSeen;
 18
 119  public Jeep(List<Vector2> path, Vector2 position, int passengers) {
 120    _passengers = passengers;
 121    _path = path;
 122    _position = position;
 123    _animalsSeen = [];
 124  }
 25
 26  /// <summary>Occurs when the jeep is moving</summary>
 27  public event EventHandler<EventArgs>? Moving;
 28  /// <summary>Occurs when the jeep reaches its goal</summary>
 29  public event EventHandler<JeepFinishedEventArgs>? Finished;
 30
 131  public Vector2 Position => _position;
 32  public const int Price = 70;
 133  int Purchasable.Price => Price;
 134  public float Speed => 200f;
 35
 36  /// <summary>
 37  /// Moves the jeep along it's path.
 38  /// </summary>
 39  /// <returns>True, if it reached the end</returns>
 140  public bool Move() {
 141    if (_position == _path[0]) { _path.RemoveAt(0); }
 42
 143    if (_path.Count == 0) {
 144      OnFinished();
 145      return true;
 46    }
 47
 148    if (_position.DistanceTo(_path[0]) <= Speed) {
 149      _position = _path[0];
 150    } else {
 151      Vector2 direction = (_path[0] - _position).Normalized();
 152      _position += direction * Speed;
 153    }
 154    OnMoving();
 155    return false;
 156  }
 57
 58  /// <summary>
 59  /// Adds an animal to the jeep's seen animals set.
 60  /// </summary>
 61  /// <param name="animal">The animal spotted by the jeep.</param>
 162  public void AnimalSeen(Animal animal) {
 163    _animalsSeen.Add(animal);
 164  }
 65
 166  private void OnFinished() {
 167    Finished?.Invoke(this, new JeepFinishedEventArgs(_animalsSeen.Count, _passengers));
 168  }
 69
 170  private void OnMoving() {
 171    Moving?.Invoke(this, EventArgs.Empty);
 172  }
 73}