< Summary

Information
Class: Safarimacik.Model.PurchasableFactory
Assembly: Safarimacik
File(s): /builds/szofttech-ab-2025/group-03/safarimacik/model/Purchasable.cs
Line coverage
94%
Covered lines: 18
Uncovered lines: 1
Coverable lines: 19
Total lines: 46
Line coverage: 94.7%
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
.cctor()100%11100%
Purchase(...)50%2283.33%

File(s)

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

#LineLine coverage
 1using Godot;
 2
 3
 4namespace Safarimacik.Model;
 5
 6
 7/// <summary>
 8/// Base class for all placeable objects.
 9/// </summary>
 10public interface Purchasable {
 11  public int Price { get; }
 12}
 13
 14/// <summary>
 15/// Static class for purchasing a purchasable object.
 16/// </summary>
 17public static class PurchasableFactory {
 118  private static readonly Func<Vector2, Purchasable>[] registry = [
 119    (position) => new Sheep(position),
 120    (position) => new Cow(position),
 121    (position) => new Wolf(position),
 122    (position) => new Fox(position),
 123    (position) => Weed.Instance, // Assuming Weed.Instance doesn't require a position
 124    (position) => new Bush(),
 125    (position) => new Tree(),
 126    (position) => new Road(),
 127    (position) => new Water(),
 128    (position) => new Jeep([], position, 0), // Handle null position for Jeep
 129    (position) => new Ranger(position)
 130  ];
 31
 32  /// <summary>
 33  /// Purchases an object.
 34  /// </summary>
 35  /// <param name="purchaseId">Id of the object to be purchased</param>
 36  /// <param name="funds">Funds for the purchase</param>
 37  /// <param name="position">Position with which the object is constructed</param>
 38  /// <returns>Null if the funds are insufficient, the purchased object otherwise</returns>
 139  public static Purchasable? Purchase(int purchaseId, int funds, Vector2 position) {
 140    Purchasable candidate = registry[purchaseId](position);
 141    if (funds >= candidate.Price) {
 142      return candidate;
 43    }
 044    return null;
 145  }
 46}