aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/die.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'die.cpp')
-rw-r--r--die.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/die.cpp b/die.cpp
index 4a968a3..7ab78e9 100644
--- a/die.cpp
+++ b/die.cpp
@@ -1,10 +1,17 @@
+#include <QDateTime>
+
#include "die.h"
+#include <QDebug>
+
Die::Die()
: m_hasValue(false)
{
+ uint seed = quintptr(this) + QDateTime::currentDateTime().toMSecsSinceEpoch();
+ qsrand(seed);
}
+
void Die::setValue(qint64 r)
{
m_value = r;
@@ -48,3 +55,28 @@ bool Die::hasChildrenValue()
{
return m_rollResult.size()>1?true:false;
}
+void Die::replaceLastValue(qint64 value)
+{
+ m_rollResult.removeLast();
+ insertRollValue(value);
+}
+
+void Die::roll(bool adding)
+{
+ quint64 value=(qrand()%m_faces)+1;
+
+ if((adding)||(m_rollResult.isEmpty()))
+ {
+ insertRollValue(value);
+ }
+ else
+ {
+ replaceLastValue(value);
+ }
+}
+
+
+void Die::setFaces(quint64 face)
+{
+ m_faces=face;
+}