diff --git a/Sources/Model/Dice/Faces/AbstractDieFace.cs b/Sources/Model/Dice/Faces/AbstractDieFace.cs
index a3f5364..ae09083 100644
--- a/Sources/Model/Dice/Faces/AbstractDieFace.cs
+++ b/Sources/Model/Dice/Faces/AbstractDieFace.cs
@@ -14,7 +14,7 @@ namespace Model.Dice.Faces
///
/// USE GetPracticalValue for a Value specific to face type
///
- protected abstract int Value { get; }
+ public int Value { get; protected set; }
public abstract object GetPracticalValue();
diff --git a/Sources/Model/Dice/Faces/ColorDieFace.cs b/Sources/Model/Dice/Faces/ColorDieFace.cs
index 2d7e450..fc7f7a0 100644
--- a/Sources/Model/Dice/Faces/ColorDieFace.cs
+++ b/Sources/Model/Dice/Faces/ColorDieFace.cs
@@ -8,22 +8,34 @@ namespace Model.Dice.Faces
{
public class ColorDieFace : AbstractDieFace
{
+ private static readonly int MAX_HEX = 16777215;
///
- /// a decimal representation of the hex (...representation of the color)
- ///
- protected override int Value { get; }
-
- ///
- /// accepts hex strings like "ffbb84" ([RRGGBB])
+ /// accepts hex strings like "ffbb84" and "#af567d" ([RRGGBB])
///
/// hex string
public ColorDieFace(string hexValueString)
{
// https://stackoverflow.com/questions/1139957/convert-integer-to-hexadecimal-and-back-again
+ // we remove any initial '#' before parsing
+ if (hexValueString.StartsWith('#'))
+ {
+ hexValueString = hexValueString[1..];
+ }
- // if style is ("f0b"), this constructor can develop it to "ff00bb" before doing the job
+ // if style is "f0b", this constructor can develop it to "ff00bb" before doing the job
+ if (hexValueString.Length == 3)
+ {
+ foreach (char ch in hexValueString)
+ {
+ // replace one instance of the char by two instances of it
+ hexValueString = hexValueString.Replace(new string(ch, 1), new string(ch, 2));
+ }
+ }
+ int result = int.Parse(hexValueString, System.Globalization.NumberStyles.HexNumber);
- Value = int.Parse(hexValueString, System.Globalization.NumberStyles.HexNumber);
+ if (result < 0) Value = 0;
+ else if (result > MAX_HEX) Value = MAX_HEX;
+ else Value = result;
}
///
@@ -31,13 +43,11 @@ namespace Model.Dice.Faces
///
///
public ColorDieFace(int decimalValue)
- {
- Value = decimalValue;
- }
+ : this(decimalValue.ToString())
+ { }
public override object GetPracticalValue()
{
// https://stackoverflow.com/questions/1139957/convert-integer-to-hexadecimal-and-back-again
- // maybe prepend it with a "#"...
return Value.ToString("X6").Insert(0, "#");
}
}
diff --git a/Sources/Model/Dice/Faces/ImageDieFace.cs b/Sources/Model/Dice/Faces/ImageDieFace.cs
index 966832c..84d472b 100644
--- a/Sources/Model/Dice/Faces/ImageDieFace.cs
+++ b/Sources/Model/Dice/Faces/ImageDieFace.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -8,18 +9,9 @@ namespace Model.Dice.Faces
{
public class ImageDieFace : AbstractDieFace
{
- ///
- /// an image URL code, to find the image URL (to find the image)
- ///
- protected override int Value { get; }
-
public ImageDieFace(string uri)
{
- /*parse an int after the last occurrence of "/" ? */
- string resultString = uri[(uri.LastIndexOf('/') + 1)..];
- /* !! here we should make sure to remove any ".jpg" etc, if there was one in the uri*/
- int result = int.Parse(resultString);
- Value = result;
+ Value = int.Parse(Path.GetFileNameWithoutExtension(uri));
}
public ImageDieFace(int code)
@@ -29,7 +21,7 @@ namespace Model.Dice.Faces
public override object GetPracticalValue()
{
- return string.Format("Assets/images/{0}", Value);
+ return string.Format($"Assets/images/{Value}.png");
}
}
}
diff --git a/Sources/Model/Dice/Faces/NumberDieFace.cs b/Sources/Model/Dice/Faces/NumberDieFace.cs
index 0e236a9..5aa7adf 100644
--- a/Sources/Model/Dice/Faces/NumberDieFace.cs
+++ b/Sources/Model/Dice/Faces/NumberDieFace.cs
@@ -8,7 +8,6 @@ namespace Model.Dice.Faces
{
public class NumberDieFace : AbstractDieFace
{
- protected override int Value { get; }
public NumberDieFace(int value)
{
Value = value;
diff --git a/Sources/Tests/Model_UTs/GameTest.cs b/Sources/Tests/Model_UTs/GameTest.cs
index abd259b..5a18c07 100644
--- a/Sources/Tests/Model_UTs/GameTest.cs
+++ b/Sources/Tests/Model_UTs/GameTest.cs
@@ -383,8 +383,8 @@ namespace Tests.Model_UTs
"\nPlayers: Alice Bob" +
"\nNext: Alice" +
"\nLog:" +
- "\n\t" + date + " " + time + " -- Alice rolled: 4 Assets/images/40 #A00FA0" +
- "\n\t" + date + " " + time + " -- Bob rolled: 3 Assets/images/20 #A00BB8" +
+ "\n\t" + date + " " + time + " -- Alice rolled: 4 Assets/images/40.png #A00FA0" +
+ "\n\t" + date + " " + time + " -- Bob rolled: 3 Assets/images/20.png #A00BB8" +
"\n";
string actual = game.ToString();