|
|
|
@ -212,6 +212,11 @@ class Solitaire : public olc::PixelGameEngine |
|
|
|
|
previousCardInteraction.clear(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool IsOppositeColor(Suit s1, Suit s2) { |
|
|
|
|
return (s1 == HEART || s1 == DIAMOND) && (s2 == CLUB || s2 == SPADE) || |
|
|
|
|
(s1 == CLUB || s1 == SPADE) && (s2 == HEART || s2 == DIAMOND); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void UpdateCardSlots() { |
|
|
|
|
if (GetMouse(0).bPressed&&MouseOver(PlayDeck)) { |
|
|
|
|
if (PlayDeck.faceDownCards.size() > 0) { |
|
|
|
@ -306,7 +311,24 @@ class Solitaire : public olc::PixelGameEngine |
|
|
|
|
} |
|
|
|
|
for (int i = 0; i < Field.size(); i++) { |
|
|
|
|
if (MouseOver(Field[i])) { |
|
|
|
|
|
|
|
|
|
if (Field[i].faceDownCards.size() + Field[i].faceUpCards.size() == 0 && draggedCard[0].number==13) { |
|
|
|
|
//The column is empty and the top-most card is a King.
|
|
|
|
|
for (int j = 0; j < draggedCard.size(); j++) { |
|
|
|
|
Field[i].faceUpCards.push_back(draggedCard[j]); |
|
|
|
|
} |
|
|
|
|
DeleteDraggedCard(); |
|
|
|
|
goto draggedCardSuccess; |
|
|
|
|
} else |
|
|
|
|
if (Field[i].faceUpCards.size() > 0 && IsOppositeColor(draggedCard[0].s, Field[i].faceUpCards[Field[i].faceUpCards.size() - 1].s)&& |
|
|
|
|
draggedCard[0].number==Field[i].faceUpCards[Field[i].faceUpCards.size() - 1].number-1) { |
|
|
|
|
//If the column has face up cards and the top dragged card's suit is the opposite color of the last face up card's suit
|
|
|
|
|
// and the dragged card's number is 1 less than the last face up card's number.
|
|
|
|
|
for (int j = 0; j < draggedCard.size(); j++) { |
|
|
|
|
Field[i].faceUpCards.push_back(draggedCard[j]); |
|
|
|
|
} |
|
|
|
|
DeleteDraggedCard(); |
|
|
|
|
goto draggedCardSuccess; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ResetDraggedCard(); |
|
|
|
@ -354,10 +376,6 @@ class Solitaire : public olc::PixelGameEngine |
|
|
|
|
diamond_spr.Load("assets/diamond.png"); |
|
|
|
|
heart_spr.Load("assets/heart.png"); |
|
|
|
|
spade_spr.Load("assets/spade.png"); |
|
|
|
|
Home[0].faceUpCards.push_back({ SPADE,1 }); |
|
|
|
|
Home[0].faceUpCards.push_back({ SPADE,2 }); |
|
|
|
|
Field[3].faceUpCards.push_back({ SPADE,3 }); |
|
|
|
|
Field[3].faceUpCards.push_back({ SPADE,4 }); |
|
|
|
|
for (int i = 0; i < Field.size(); i++) { |
|
|
|
|
for (int j = 0; j < i; j++) { |
|
|
|
|
Field[i].faceDownCards.push_back(DrawCard()); |
|
|
|
|