Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Assets/Scripts/Cauldron/Cauldron.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public void AddIngredient(IIngredient ingredient)
return;
}

// TODO: Add a check here to make sure that the fractions are of the same denominator
// (in other words, plants are the same type)

ingredients.Add(ingredient);
value += ingredient.Value;

Expand Down
36 changes: 31 additions & 5 deletions Assets/Scripts/Utility/Fraction.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using FractionGame.Inputs;
using UnityEngine;

namespace FractionGame.Utility
Expand Down Expand Up @@ -54,17 +55,42 @@ public override string ToString()

public static Fraction operator +(Fraction a, Fraction b)
{
int numerator = a.numerator * b.denominator + b.numerator * a.denominator;
int denominator = a.denominator * b.denominator;
int denominator = CalculateCommonDenominator(a, b);
int numerator = denominator / a.denominator * a.numerator + denominator / b.denominator * b.numerator;
return new Fraction(numerator, denominator);
}

public static Fraction operator -(Fraction a, Fraction b)
{
int numerator = a.numerator * b.denominator - b.numerator * a.denominator;
int denominator = a.denominator * b.denominator;
return new Fraction(numerator, denominator);
int denominator = CalculateCommonDenominator(a, b);
int numerator = denominator / a.denominator * a.numerator - denominator / b.denominator * b.numerator;
return new Fraction(numerator, denominator);
}

/// <summary>
/// Returns the common denominator between two Fractions.
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int CalculateCommonDenominator(Fraction a, Fraction b)
{
/*
* Cases:
* 1) a and b are the same
* 2) one number is a factor of the other
* 3) the two numbers need to be multiplied together to get the common denominator
*/

int x = a.denominator;
int y = b.denominator;

if (x == y || x % y == 0)
return x;
else if (y % x == 0)
return y;
else
return x * y;
}
}
}
15 changes: 14 additions & 1 deletion Assets/Tests/Test Sprites/plant_dog.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion Assets/Tests/Test Sprites/roslinka.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.