diff options
author | TrueDoctor <d-kobert@web.de> | 2018-09-26 20:51:37 +0200 |
---|---|---|
committer | TrueDoctor <d-kobert@web.de> | 2018-09-26 20:51:37 +0200 |
commit | b411aa2128c2724bec0ecedb8cb4e1ffa59f3b53 (patch) | |
tree | 14e0a0cca2cf66b95fda402c8c7d7b6bd5b7b222 /DSACore/Auxiliary/Calculator/Operator.cs | |
parent | 92e8bb7523c775014ccf68355e3f0178ebf4a61c (diff) |
disconnected most vital calles from the Discord Bot
Diffstat (limited to 'DSACore/Auxiliary/Calculator/Operator.cs')
-rw-r--r-- | DSACore/Auxiliary/Calculator/Operator.cs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/DSACore/Auxiliary/Calculator/Operator.cs b/DSACore/Auxiliary/Calculator/Operator.cs new file mode 100644 index 0000000..703f060 --- /dev/null +++ b/DSACore/Auxiliary/Calculator/Operator.cs @@ -0,0 +1,51 @@ +using System; +using DSACore.Auxiliary; + +namespace DiscoBot.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; + this.OperatorType = operatorType; + } + + public Ops OperatorType { get; set; } + + public int Solve() + { + int result; + switch (this.OperatorType) + { + case Ops.Dice: + result = Dice.Roll(this.arg1.Solve(), this.arg2.Solve()); + break; + case Ops.Multiply: + result = this.arg1.Solve() * this.arg2.Solve(); + break; + case Ops.Add: + result = this.arg1.Solve() + this.arg2.Solve(); + break; + case Ops.Subtract: + result = this.arg1.Solve() - this.arg2.Solve(); + break; + default: + throw new ArgumentOutOfRangeException(); + } + + return result; + } + + public override string ToString() + { + return $"({this.arg1} {this.OperatorType} {this.arg2})"; + } + } +} |