ReactOS 0.4.16-dev-336-gb667d82
solundo.cpp File Reference
#include "solitaire.h"
Include dependency graph for solundo.cpp:

Go to the source code of this file.

Functions

void SetUndo (int set_source_id, int set_destination_id, int set_number_of_cards, int set_prev_score, int set_prev_visible_pile_cards)
 
void ClearUndo (void)
 
void Undo (void)
 

Variables

static int source_id = -1
 
static int destination_id = -1
 
static int number_of_cards = 0
 
static int prev_score = 0
 
static int prev_visible_pile_cards = 0
 

Function Documentation

◆ ClearUndo()

void ClearUndo ( void  )

Definition at line 45 of file solundo.cpp.

46{
47 source_id = -1;
48 destination_id = -1;
50 SetUndoMenuState(false);
51}
void SetUndoMenuState(bool enable)
Definition: solitaire.cpp:183
static int destination_id
Definition: solundo.cpp:16
static int number_of_cards
Definition: solundo.cpp:19
static int source_id
Definition: solundo.cpp:15

Referenced by NewGame(), RowStackClickProc(), SuitStackAddProc(), and Undo().

◆ SetUndo()

void SetUndo ( int  set_source_id,
int  set_destination_id,
int  set_number_of_cards,
int  set_prev_score,
int  set_prev_visible_pile_cards 
)

Definition at line 27 of file solundo.cpp.

33{
34 if ((set_source_id == set_destination_id) || (set_number_of_cards == 0))
35 return;
36
37 source_id = set_source_id;
38 destination_id = set_destination_id;
39 number_of_cards = set_number_of_cards;
40 prev_score = set_prev_score;
41 prev_visible_pile_cards = set_prev_visible_pile_cards;
42 SetUndoMenuState(true);
43}
static int prev_score
Definition: solundo.cpp:22
static int prev_visible_pile_cards
Definition: solundo.cpp:25

Referenced by DeckClickProc(), RowStackDropProc(), and SuitStackDropProc().

◆ Undo()

void Undo ( void  )

Definition at line 53 of file solundo.cpp.

54{
56 CardRegion *destination = NULL;
57
58 if ((source_id < 1) ||
59 (source_id > (ROW_ID + NUM_ROW_STACKS - 1)) ||
60 (destination_id < 1) ||
62 (number_of_cards < 1))
63 {
64 ClearUndo();
65 return;
66 }
67
68 if (source_id >= ROW_ID)
70 else if ((source_id >= SUIT_ID) && (source_id < SUIT_ID + 4))
72 else if (source_id == PILE_ID)
73 source = pPile;
74 else if (source_id == DECK_ID)
75 source = pDeck;
76
78 destination = pRowStack[destination_id - ROW_ID];
79 else if ((destination_id >= SUIT_ID) && (destination_id < SUIT_ID + 4))
80 destination = pSuitStack[destination_id - SUIT_ID];
81 else if (destination_id == PILE_ID)
82 destination = pPile;
83 else if (destination_id == DECK_ID)
84 destination = pDeck;
85
86 if (destination == NULL || source == NULL)
87 {
88 ClearUndo();
89 return;
90 }
91
92 // If the player clicked on the deck.
93 if (destination == pPile && source == pDeck)
94 {
95 // Put back the cards on the deck in reversed order.
97 tmp.Reverse();
98 source->Push(tmp);
99 // Restore the pile to be the top cards in the active pile.
100 destination->Clear();
102 {
103 destination->SetOffsets(0,0);
104 destination->SetCardStack(activepile);
105 }
106 else
107 {
109 destination->SetOffsets(CS_DEFXOFF, 1);
110 destination->Push(tmp);
111 }
113 }
114
115 // If the player clicked on the empty deck.
116 else if (source == pPile && destination == pDeck)
117 {
118 // Put back all the cards from the deck to the active pile in reversed order.
119 destination->Reverse();
120 activepile.Push(destination->GetCardStack());
121 destination->Clear();
123 {
124 source->SetOffsets(0,0);
125 source->SetCardStack(activepile);
126 }
127 else
128 {
130 source->SetOffsets(CS_DEFXOFF, 1);
131 source->Push(tmp);
132 }
134 }
135
136 // If the player moved one card from the pile.
137 else if (source == pPile)
138 {
139 CardStack tmp = destination->Pop(1);
140 activepile.Push(tmp);
142 {
143 source->Push(tmp);
144 }
145 else
146 {
147 source->Clear();
149 source->Push(tmp);
150 source->SetOffsets(CS_DEFXOFF, 1);
151 }
153 }
154
155 // If the player moved cards between row stacks / suit stacks.
156 else
157 {
158 destination->MoveCard(source, number_of_cards, false);
159 }
160
162
163 // -2 points for the undo in standard score mode.
164 if (GetScoreMode() == SCORE_STD)
165 lScore = lScore >= 2 ? lScore - 2 : 0;
166
168
169 SolWnd.Redraw();
170 ClearUndo();
171}
#define CS_DEFXOFF
Definition: cardlib.h:23
void Push(const Card card)
Definition: cardregion.h:88
bool MoveCard(CardRegion *pDestStack, int nNumCards, bool fAnimate)
Definition: cardregion.cpp:477
void Reverse()
Definition: cardregion.h:86
void SetCardStack(const CardStack &cs)
Definition: cardregion.cpp:390
const CardStack & GetCardStack()
Definition: cardregion.cpp:399
void SetOffsets(int x, int y)
Definition: cardregion.cpp:228
void Clear()
Definition: cardregion.h:84
Card Pop()
Definition: cardregion.h:91
Card Top()
Definition: cardstack.cpp:151
void Push(const Card card)
Definition: cardstack.cpp:83
void Reverse()
Definition: cardstack.cpp:73
Card Pop()
Definition: cardstack.cpp:127
void Redraw(void)
Definition: cardwindow.cpp:553
#define NULL
Definition: types.h:112
CardRegion * pSuitStack[4]
Definition: solcreate.cpp:5
CardRegion * pDeck
Definition: solcreate.cpp:3
CardRegion * pPile
Definition: solcreate.cpp:4
CardRegion * pRowStack[NUM_ROW_STACKS]
Definition: solcreate.cpp:6
int VisiblePileCards
Definition: solgame.cpp:13
CardStack activepile
Definition: solgame.cpp:12
void UpdateStatusBar(void)
Definition: solitaire.cpp:150
int GetScoreMode(void)
Definition: solitaire.cpp:130
CardWindow SolWnd
Definition: solitaire.cpp:34
long lScore
Definition: solitaire.cpp:31
#define PILE_ID
Definition: solitaire.h:40
#define ROW_ID
Definition: solitaire.h:42
#define SUIT_ID
Definition: solitaire.h:41
#define NUM_ROW_STACKS
Definition: solitaire.h:38
#define SCORE_STD
Definition: solitaire.h:45
#define DECK_ID
Definition: solitaire.h:39
void ClearUndo(void)
Definition: solundo.cpp:45

Referenced by WndProc().

Variable Documentation

◆ destination_id

int destination_id = -1
static

Definition at line 16 of file solundo.cpp.

Referenced by ClearUndo(), SetUndo(), and Undo().

◆ number_of_cards

int number_of_cards = 0
static

Definition at line 19 of file solundo.cpp.

Referenced by ClearUndo(), SetUndo(), and Undo().

◆ prev_score

int prev_score = 0
static

Definition at line 22 of file solundo.cpp.

Referenced by SetUndo(), and Undo().

◆ prev_visible_pile_cards

int prev_visible_pile_cards = 0
static

Definition at line 25 of file solundo.cpp.

Referenced by SetUndo(), and Undo().

◆ source_id