-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Renaud G
committed
Sep 26, 2019
1 parent
69a238f
commit d94207b
Showing
8 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include "allsamenode.h" | ||
|
||
|
||
AllSameNode::AllSameNode() : m_diceResult(new DiceResult()) | ||
{ | ||
m_result= m_diceResult; | ||
} | ||
|
||
void AllSameNode::run(ExecutionNode* previous) | ||
{ | ||
m_previousNode= previous; | ||
if(nullptr != previous) | ||
{ | ||
DiceResult* previous_result= dynamic_cast<DiceResult*>(previous->getResult()); | ||
if(nullptr != previous_result) | ||
{ | ||
m_result->setPrevious(previous_result); | ||
bool allSame=true; | ||
int i=0; | ||
quint64 previousValue; | ||
for(auto& die : previous_result->getResultList()) | ||
{ | ||
if(i == 0) | ||
previousValue=die->getValue(); | ||
Die* tmpdie= new Die(*die); | ||
m_diceResult->insertResult(tmpdie); | ||
die->displayed(); | ||
if(previousValue != die->getValue()) | ||
allSame=false; | ||
++i; | ||
} | ||
|
||
while(allSame) | ||
{ | ||
QList<Die*> list= m_diceResult->getResultList(); | ||
qint64 pValue; | ||
int i =0; | ||
for(auto& die: list) | ||
{ | ||
die->roll(true); | ||
if(i==0) | ||
pValue=die->getValue(); | ||
if(pValue != die->getValue()) | ||
allSame = false; | ||
++i; | ||
} | ||
} | ||
} | ||
} | ||
if(nullptr != m_nextNode) | ||
{ | ||
m_nextNode->run(this); | ||
} | ||
} | ||
|
||
|
||
QString AllSameNode::toString(bool withLabel) const | ||
{ | ||
if(withLabel) | ||
{ | ||
return QString("%1 [label=\"AllSameNode\"]").arg(m_id); | ||
} | ||
else | ||
{ | ||
return m_id; | ||
} | ||
} | ||
|
||
qint64 AllSameNode::getPriority() const | ||
{ | ||
qint64 priority= 0; | ||
if(nullptr != m_nextNode) | ||
{ | ||
priority= m_nextNode->getPriority(); | ||
} | ||
return priority; | ||
} | ||
|
||
ExecutionNode* AllSameNode::getCopy() const | ||
{ | ||
return new AllSameNode(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef ALLSAMENODE_H | ||
#define ALLSAMENODE_H | ||
|
||
#include "executionnode.h" | ||
|
||
#include "result/diceresult.h" | ||
#include "validator.h" | ||
|
||
class AllSameNode : public ExecutionNode | ||
{ | ||
public: | ||
AllSameNode(); | ||
// virtual ~AllSameNode(); | ||
|
||
virtual void run(ExecutionNode* previous); | ||
/** | ||
* @brief toString | ||
* @return | ||
*/ | ||
virtual QString toString(bool withLabel) const; | ||
/** | ||
* @brief getPriority | ||
* @return | ||
*/ | ||
virtual qint64 getPriority() const; | ||
|
||
virtual ExecutionNode* getCopy() const; | ||
|
||
private: | ||
DiceResult* m_diceResult; | ||
}; | ||
|
||
#endif // FILTERNODE_H |