diff options
Diffstat (limited to 'die.cpp')
| -rw-r--r-- | die.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -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; +} |