diff --git a/Solitaire/main.cpp b/Solitaire/main.cpp index f50458c..46e94d5 100644 --- a/Solitaire/main.cpp +++ b/Solitaire/main.cpp @@ -19,6 +19,7 @@ class Solitaire : public olc::PixelGameEngine DIAMOND, HEART, SPADE, + FACEDOWN, }; enum SlotType { @@ -57,19 +58,34 @@ class Solitaire : public olc::PixelGameEngine std::vector faceUpCards; std::vector flippedOverCards; //Just for active play deck. Face up cards will contain the rest of the pile. void RenderCard(vf2d pos, Suit s, int number) { - game->FillRectDecal(pos, CARD_SIZE, WHITE); - game->DrawStringDecal(pos + vf2d{ 2,2 }, number==1?"A":number == 13 ? "K" : number == 12 ? "Q" : number == 11 ? "J" : std::to_string(number), s == CLUB || s == SPADE ? BLACK : DARK_RED, number == 10 ? vf2d{0.6,1} : vf2d{1,1}); - game->DrawDecal(pos + vf2d{ 2,12 }, game->GetSprite(s), { 0.25,0.25 }); - game->DrawRotatedStringDecal(pos + CARD_SIZE - vf2d{ 2,2 }, number == 1 ? "A" : number == 13 ? "K" : number == 12 ? "Q" : number == 11 ? "J" : std::to_string(number), PI, { 0,0 }, s == CLUB||s==SPADE ? BLACK : DARK_RED, number == 10 ? vf2d{ 0.6,1 } : vf2d{ 1,1 }); - game->DrawRotatedDecal(pos + CARD_SIZE - vf2d{ 2,12 }, game->GetSprite(s), PI, { 0,0 }, { 0.25, 0.25 }); - game->DrawRectDecal(pos, CARD_SIZE, BLACK); + if (s == FACEDOWN) { + game->FillRectDecal(pos, CARD_SIZE, DARK_CYAN); + game->DrawRectDecal(pos, CARD_SIZE, BLACK); + } + else { + game->FillRectDecal(pos, CARD_SIZE, WHITE); + game->DrawStringDecal(pos + vf2d{ 2,2 }, number == 1 ? "A" : number == 13 ? "K" : number == 12 ? "Q" : number == 11 ? "J" : std::to_string(number), s == CLUB || s == SPADE ? BLACK : DARK_RED, number == 10 ? vf2d{ 0.6,1 } : vf2d{ 1,1 }); + game->DrawDecal(pos + vf2d{ 2,12 }, game->GetSprite(s), { 0.25,0.25 }); + game->DrawRotatedStringDecal(pos + CARD_SIZE - vf2d{ 2,2 }, number == 1 ? "A" : number == 13 ? "K" : number == 12 ? "Q" : number == 11 ? "J" : std::to_string(number), PI, { 0,0 }, s == CLUB || s == SPADE ? BLACK : DARK_RED, number == 10 ? vf2d{ 0.6,1 } : vf2d{ 1,1 }); + game->DrawRotatedDecal(pos + CARD_SIZE - vf2d{ 2,12 }, game->GetSprite(s), PI, { 0,0 }, { 0.25, 0.25 }); + game->DrawRectDecal(pos, CARD_SIZE, BLACK); + } } void RenderCards() { game->DrawRectDecal(pos, CARD_SIZE, BLACK); switch (type) { case PLAYDECK: { - if (faceDownCards.size() > 0) { - game->FillRectDecal(pos, CARD_SIZE, DARK_CYAN); + if (faceDownCards.size() > 6*3) { + RenderCard(pos+vi2d{-2,-2}, FACEDOWN, 0); + RenderCard(pos + vi2d{ -1,-1 }, FACEDOWN, 0); + RenderCard(pos, FACEDOWN, 0); + } else + if (faceDownCards.size() > 3 * 3) { + RenderCard(pos + vi2d{ -1,-1 }, FACEDOWN, 0); + RenderCard(pos, FACEDOWN, 0); + } + else { + RenderCard(pos, FACEDOWN, 0); } }break; case ACTIVE_PLAYDECK: { @@ -86,22 +102,43 @@ class Solitaire : public olc::PixelGameEngine } }break; case HOME: { - if (faceUpCards.size() > 0) { + if (faceUpCards.size() > 2) { + Card& c = faceUpCards[faceUpCards.size() - 1]; + RenderCard(pos+vi2d{-2,-2}, c.s, c.number); + c = faceUpCards[faceUpCards.size() - 2]; + RenderCard(pos + vi2d{ -1,-1 }, c.s, c.number); + c = faceUpCards[faceUpCards.size() - 3]; + RenderCard(pos, c.s, c.number); + } else + if (faceUpCards.size() > 1) { + Card& c = faceUpCards[faceUpCards.size() - 1]; + RenderCard(pos + vi2d{ -1,-1 }, c.s, c.number); + c = faceUpCards[faceUpCards.size() - 2]; + RenderCard(pos, c.s, c.number); + } + else + if (faceUpCards.size() == 1) { Card& c = faceUpCards[faceUpCards.size() - 1]; RenderCard(pos, c.s, c.number); } }break; case FIELD: { + int cardSpacing = 16; + int totalCards = faceDownCards.size() + faceUpCards.size(); + int spaceTakenUp = CARD_SIZE.y + totalCards * cardSpacing; + while (spaceTakenUp + pos.y > game->ScreenHeight()) { + cardSpacing--; + spaceTakenUp = CARD_SIZE.y + totalCards * cardSpacing; + } + for (int i = 0; i < faceDownCards.size(); i++) { + RenderCard(pos + vi2d{ 0,i * cardSpacing },FACEDOWN, 0); + } if (faceUpCards.size() > 0) { for (int i = 0; i < faceUpCards.size(); i++) { Card& c = faceUpCards[i]; - RenderCard(pos + vi2d{ 0,i * 16 }, c.s, c.number); + RenderCard(pos + vi2d{ 0,(i+(int)faceDownCards.size()) * cardSpacing }, c.s, c.number); } } - else - if (faceDownCards.size()>0){ - game->FillRectDecal(pos, CARD_SIZE, DARK_CYAN); - } }break; } }