Private
Public Access
Updated Interface
This commit is contained in:
1 parent
35bc68cfb6
commit
15c9eb98c9
6 files changed
+53
-12
No files matched your search
@@ -16,5 +16,7 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
||||
Color ToColor();
|
||||
|
||||
Type GetOriginalType();
|
||||
|
||||
bool isInitialised();
|
||||
}
|
||||
}
|
||||
+17
-5
@@ -5,15 +5,22 @@ namespace Advanced_Software_Engineering.Verbs.Value.ValueTypes {
|
||||
|
||||
internal class BoolValue : IValue {
|
||||
|
||||
bool initialised = false;
|
||||
|
||||
bool value;
|
||||
Type type = typeof(bool);
|
||||
|
||||
public BoolValue(bool value) {
|
||||
this.value = value;
|
||||
initialised = true;
|
||||
}
|
||||
|
||||
public BoolValue() {
|
||||
}
|
||||
|
||||
public string GetDescription() {
|
||||
return "boolean of value " + value.ToString();
|
||||
if (initialised) return "boolean of value " + value.ToString();
|
||||
else return "an unset boolean value";
|
||||
}
|
||||
|
||||
public Type GetOriginalType() {
|
||||
@@ -21,19 +28,24 @@ namespace Advanced_Software_Engineering.Verbs.Value.ValueTypes {
|
||||
}
|
||||
|
||||
public bool ToBool() {
|
||||
return value;
|
||||
if (initialised) return value;
|
||||
else throw new Exception("not initilised");
|
||||
}
|
||||
|
||||
public Color ToColor() {
|
||||
return value ? Color.White : Color.Black;
|
||||
return ToBool() ? Color.White : Color.Black;
|
||||
}
|
||||
|
||||
public double ToDouble() {
|
||||
return value ? 1d : 0d;
|
||||
return ToBool() ? 1d : 0d;
|
||||
}
|
||||
|
||||
public int ToInt() {
|
||||
return value ? 1 : 0;
|
||||
return ToBool() ? 1 : 0;
|
||||
}
|
||||
|
||||
public bool isInitialised() {
|
||||
return initialised;
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
-5
@@ -5,15 +5,22 @@ namespace Advanced_Software_Engineering.Verbs.Value.ValueTypes {
|
||||
|
||||
internal class ColorValue : IValue {
|
||||
|
||||
bool initialised = false;
|
||||
|
||||
Color value;
|
||||
Type type = typeof(Color);
|
||||
|
||||
public ColorValue(Color value) {
|
||||
this.value = value;
|
||||
initialised = true;
|
||||
}
|
||||
|
||||
public ColorValue() {
|
||||
}
|
||||
|
||||
public string GetDescription() {
|
||||
return "A color with description " + value.ToString();
|
||||
if (initialised) return "A color with description " + value.ToString();
|
||||
else return "An uninitialised color";
|
||||
}
|
||||
|
||||
public Type GetOriginalType() {
|
||||
@@ -21,19 +28,24 @@ namespace Advanced_Software_Engineering.Verbs.Value.ValueTypes {
|
||||
}
|
||||
|
||||
public bool ToBool() {
|
||||
return value.GetBrightness() > 0.5;
|
||||
return ToColor().GetBrightness() > 0.5;
|
||||
}
|
||||
|
||||
public Color ToColor() {
|
||||
return value;
|
||||
if (initialised) return value;
|
||||
else throw new Exception("Color value not set");
|
||||
}
|
||||
|
||||
public double ToDouble() {
|
||||
return value.GetBrightness();
|
||||
return ToColor().GetBrightness();
|
||||
}
|
||||
|
||||
public int ToInt() {
|
||||
return value.ToArgb();
|
||||
return ToColor().ToArgb();
|
||||
}
|
||||
|
||||
public bool isInitialised() {
|
||||
return initialised;
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
@@ -5,6 +5,8 @@ namespace Advanced_Software_Engineering.Verbs.Value.ValueTypes {
|
||||
|
||||
internal class DoubleValue : IValue {
|
||||
|
||||
bool initialised = false;
|
||||
|
||||
bool colorValueCacheAvailable = false;
|
||||
Color colorValueCache;
|
||||
|
||||
@@ -44,5 +46,9 @@ namespace Advanced_Software_Engineering.Verbs.Value.ValueTypes {
|
||||
public int ToInt() {
|
||||
return (int)Math.Round(value);
|
||||
}
|
||||
|
||||
public bool isInitialised() {
|
||||
return initialised;
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
@@ -5,6 +5,8 @@ namespace Advanced_Software_Engineering.Verbs.Value.ValueTypes {
|
||||
|
||||
internal class IntValue : IValue {
|
||||
|
||||
bool initialised = false;
|
||||
|
||||
int value;
|
||||
|
||||
bool doubleValueCacheAvaiable = false;
|
||||
@@ -60,5 +62,9 @@ namespace Advanced_Software_Engineering.Verbs.Value.ValueTypes {
|
||||
public int ToInt() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public bool isInitialised() {
|
||||
return initialised;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,9 +203,12 @@ namespace Advanced_Software_Engineering {
|
||||
} else throw new Exception(command + " has an incorrect number of parameters");
|
||||
|
||||
case "int":
|
||||
case "double":
|
||||
case "bool":
|
||||
case "color":
|
||||
if (parameterLength == 1) {
|
||||
return new Verb
|
||||
} else throw new Exception("ints need to be initialised");
|
||||
return new InitialiseVariable(drawer, command, parameters[0]);
|
||||
} else throw new Exception(command + "s need to be initialised");
|
||||
|
||||
default:
|
||||
throw new Exception("Unknown command");
|
||||
|
||||
Reference in new issue
Block a user