From b0ddec64a03135484a7439a65de8486974f08499 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sun, 12 Feb 2017 11:05:54 +0100 Subject: -Fix range management for DF dice. --- die.cpp | 20 +++++++++++++++----- die.h | 5 ++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/die.cpp b/die.cpp index 979c8c9..49b30ac 100644 --- a/die.cpp +++ b/die.cpp @@ -44,7 +44,7 @@ Die::Die(const Die& die) m_selected = die.m_selected; m_hasValue = die.m_hasValue; m_displayStatus = die.m_displayStatus; - m_faces = die.m_faces; + m_maxValue = die.m_maxValue; m_highlighted = die.m_highlighted; m_base = die.m_base; m_color = die.getColor(); @@ -103,11 +103,11 @@ void Die::replaceLastValue(qint64 value) void Die::roll(bool adding) { - if(m_faces!=0) + if(m_maxValue!=0) { //quint64 value=(qrand()%m_faces)+m_base; - std::uniform_int_distribution dist(m_base,m_faces); + std::uniform_int_distribution dist(m_base,m_maxValue); qint64 value = dist(m_rng); if((adding)||(m_rollResult.isEmpty())) { @@ -122,12 +122,12 @@ void Die::roll(bool adding) quint64 Die::getFaces() const { - return m_faces; + return abs(m_maxValue-m_base)+1; } void Die::setFaces(quint64 face) { - m_faces=face; + //m_maxValue=m_base+face-1; } qint64 Die::getLastRolledValue() { @@ -169,3 +169,13 @@ void Die::setColor(const QString &color) m_color = color; } +quint64 Die::getMaxValue() const +{ + return m_maxValue; +} + +void Die::setMaxValue(const quint64 &maxValue) +{ + m_maxValue = maxValue; +} + diff --git a/die.h b/die.h index 6f3af8c..5899bab 100644 --- a/die.h +++ b/die.h @@ -128,6 +128,9 @@ public: QString getColor() const; void setColor(const QString &color); + quint64 getMaxValue() const; + void setMaxValue(const quint64 &maxValue); + private: qint64 m_value; QList m_rollResult; @@ -135,7 +138,7 @@ private: bool m_hasValue; bool m_displayStatus; bool m_highlighted; - quint64 m_faces; + quint64 m_maxValue; qint64 m_base; QString m_color; -- cgit v1.2.3-70-g09d2