Commit 247f710c authored by Shlomi Fish's avatar Shlomi Fish

Extract a cardsListToLine function.

This is Refactoring / code cleanup.

See:

* https://refactoring.com/catalog/extractMethod.html

* https://en.wikipedia.org/wiki/Code_refactoring
parent 64882cd6
......@@ -135,12 +135,7 @@ QString Freecell::solverFormat() const
}
for (int i = 0; i < 8 ; i++)
{
QList<KCard*> cards = store[i]->cards();
for (QList<KCard*>::ConstIterator it = cards.constBegin(); it != cards.constEnd(); ++it)
output += cardToRankSuitString(*it) + ' ';
output += '\n';
}
cardsListToLine(output, store[i]->cards());
return output;
}
......
......@@ -181,20 +181,7 @@ QString Golf::solverFormat() const
}
output += "\n";
for (int i = 0; i < 7 ; i++)
{
QList<KCard*> cards = stack[i]->cards();
bool first = true;
for (QList<KCard*>::ConstIterator it = cards.constBegin(); it != cards.constEnd(); ++it)
{
if (!first)
{
output += ' ';
}
first = false;
output += cardToRankSuitString(*it);
}
output += '\n';
}
cardsListToLine(output, stack[i]->cards());
return output;
}
......
......@@ -186,3 +186,18 @@ QString cardToRankSuitString(const KCard *const card)
{
return rankToString(card->rank()) + suitToString(card->suit());
}
void cardsListToLine(QString & output, const QList<KCard*> cards)
{
bool first = true;
for (QList<KCard*>::ConstIterator it = cards.constBegin(); it != cards.constEnd(); ++it)
{
if (!first)
{
output += ' ';
}
first = false;
output += cardToRankSuitString(*it);
}
output += '\n';
}
......@@ -35,5 +35,6 @@ bool checkAddAlternateColorDescendingFromKing( const QList<KCard*> & oldCards, c
extern QString suitToString(int s);
extern QString rankToString(int r);
extern QString cardToRankSuitString(const KCard*);
extern void cardsListToLine(QString & output, const QList<KCard*> cards);
#endif
......@@ -168,10 +168,7 @@ QString Simon::solverFormat() const
for (int i = 0; i < 10 ; i++)
{
QList<KCard*> cards = store[i]->cards();
for (QList<KCard*>::ConstIterator it = cards.constBegin(); it != cards.constEnd(); ++it)
output += cardToRankSuitString(*it) + ' ';
output += '\n';
cardsListToLine(output, store[i]->cards());
}
return output;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment