< Summary

Information
Class: Safarimacik.Model.WalkingRangerState
Assembly: Safarimacik
File(s): /builds/szofttech-ab-2025/group-03/safarimacik/model/RangerState.cs
Line coverage
83%
Covered lines: 10
Uncovered lines: 2
Coverable lines: 12
Total lines: 50
Line coverage: 83.3%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
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_Destination()100%11100%
Tick()50%2260%
HasReachedDestination()100%11100%

File(s)

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

#LineLine coverage
 1using Godot;
 2
 3
 4namespace Safarimacik.Model;
 5
 6
 7/// <summary>
 8/// Base class for all ranger states.
 9/// </summary>
 10public abstract class RangerState(Ranger ranger) {
 11  protected Ranger _ranger = ranger;
 12
 13  public abstract void Tick();
 14}
 15
 16/// <summary>
 17/// Represents a state in which the ranger has nothing to do.
 18/// </summary>
 19public class IdleRangerState(Ranger ranger) : RangerState(ranger) {
 20  public override void Tick() { }
 21}
 22
 23/// <summary>
 24/// Represents a state in which the ranger approaches its destination following its given path.
 25/// </summary>
 126public class WalkingRangerState(Ranger ranger, List<Vector2> path) : RangerState(ranger) {
 127  private Vector2 _destination = path.Last();
 128  private List<Vector2> _path = path;
 29
 130  public Vector2 Destination => _destination;
 31
 132  public override void Tick() {
 133    if (!HasReachedDestination()) {
 034      _ranger.Move(_path);
 035    }
 136  }
 37
 138  public bool HasReachedDestination() {
 139    return _destination == _ranger.Position;
 140  }
 41}
 42
 43/// <summary>
 44/// Represents a state in which the animal has reached its target, and is now shooting it.
 45/// </summary>
 46public class ShootingRangerState(Ranger ranger) : RangerState(ranger) {
 47  public override void Tick() {
 48    _ranger.KillTarget();
 49  }
 50}