Add clang-format config & format files
This commit is contained in:
parent
ddb17f8bba
commit
36a010d5aa
65
.clang-format
Normal file
65
.clang-format
Normal file
|
@ -0,0 +1,65 @@
|
|||
---
|
||||
Language: Cpp
|
||||
BasedOnStyle: LLVM
|
||||
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveMacros: None
|
||||
AlignConsecutiveAssignments: None
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: DontAlign
|
||||
AlignTrailingComments: false
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: Always
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeTernaryOperators: false
|
||||
BreakConstructorInitializers: AfterColon
|
||||
ColumnLimit: 180
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: false
|
||||
IncludeBlocks: Preserve
|
||||
IndentCaseLabels: true
|
||||
IndentWidth: 4
|
||||
PointerAlignment: Left
|
||||
ReflowComments: false
|
||||
SortIncludes: CaseSensitive
|
||||
SortUsingDeclarations: false
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: Never
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Auto
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
|
||||
BraceWrapping:
|
||||
AfterEnum: false
|
||||
|
||||
AlignConsecutiveDeclarations: None
|
||||
|
||||
NamespaceIndentation: All
|
|
@ -1,8 +1,6 @@
|
|||
#include "columnslot.h"
|
||||
|
||||
ColumnSlot::ColumnSlot(PlayingCard* card, bool revealed, QObject* parent)
|
||||
: QObject(parent), m_card(card), m_revealed(revealed)
|
||||
{}
|
||||
ColumnSlot::ColumnSlot(PlayingCard* card, bool revealed, QObject* parent) : QObject(parent), m_card(card), m_revealed(revealed) {}
|
||||
|
||||
PlayingCard* ColumnSlot::card() const {
|
||||
return m_card;
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
#ifndef COLUMNSLOT_H
|
||||
#define COLUMNSLOT_H
|
||||
|
||||
#include "playingcard.h"
|
||||
#include <QObject>
|
||||
#include <qqmlintegration.h>
|
||||
#include "playingcard.h"
|
||||
|
||||
class ColumnSlot : public QObject
|
||||
{
|
||||
class ColumnSlot : public QObject {
|
||||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
QML_UNCREATABLE("Use C++ logic to instantiate")
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
#include "gamestate.h"
|
||||
#include <random>
|
||||
#include <QDebug>
|
||||
#include <random>
|
||||
|
||||
GameState::GameState(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
GameState::GameState(QObject* parent) : QObject{parent} {
|
||||
assert(connect(this, SIGNAL(foundationChanged()), this, SLOT(onFoundationChanged())));
|
||||
|
||||
m_foundation.resize(4);
|
||||
|
@ -13,8 +11,7 @@ GameState::GameState(QObject *parent)
|
|||
dealCards();
|
||||
}
|
||||
|
||||
void GameState::dealCards()
|
||||
{
|
||||
void GameState::dealCards() {
|
||||
qDebug() << "Dealing cards";
|
||||
cleanupBoard(false);
|
||||
|
||||
|
@ -51,8 +48,7 @@ void GameState::dealCards()
|
|||
emit foundationChanged();
|
||||
}
|
||||
|
||||
void GameState::setupWinningDeck()
|
||||
{
|
||||
void GameState::setupWinningDeck() {
|
||||
qDebug() << "Setting up a winning deck";
|
||||
cleanupBoard(false);
|
||||
|
||||
|
@ -92,8 +88,7 @@ void GameState::setupWinningDeck()
|
|||
emit foundationChanged();
|
||||
}
|
||||
|
||||
void GameState::drawNextCard()
|
||||
{
|
||||
void GameState::drawNextCard() {
|
||||
qDebug() << "Drawing next card.";
|
||||
|
||||
// If drawPile is empty, flip the throwawayPile to drawPile
|
||||
|
@ -116,8 +111,7 @@ void GameState::drawNextCard()
|
|||
emit throwawayPileChanged();
|
||||
}
|
||||
|
||||
bool GameState::moveThrownCardToColumn(int columnId)
|
||||
{
|
||||
bool GameState::moveThrownCardToColumn(int columnId) {
|
||||
assert(columnId >= 0 && columnId < 7);
|
||||
auto& columnStack = m_columns[columnId];
|
||||
|
||||
|
@ -146,8 +140,7 @@ bool GameState::moveThrownCardToColumn(int columnId)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool GameState::moveThrownCardToFoundation(int foundationId)
|
||||
{
|
||||
bool GameState::moveThrownCardToFoundation(int foundationId) {
|
||||
assert(foundationId >= 0 && foundationId < 4);
|
||||
auto& foundationStack = m_foundation[foundationId];
|
||||
|
||||
|
@ -176,8 +169,7 @@ bool GameState::moveThrownCardToFoundation(int foundationId)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool GameState::moveColumnCardToColumn(int fromColumnId, int toColumnId, int fromCardIndex)
|
||||
{
|
||||
bool GameState::moveColumnCardToColumn(int fromColumnId, int toColumnId, int fromCardIndex) {
|
||||
assert(fromColumnId >= 0 && fromColumnId < 7);
|
||||
assert(toColumnId >= 0 && toColumnId < 7);
|
||||
auto fromColumnStack = m_columns[fromColumnId];
|
||||
|
@ -213,8 +205,7 @@ bool GameState::moveColumnCardToColumn(int fromColumnId, int toColumnId, int fro
|
|||
return true;
|
||||
}
|
||||
|
||||
bool GameState::moveColumnCardToFoundation(int columnId, int foundationId)
|
||||
{
|
||||
bool GameState::moveColumnCardToFoundation(int columnId, int foundationId) {
|
||||
assert(columnId >= 0 && columnId < 7);
|
||||
assert(foundationId >= 0 && foundationId < 4);
|
||||
auto& columnStack = m_columns[columnId];
|
||||
|
@ -246,11 +237,9 @@ bool GameState::moveColumnCardToFoundation(int columnId, int foundationId)
|
|||
emit columnsChanged(); // CRASH (not if I remove the delete col line though)
|
||||
emit foundationChanged();
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool GameState::autoMoveThrownCard()
|
||||
{
|
||||
bool GameState::autoMoveThrownCard() {
|
||||
if (m_throwawayPile.isEmpty()) {
|
||||
qWarning() << "Attempted to move thrown card to foundation with empty throwaway pile";
|
||||
return false;
|
||||
|
@ -272,7 +261,6 @@ bool GameState::autoMoveThrownCard()
|
|||
|
||||
emit throwawayPileChanged();
|
||||
|
||||
|
||||
// We don't know which pile the card was moved to, to be safe, emit
|
||||
// a change from both
|
||||
// NOTE: consider returning what changed from tryAutoMoveSingleCard
|
||||
|
@ -282,8 +270,7 @@ bool GameState::autoMoveThrownCard()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool GameState::autoMoveColumnCard(int columnId, int cardIndex)
|
||||
{
|
||||
bool GameState::autoMoveColumnCard(int columnId, int cardIndex) {
|
||||
assert(columnId >= 0 && columnId < 7);
|
||||
auto& columnStack = m_columns[columnId];
|
||||
|
||||
|
@ -349,8 +336,7 @@ bool GameState::autoMoveColumnCard(int columnId, int cardIndex)
|
|||
return true;
|
||||
}
|
||||
|
||||
void GameState::onFoundationChanged()
|
||||
{
|
||||
void GameState::onFoundationChanged() {
|
||||
// Check if the game is won (can only happen on a foundation pile change)
|
||||
bool gameWon = true;
|
||||
for (const QList<PlayingCard*>& foundationPile : std::as_const(m_foundation)) {
|
||||
|
@ -371,8 +357,7 @@ void GameState::onFoundationChanged()
|
|||
emit gameWonChanged();
|
||||
}
|
||||
|
||||
void GameState::cleanupBoard(bool emitChanges)
|
||||
{
|
||||
void GameState::cleanupBoard(bool emitChanges) {
|
||||
// Clean up all PlayingCard objects in the draw pile
|
||||
for (auto& card : m_drawPile) {
|
||||
card->deleteLater();
|
||||
|
@ -414,8 +399,7 @@ void GameState::cleanupBoard(bool emitChanges)
|
|||
}
|
||||
}
|
||||
|
||||
bool GameState::tryAutoMoveSingleCard(PlayingCard &cardToMove, int skipColumnId)
|
||||
{
|
||||
bool GameState::tryAutoMoveSingleCard(PlayingCard& cardToMove, int skipColumnId) {
|
||||
// 1. Try moving the card to the foundation
|
||||
const int foundationId = static_cast<int>(cardToMove.suit());
|
||||
if (isFoundationMoveValid(cardToMove, foundationId)) {
|
||||
|
@ -442,8 +426,7 @@ bool GameState::tryAutoMoveSingleCard(PlayingCard &cardToMove, int skipColumnId)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool GameState::tryAutoMoveMultipleCards(const QList<PlayingCard*>& cards, int skipColumnId)
|
||||
{
|
||||
bool GameState::tryAutoMoveMultipleCards(const QList<PlayingCard*>& cards, int skipColumnId) {
|
||||
assert(cards.size() > 1);
|
||||
|
||||
// If we can move the first (selected) card to another column,
|
||||
|
@ -471,8 +454,7 @@ bool GameState::tryAutoMoveMultipleCards(const QList<PlayingCard*>& cards, int s
|
|||
return false;
|
||||
}
|
||||
|
||||
bool GameState::isFoundationMoveValid(const PlayingCard& cardToMove, int foundationId)
|
||||
{
|
||||
bool GameState::isFoundationMoveValid(const PlayingCard& cardToMove, int foundationId) {
|
||||
assert(foundationId >= 0 && foundationId < 4);
|
||||
const auto foundationSuit = static_cast<PlayingCard::Suit>(foundationId);
|
||||
const auto& foundationStack = m_foundation[foundationId];
|
||||
|
@ -523,9 +505,7 @@ bool GameState::isColumnMoveValid(const PlayingCard& cardToMove, int columnId) {
|
|||
return PlayingCard::areOppositeColors(cardToMove, columnCard);
|
||||
}
|
||||
|
||||
|
||||
void GameState::ensureColumnRevealed(int columnId)
|
||||
{
|
||||
void GameState::ensureColumnRevealed(int columnId) {
|
||||
assert(columnId >= 0 && columnId < 7);
|
||||
auto& columnStack = m_columns[columnId];
|
||||
|
||||
|
@ -545,27 +525,22 @@ void GameState::ensureColumnRevealed(int columnId)
|
|||
qDebug() << "Revealed card " << col->card()->toString() << " in column " << columnId;
|
||||
}
|
||||
|
||||
QList<PlayingCard *> GameState::drawPile() const
|
||||
{
|
||||
QList<PlayingCard*> GameState::drawPile() const {
|
||||
return m_drawPile;
|
||||
}
|
||||
|
||||
QList<PlayingCard *> GameState::throwawayPile() const
|
||||
{
|
||||
QList<PlayingCard*> GameState::throwawayPile() const {
|
||||
return m_throwawayPile;
|
||||
}
|
||||
|
||||
QList<QList<ColumnSlot *> > GameState::columns() const
|
||||
{
|
||||
QList<QList<ColumnSlot*> > GameState::columns() const {
|
||||
return m_columns;
|
||||
}
|
||||
|
||||
QList<QList<PlayingCard *> > GameState::foundation() const
|
||||
{
|
||||
QList<QList<PlayingCard*> > GameState::foundation() const {
|
||||
return m_foundation;
|
||||
}
|
||||
|
||||
bool GameState::gameWon() const
|
||||
{
|
||||
bool GameState::gameWon() const {
|
||||
return m_gameWon;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
#ifndef GAMESTATE_H
|
||||
#define GAMESTATE_H
|
||||
|
||||
#include "columnslot.h"
|
||||
#include "playingcard.h"
|
||||
#include <QObject>
|
||||
#include <qqmlintegration.h>
|
||||
#include "playingcard.h"
|
||||
#include "columnslot.h"
|
||||
|
||||
class GameState : public QObject
|
||||
{
|
||||
class GameState : public QObject {
|
||||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
QML_SINGLETON
|
||||
|
|
12
src/main.cpp
12
src/main.cpp
|
@ -1,19 +1,13 @@
|
|||
#include "gamestate.h"
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include "gamestate.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char* argv[]) {
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
QObject::connect(
|
||||
&engine,
|
||||
&QQmlApplicationEngine::objectCreationFailed,
|
||||
&app,
|
||||
[]() { QCoreApplication::exit(-1); },
|
||||
Qt::QueuedConnection);
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection);
|
||||
|
||||
auto gameState = engine.singletonInstance<GameState*>("Solitare", "GameState");
|
||||
gameState->setupWinningDeck();
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
#include "playingcard.h"
|
||||
|
||||
PlayingCard::PlayingCard(const PlayingCard::Suit &suit, const PlayingCard::Value &value, QObject *parent)
|
||||
: QObject{parent}, m_suit{suit}, m_value{value}
|
||||
{ }
|
||||
PlayingCard::PlayingCard(const PlayingCard::Suit& suit, const PlayingCard::Value& value, QObject* parent) : QObject{parent}, m_suit{suit}, m_value{value} {}
|
||||
|
||||
PlayingCard::Suit PlayingCard::suit() const
|
||||
{
|
||||
PlayingCard::Suit PlayingCard::suit() const {
|
||||
return m_suit;
|
||||
}
|
||||
|
||||
QString PlayingCard::suitString() const
|
||||
{
|
||||
QString PlayingCard::suitString() const {
|
||||
switch (m_suit) {
|
||||
case Clubs: return "clubs";
|
||||
case Diamonds: return "diamonds";
|
||||
|
@ -20,8 +16,7 @@ QString PlayingCard::suitString() const
|
|||
}
|
||||
}
|
||||
|
||||
void PlayingCard::setSuit(const PlayingCard::Suit &suit)
|
||||
{
|
||||
void PlayingCard::setSuit(const PlayingCard::Suit& suit) {
|
||||
if (m_suit == suit)
|
||||
return;
|
||||
|
||||
|
@ -29,13 +24,11 @@ void PlayingCard::setSuit(const PlayingCard::Suit &suit)
|
|||
emit suitChanged();
|
||||
}
|
||||
|
||||
PlayingCard::Value PlayingCard::value() const
|
||||
{
|
||||
PlayingCard::Value PlayingCard::value() const {
|
||||
return m_value;
|
||||
}
|
||||
|
||||
QString PlayingCard::valueString() const
|
||||
{
|
||||
QString PlayingCard::valueString() const {
|
||||
switch (m_value) {
|
||||
case Ace: return "ace";
|
||||
case Two: return "2";
|
||||
|
@ -54,8 +47,7 @@ QString PlayingCard::valueString() const
|
|||
}
|
||||
}
|
||||
|
||||
void PlayingCard::setValue(const PlayingCard::Value &value)
|
||||
{
|
||||
void PlayingCard::setValue(const PlayingCard::Value& value) {
|
||||
if (m_value == value)
|
||||
return;
|
||||
|
||||
|
@ -63,13 +55,11 @@ void PlayingCard::setValue(const PlayingCard::Value &value)
|
|||
emit valueChanged();
|
||||
}
|
||||
|
||||
QString PlayingCard::toString() const
|
||||
{
|
||||
QString PlayingCard::toString() const {
|
||||
return valueString() + " of " + suitString();
|
||||
}
|
||||
|
||||
QList<PlayingCard *> PlayingCard::createDeck()
|
||||
{
|
||||
QList<PlayingCard*> PlayingCard::createDeck() {
|
||||
QList<PlayingCard*> deck;
|
||||
|
||||
for (int suitIndex = PlayingCard::Suit::Clubs; suitIndex <= PlayingCard::Suit::Spades; ++suitIndex) {
|
||||
|
@ -84,8 +74,7 @@ QList<PlayingCard *> PlayingCard::createDeck()
|
|||
return deck;
|
||||
}
|
||||
|
||||
bool PlayingCard::areOppositeColors(const PlayingCard &card1, const PlayingCard &card2)
|
||||
{
|
||||
bool PlayingCard::areOppositeColors(const PlayingCard& card1, const PlayingCard& card2) {
|
||||
bool card1IsRed = (card1.suit() == Suit::Hearts || card1.suit() == Suit::Diamonds);
|
||||
bool card2IsRed = (card2.suit() == Suit::Hearts || card2.suit() == Suit::Diamonds);
|
||||
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
#include <QObject>
|
||||
#include <qqmlintegration.h>
|
||||
|
||||
class PlayingCard : public QObject
|
||||
{
|
||||
class PlayingCard : public QObject {
|
||||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
QML_UNCREATABLE("Use C++ logic to instantiate")
|
||||
|
|
Loading…
Reference in a new issue