summaryrefslogtreecommitdiff
path: root/dsa/DSALib/Auxiliary/Calculator/Operator.cs
diff options
context:
space:
mode:
authorDennis Kobert <d-kobert@web.de>2019-06-11 23:38:13 +0200
committerDennis Kobert <d-kobert@web.de>2019-06-11 23:38:13 +0200
commit2fa4a0e50ebfc97059c8b84dbd17e79f9afc8a8d (patch)
treec3b34ccb2737e347a73768536895cbbaab13cc01 /dsa/DSALib/Auxiliary/Calculator/Operator.cs
parentec991104f56e90d7bb2878da2fe6ed4e585dfc46 (diff)
parentaf74efccf8d21e6151022b71f3cacd3fa83024ee (diff)
Merge branch 'rework-backend'
Diffstat (limited to 'dsa/DSALib/Auxiliary/Calculator/Operator.cs')
-rw-r--r--dsa/DSALib/Auxiliary/Calculator/Operator.cs51
1 files changed, 51 insertions, 0 deletions
diff --git a/dsa/DSALib/Auxiliary/Calculator/Operator.cs b/dsa/DSALib/Auxiliary/Calculator/Operator.cs
new file mode 100644
index 0000000..e6aeec6
--- /dev/null
+++ b/dsa/DSALib/Auxiliary/Calculator/Operator.cs
@@ -0,0 +1,51 @@
+using System;
+using DSALibv.Auxiliary.Calculator;
+
+namespace DSALib.Auxiliary.Calculator
+{
+ /// <summary>
+ /// The Operator Class represents a binary operator with tow Arguments and an Operation type
+ /// </summary>
+ public class Operator : ISolvable
+ {
+ private readonly ISolvable arg1, arg2;
+
+ public Operator(ISolvable arg1, ISolvable arg2, Ops operatorType)
+ {
+ this.arg1 = arg1;
+ this.arg2 = arg2;
+ OperatorType = operatorType;
+ }
+
+ public Ops OperatorType { get; set; }
+
+ public int Solve()
+ {
+ int result;
+ switch (OperatorType)
+ {
+ case Ops.Dice:
+ result = Dice.Roll(arg1.Solve(), arg2.Solve());
+ break;
+ case Ops.Multiply:
+ result = arg1.Solve() * arg2.Solve();
+ break;
+ case Ops.Add:
+ result = arg1.Solve() + arg2.Solve();
+ break;
+ case Ops.Subtract:
+ result = arg1.Solve() - arg2.Solve();
+ break;
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
+
+ return result;
+ }
+
+ public override string ToString()
+ {
+ return $"({arg1} {OperatorType} {arg2})";
+ }
+ }
+} \ No newline at end of file