aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/die.cpp
diff options
context:
space:
mode:
authorobiwankennedy <renaud@rolisteam.org>2014-01-08 18:02:50 +0100
committerobiwankennedy <renaud@rolisteam.org>2014-01-08 18:02:50 +0100
commited4de87f2518c63fc8a463b0f600ce37eb4749c4 (patch)
tree2826be68884205a2a3382c5fbe0f1f31e2ebf0b4 /die.cpp
parent4c02b504e0369fea3e82f240ba4269c08962bdba (diff)
downloadOneRoll-ed4de87f2518c63fc8a463b0f600ce37eb4749c4.tar.gz
OneRoll-ed4de87f2518c63fc8a463b0f600ce37eb4749c4.zip
Update die.cpp
-put rolling die as method of die class
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;
+}