summaryrefslogtreecommitdiff
path: root/DiscoBot/Auxiliary/Calculator/Operator.cs
diff options
context:
space:
mode:
authorTrueDoctor <d-kobert@web.de>2018-07-17 21:18:59 +0200
committerTrueDoctor <d-kobert@web.de>2018-07-17 21:18:59 +0200
commit497a9eded3b785f7f96732c447943cc8bbad284b (patch)
tree87e40525b6d5173171597a0c8c288fd8d8e7f610 /DiscoBot/Auxiliary/Calculator/Operator.cs
parent496c9c32cb8d0d067e675855289904a22b05d9ac (diff)
Added object oriented dice resolving
Diffstat (limited to 'DiscoBot/Auxiliary/Calculator/Operator.cs')
-rw-r--r--DiscoBot/Auxiliary/Calculator/Operator.cs50
1 files changed, 50 insertions, 0 deletions
diff --git a/DiscoBot/Auxiliary/Calculator/Operator.cs b/DiscoBot/Auxiliary/Calculator/Operator.cs
new file mode 100644
index 0000000..0928ec2
--- /dev/null
+++ b/DiscoBot/Auxiliary/Calculator/Operator.cs
@@ -0,0 +1,50 @@
+using System;
+
+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})";
+ }
+ }
+}