-#if 0
-void GameWidget::DrawBoard(QPainter * painter, QRect r)
-{
- // Use "r" as clipping rect--only draw what's necessary
-
-// pDC->BitBlt(r.left, r.top, r.Width(), r.Height(), pDC2, r.left, r.top, SRCCOPY);
-
- // Draw the solitaire board...
-
- for(int i=0; i<7; i++)
- {
- int y = 126; //130-4;
-
- for(int j=0; j<19; j++)
- {
- int card = solBoard[i][j];
-
- if (card != -1 && !(hitStack && (i == stackStart.x()) && (j >= stackStart.y())))
- {
- int nLinesToDraw = 0; // Default--draws whole card
-
- if (solBoard[i][j + 1] != -1 && !(hitStack && (i == stackStart.x()) && (j + 1 >= stackStart.y())))
- {
- nLinesToDraw = 6;
-
- if (myDeck.IsFaceUp(card))
- nLinesToDraw += 14;
- }
-
- int x = 10 + (i * (CARD_WIDTH + 8));//, y = 130 + (j * 4);
- y += 4;
-
- if (j > 0)
- {
- if (myDeck.IsFaceUp(solBoard[i][j - 1])) // Previous card...
- y += 14;
- }
-
- //wil wok??? mebbe... YESH!!!!!!!!!!!!!
- QRect cardRect(x, y, CARD_WIDTH, (nLinesToDraw ? nLinesToDraw : CARD_HEIGHT));
-
- if (r.intersects(cardRect))
- cdtDraw(painter, x, y, (myDeck.IsFaceUp(card) ? myDeck.GetCardAtPos(card)
- : nCardBack), FACEUP, nLinesToDraw);
- }
- }
- }
-
- for(int i=0; i<4; i++)
- {
- if (nHitAce == i + 1)
- {
- if (((nAce[i] - 1) % 13) != 0)
- cdtDraw(painter, 200 + ((CARD_WIDTH + 4) * i), 7, nAce[i] - 1, FACEUP);
- else
- cdtDraw(painter, 200 + ((CARD_WIDTH + 4) * i), 7, 0, INVISIBLEGHOST);
- }
- else
- {
- if (nAce[i] != -1)
- cdtDraw(painter, 200 + ((CARD_WIDTH + 4) * i), 7, nAce[i], FACEUP);
- else
- cdtDraw(painter, 200 + ((CARD_WIDTH + 4) * i), 7, 0, INVISIBLEGHOST);
- }
- }
-
- if (stack1p != -1)
- cdtDraw(painter, 5, 7, nCardBack, FACEUP);
- else
- {
-#if 0
- if (m_bShowX)
- cdtDraw(painter, 5, 7, 0, DECKX);
- else
- cdtDraw(painter, 5, 7, 0, DECKO);
-#else
- cdtDraw(painter, 5, 7, 0, (m_bShowX ? DECKX : DECKO));
-#endif
- }
-
- if (stack2p != -1)
- {
- if (!hitDiscard)
- {
- for(int k=0; k<m_nNumToSplay; k++)
- cdtDraw(painter, 5 + CARD_WIDTH + 6 + (k * 12), 7 + (k * 2),
- myDeck.GetCardAtPos(stack2[stack2p - (m_nNumToSplay - k - 1)]), FACEUP);
- }
- else
- {
- if (stack2p != 0)
- {
- if (m_nNumToSplay == 1)
- cdtDraw(painter, 5 + CARD_WIDTH + 6, 7, myDeck.GetCardAtPos(stack2[stack2p - 1]), FACEUP);
- else
- for(int k=0; k<m_nNumToSplay-1; k++)
- cdtDraw(painter, 5 + CARD_WIDTH + 6 + (k * 12), 7 + (k * 2),
- myDeck.GetCardAtPos(stack2[stack2p - (m_nNumToSplay - k - 1)]), FACEUP);
- }
- }
- }
-}
-
-
-void GameWidget::OnLButtonDown(QPoint point)
-{
- dcHitStack = dcHitDiscard = false; // For double clicking...
- m_bTouchedGame = true; // Game has been attempted!
-
- if (!allowUserInput)
- return;
-
- mouseDown = true;
-
- // Set undo up...
- for(int i=0; i<7; i++)
- for(int j=0; j<20; j++)
- solBoardUndo[i][j] = solBoard[i][j];
-
- for(int i=0; i<24; i++)
- stack1Undo[i] = stack1[i], stack2Undo[i] = stack2[i];
-
- for(int i=0; i<4; i++)
- nAceUndo[i] = nAce[i];
-
- stack1pUndo = stack1p, stack2pUndo = stack2p;
- m_nScoreUndo = m_nScore;
- m_nExhaustedDeckUndo = m_nExhaustedDeck;
- m_nNumToSplayUndo = m_nNumToSplay;
- m_bShowXUndo = m_bShowX;
- m_bCanUndo = false;
-
- // Check for a hit on the tableaux...
-
- for(int i=0; i<7; i++)
- {
- QRect r;
- r.setLeft(10 + (i * (CARD_WIDTH + 8)));
- r.setRight(r.left() + CARD_WIDTH - 1);
- r.setTop(130);
- int nCards = 0;
-
- for(int j=0; j<19; j++)
- {
- if (solBoard[i][j] != -1)
- {
- if (myDeck.IsFaceUp(solBoard[i][j]))
- {
- if ((j == 18) || (solBoard[i][j + 1] == -1))
- r.setBottom(r.top() + CARD_HEIGHT - 1);
- else
- r.setBottom(r.top() + 17);
-
- if (r.contains(point))
- {
- hitStack = dcHitStack = true;
- stackStart = QPoint(i, j);
- mouseOffset = QPoint(point.x() - r.left(), point.y() - r.top());
- stackPos = QPoint(point.x() - mouseOffset.x(), point.y() - mouseOffset.y());
- QRect rcUpdate(r.left(), r.top(), r.width(), CARD_HEIGHT - 1); //wil wok?
- return;
- }
-
- r.setTop(r.top() + 18);
- }
- else
- {
- if (j != 18)
- {
- if (solBoard[i][j + 1] == -1)
- {
- r.setBottom(r.top() + CARD_HEIGHT - 1);
-
- if (r.contains(point))
- {
- myDeck.ToggleCardFacing(solBoard[i][j]); // Turn over that last card
-
-#if HAVE_SOUND
- if (bSoundOn)
- PlaySound(IDW_CARDFLIP);
-#endif
-
- update(r); //wil wok?
-
- // Scoring...
- if (!m_bVegasStyle)
- {
- m_nScore += 5;
- emit UpdateScore(m_nScore);
- }
-
- return;
- }
- }
- }
-
- r.setTop(r.top() + 4);
- }
-
- nCards++;
- }
- }
- }
-
- // Check for hit on discard stack
-
- int nCX = 5 + CARD_WIDTH + 6 + ((m_nNumToSplay - 1) * 12);
- int nCY = 7 + ((m_nNumToSplay - 1) * 2);
-
- if (QRect(nCX, nCY, CARD_WIDTH - 1, CARD_HEIGHT - 1).contains(point))
- {
- if (stack2p != -1)
- {
- hitDiscard = dcHitDiscard = true;
- mouseOffset = QPoint(point.x() - (5 + CARD_WIDTH + 6 + ((m_nNumToSplay - 1) * 12)),
- point.y() - (7 + ((m_nNumToSplay - 1) * 2)));
- stackPos = QPoint(point.x() - mouseOffset.x(), point.y() - mouseOffset.y());
- return;
- }
- }
-
- // Check for hit on remaining deck
-
- if (QRect(5, 7, 5 + CARD_WIDTH - 1, 7 + CARD_HEIGHT - 1).contains(point))
- {
- m_bCanUndo = true;
-
- if (stack1p == -1) // I.e. it's empty...
- {
- // Scoring...
- if ((m_bDrawThree && (m_nExhaustedDeck == 3))
- || (!m_bDrawThree && (m_nExhaustedDeck == 1)))
- {
- if (!m_bVegasStyle)
- {
- m_nExhaustedDeck = 0;
- m_nScore -= (m_bDrawThree ? 20 : 100);
-
- if (m_nScore < 0)
- m_nScore = 0;
-
- emit UpdateScore(m_nScore);
- }
- }
- if (!m_bVegasStyle || (m_bVegasStyle && ((m_bDrawThree && (m_nExhaustedDeck < 3))
- || (!m_bDrawThree && (m_nExhaustedDeck < 1)))))
- {
- for(; stack2p != -1; stack2p--)
- {
- stack1p++;
- stack1[stack1p] = stack2[stack2p];
- }
-
-#if HAVE_SOUND
- if (bSoundOn)
- PlaySound(IDW_CARDKNOCK);
-#endif
- }
- }
- else
- {
- m_nNumToSplay = 0;
-
- for(int i=0; i<(m_bDrawThree ? 3 : 1); i++)
- {
- if (stack1p != -1) // I.e., there are cards left...
- {
- stack2[++stack2p] = stack1[stack1p--];
-
-#if HAVE_SOUND
- if (bSoundOn)
- {
- PlaySound(IDW_CARDFLIP);
- // Pause
- Pause(55);
- }
-#endif
-
- m_nNumToSplay++;
- }
- }
-
- if (stack1p == -1) // This is done here because it's right!
- {
- m_nExhaustedDeck++;
-
- if (m_bVegasStyle && ((m_bDrawThree && (m_nExhaustedDeck == 3))
- || (!m_bDrawThree && (m_nExhaustedDeck == 1))))
- m_bShowX = true;
- }
- }
-
- mouseOffset = QPoint(point.x() - 5, point.y() - 7);
-
- QRect inv1(5, 7, CARD_WIDTH, CARD_HEIGHT),
- inv2(5 + CARD_WIDTH + 6, 7, (2 * 12) + CARD_WIDTH, (2 * 2) + CARD_HEIGHT);
- update(inv1);
- update(inv2);
- }
-
- // Check for hit on ace piles
-
- for(int i=0; i<4; i++)
- {
- QRect aceRect(200 + ((CARD_WIDTH + 4) * i), 7, CARD_WIDTH - 1, CARD_HEIGHT - 1);
-
- if (aceRect.contains(point) && (nAce[i] > -1))
- {
- nHitAce = i + 1;
-// mouseOffset = QPoint(point.x() - (200 + ((CARD_WIDTH + 4) * i)), point.y() - 7);
- mouseOffset = QPoint(point.x() - aceRect.x(), point.y() - aceRect.y());
- stackPos = QPoint(point.x() - mouseOffset.x(), point.y() - mouseOffset.y());
- return;
- }
- }
-}
-
-
-void GameWidget::OnLButtonUp(QPoint point)
-{
- if (!allowUserInput)
- return;
-
- point -= mouseOffset; // ?? bad form!
-
- if (hitStack || hitDiscard || (nHitAce != 0))
- {
- QRect tabl[7];
-
- for(int i=0; i<7; i++) // Compute valid rects at bottoms of stacks...
- {
- tabl[i].setLeft(10 + (i * (CARD_WIDTH + 8)));
- tabl[i].setRight(tabl[i].left() + CARD_WIDTH - 1);
- tabl[i].setTop(130);
-
- for(int j=0; j<19; j++)
- {
- if ((solBoard[i][j] == -1)
- || (hitStack && (i == stackStart.x()) && (j == stackStart.y())))
- {
- if (j > 0)
- {
- for(int k=0; k<j-1; k++)
- {
- if (!myDeck.IsFaceUp(solBoard[i][k]))
- tabl[i].setTop(tabl[i].top() + 4);
- else
- tabl[i].setTop(tabl[i].top() + 17);
- }
- }
-
- tabl[i].setBottom(tabl[i].top() + CARD_HEIGHT - 1);
- break;
- }
- }
- }
-
-// stackPos = QPoint(point.x() - mouseOffset.x(), point.y() - mouseOffset.y());
-// QRect c(point.x(), point.y(), CARD_WIDTH - 1, CARD_HEIGHT - 1);
-// QRect c(point.x() - mouseOffset.x(), point.y() - mouseOffset.y(), CARD_WIDTH - 1, CARD_HEIGHT - 1);
- QRect c(stackPos.x(), stackPos.y(), CARD_WIDTH - 1, CARD_HEIGHT - 1);
- QRect a[4];
- a[0] = QRect(200, 7, CARD_WIDTH - 1, CARD_HEIGHT - 1);
- a[1] = QRect(200 + ((CARD_WIDTH + 4) * 1), 7, CARD_WIDTH - 1, CARD_HEIGHT - 1);
- a[2] = QRect(200 + ((CARD_WIDTH + 4) * 2), 7, CARD_WIDTH - 1, CARD_HEIGHT - 1);
- a[3] = QRect(200 + ((CARD_WIDTH + 4) * 3), 7, CARD_WIDTH - 1, CARD_HEIGHT - 1);
-
- bool bHitAce[4];
- bHitAce[0] = c.intersects(a[0]);
- bHitAce[1] = c.intersects(a[1]);
- bHitAce[2] = c.intersects(a[2]);
- bHitAce[3] = c.intersects(a[3]);
-
- // Check to see if hit more than one ace & pick the one that's closer
- for(int i=0; i<3; i++)
- {
- if (bHitAce[i] && bHitAce[i + 1] && (nAce[i] == -1) && (nAce[i + 1] == -1))
- {
- if (c.intersected(a[i]).width() > c.intersected(a[i + 1]).width())
- bHitAce[i + 1] = false;
- else
- bHitAce[i] = false;
-
- break;
- }
- }
-
- bool bMovedToAce = false;
-
- for(int i=0; i<4; i++)
- {
- if (bHitAce[i] && IsValidMoveToAce(nAce[i]))
- {
- m_bCanUndo = true;
-
- if (hitStack)
- nAce[i] = myDeck.GetCardAtPos(solBoard[stackStart.x()][stackStart.y()]),
- solBoard[stackStart.x()][stackStart.y()] = -1;
-
- if (hitDiscard)
- {
- nAce[i] = myDeck.GetCardAtPos(stack2[stack2p--]);
-
- if (m_nNumToSplay != 1)
- m_nNumToSplay--;
- }
-
- if (nHitAce != 0)
- {
- nAce[i] = nAce[nHitAce - 1];
- int nCard = nAce[nHitAce - 1];
- nAce[nHitAce - 1] = ((nCard - 1) % 13 == 0 ? -1 : nCard - 1);
- break;
- }
-
-#if HAVE_SOUND
- if (bSoundOn)
- PlaySound(IDW_CARDPLACE);
-#endif
-
- bMovedToAce = true;
-
- // Scoring...
-#if 0
- if (m_bVegasStyle)
- m_nScore += 5;
- else
- m_nScore += 10;
-#else
- m_nScore += (m_bVegasStyle ? 5 : 10);
-#endif
-
- emit UpdateScore(m_nScore);
- break;
- }
- }
-
- if (!bMovedToAce) // No aces, so check for stacks
- {
- for(int i=0; i<7; i++)
- {
- if (c.intersects(tabl[i]) && IsValidMoveToTableaux(i))
- {
- m_bCanUndo = true;
-
-#if HAVE_SOUND
- if (bSoundOn)
- PlaySound(IDW_CARDPLACE);
-#endif
-
- if (hitStack && (i != stackStart.x()))
- {
- int cnt = stackStart.y();
-
- for(int k=0; k<19; k++)
- {
- if (solBoard[i][k] == -1)
- {
- solBoard[i][k] = solBoard[stackStart.x()][cnt];
- solBoard[stackStart.x()][cnt] = -1;
- cnt++;
- }
-
- if (solBoard[stackStart.x()][cnt] == -1) // Done copying?
- break;
- }
-
- break;
- }
-
- if (hitDiscard)
- {
- for(int k=0; k<19; k++)
- {
- if (solBoard[i][k] == -1)
- {
- solBoard[i][k] = stack2[stack2p--];
- myDeck.SetCardFaceUp(solBoard[i][k]);
-
- // Scoring...
- if (!m_bVegasStyle)
- {
- m_nScore += 5;
- emit UpdateScore(m_nScore);
- }
-
- if (m_nNumToSplay != 1)
- m_nNumToSplay--;
-
- break;
- }
- }
-
- break;
- }
-
- if (nHitAce != 0)
- {
- // handle moving to tableaux here...
- for(int k=0; k<19; k++)
- {
- if (solBoard[i][k] == -1)
- {
- int nCard = nAce[nHitAce - 1];
-
- for(int t=0; t<52; t++) // We have to find da damn thing...
- {
- if (myDeck.GetCardAtPos(t) == nCard)
- {
- solBoard[i][k] = t;
- break;
- }
- }
-
- nAce[nHitAce - 1] = ((nCard - 1) % 13 == 0 ? -1 : nCard - 1);
- myDeck.SetCardFaceUp(solBoard[i][k]);
-
- // Scoring...
-#if 0
- if (!m_bVegasStyle)
- m_nScore -= 15;
- else
- m_nScore -= 5;
-#else
- m_nScore -= (m_bVegasStyle ? 5 : 15);
-#endif
-
- emit UpdateScore(m_nScore);
- break;
- }
- }
-
- break;
- }
- }
- }
- }
-
- update();
- }
-
- mouseDown = hitStack = hitDiscard = false;
- nHitAce = 0;
-
- if (bAutoRemove)
- HandleAutoRemove();
-
- if (PlayerWon())
- {
- emit UpdateScore(m_nScore);
- HandleStatistics();
- m_bWonLastGame = true;
- m_bCanUndo = false;
-
-#if HAVE_SOUND
- if (bSoundOn)
- {
- QString id[] = { IDW_WINNER1, IDW_WINNER2, IDW_WINNER3, IDW_WINNER4, IDW_WINNER5 };
- srand((unsigned)time(NULL));
- int nWaveNum = rand() % 5;
- PlaySound(id[nWaveNum]);
- }
-#endif
-
- QMessageBox::information(this, "MAC Solitaire", "Congratulations!\nYou won!");
- allowUserInput = false;
- }
-}
-
-
-void GameWidget::OnMouseMove(QPoint point)
-{
- if (mouseDown && (hitStack || hitDiscard || (nHitAce != 0)))
- {
- int nHeight = 0;
-
- if (hitStack)
- {
- for(int i=stackStart.y(); i<19; i++)
- if (solBoard[stackStart.x()][i] != -1)
- nHeight += 18;
- }
- else
- nHeight = 18;
-
- nHeight += CARD_HEIGHT - 18;
-
- QRect rcOld(stackPos.x(), stackPos.y(), CARD_WIDTH,
- nHeight); // Find old position for repainting...
-
- stackPos = QPoint(point.x() - mouseOffset.x(), point.y() - mouseOffset.y());
-
- QRect rcNew(stackPos.x(), stackPos.y(), CARD_WIDTH,
- nHeight); // Find new position
- QRect rcUpdate = rcOld.united(rcNew);
- update(rcUpdate); //wil wok? YESH!
- }
-}
-
-
-void GameWidget::OnLButtonDblClk(QPoint point)
-{
- if (dcHitStack || dcHitDiscard)
- {
- hitStack = dcHitStack, hitDiscard = dcHitDiscard;
-
- for(int i=0; i<4; i++)
- {
- if (IsValidMoveToAce(nAce[i]))
- {
- if (hitStack)
- {
- nAce[i] = myDeck.GetCardAtPos(solBoard[stackStart.x()][stackStart.y()]);
- solBoard[stackStart.x()][stackStart.y()] = -1;
- }
- else
- {
- nAce[i] = myDeck.GetCardAtPos(stack2[stack2p--]);
-
- if (m_nNumToSplay != 1)
- m_nNumToSplay--;
- }
-
- update();
-
-#if HAVE_SOUND
- if (bSoundOn)
- PlaySound(IDW_ZIP);
-#endif
-
- // Scoring...
-#if 0
- if (m_bVegasStyle)
- m_nScore += 5;
- else
- m_nScore += 10;
-#else
- m_nScore += (m_bVegasStyle ? 5 : 10);
-#endif
-
- emit UpdateScore(m_nScore);
- break;
- }
- }
-
- dcHitStack = hitStack = dcHitDiscard = hitDiscard = false;
- }
- else
- OnLButtonDown(point); // Either was on draw pile or somewhere else...
-}
-
-
-// It's behaving strangely, especially with kings in the ace piles...
-// It's becuase of the mod 13 function: kings(13) get whacked to 0 this way...
-void GameWidget::HandleAutoRemove(void)
-{
- bool bCheck = true;
-
- while (bCheck)
- {
- bCheck = false;
-
- int nLowestAce = (nAce[0] == -1 ? 0 : ((nAce[0] - 1) % 13) + 1); // Aces are 1-based, cards 1-based
-
- for(int i=1; i<4; i++)
- {
- int nTemp = (nAce[i] == -1 ? 0 : ((nAce[i] - 1) % 13) + 1);
-
- if (nTemp < nLowestAce)
- nLowestAce = nTemp;
- }
-
- for(int i=0; i<7; i++) // Compare cards that *can* go
- {
- for(int j=18; j>=0; j--)
- {
- if (solBoard[i][j] != -1)
- {
- if (myDeck.IsFaceUp(solBoard[i][j]))
- {
- int nCard = myDeck.GetCardAtPos(solBoard[i][j]);
-
- for(int k=0; k<4; k++)
- {
- if (IsValidMoveToAce(nAce[k], nCard))
- {
- // Ranking/suiting doesn't work if nAce == -1... FIX!
- // Should be fixed now...
- // Figure out some way to simplify this tortuous logic, for cryin' out loud!
- int nSuit[4], nRank[4];
-
- for(int t=0; t<4; t++)
- {
- if (nAce[t] != -1)
- nSuit[t] = ((nAce[t] > 13) && (nAce[t] < 40) ? 0 : 1);
- else
- nSuit[t] = -1;
-
- nRank[t] = ((nAce[t] - 1) % 13) + 1;
- }
-
- int nCardSuit = ((nCard > 13) && (nCard < 40) ? 0 : 1),
- nCardRank = ((nCard - 1) % 13) + 1;
- bool bSpecial = false;
- int nCR[2], nCnt = 0;
-
- for(int t=0; t<4; t++)
- if ((nCardSuit != nSuit[t]) && (t != k) && (nSuit[t] != -1))
- nCR[nCnt++] = nRank[t];
-
- if ((nCnt == 2) && (nCR[0] == nCR[1])
- && (nCR[0] - nLowestAce == 2) && (nCardRank - nLowestAce == 3))
- bSpecial = true;
-
- if (((((nCard - 1) % 13) + 1) - nLowestAce) <= 2 || bSpecial)
- // OR difference is 3 and both opposite color are at 2
-// if (((nCard%13) - nLowestAce) <= 2)
- {
- solBoard[i][j] = -1;
-
- if (m_bAnimationsOn)
- AnimateCards(nCard, k, i, j);
-
- nAce[k] = nCard;
- bCheck = true;
-
- // Scoring...
-#if 0
- if (m_bVegasStyle)
- m_nScore += 5;
- else
- m_nScore += 10;
-#else
- m_nScore += (m_bVegasStyle ? 5 : 10);
-#endif
- emit UpdateScore(m_nScore);
- break;
- }
- }
- }
- }
-
- break;
- }
- }
- }
-
- if (stack2p != -1)
- {
- int nCard = myDeck.GetCardAtPos(stack2[stack2p]);
-
- for(int k=0; k<4; k++)
- {
- if (IsValidMoveToAce(nAce[k], nCard))
- {
- // Ranking/suiting doesn't work if nAce == -1... FIX!
- // Should be fixed now...
- // Figure out some way to simplify this tortuous logic, for cryin' out loud!
- int nSuit[4], nRank[4];
-
- for(int t=0; t<4; t++)
- {
- if (nAce[t] != -1)
- nSuit[t] = ((nAce[t] > 13) && (nAce[t] < 40) ? 0 : 1);
- else
- nSuit[t] = -1;
-
- nRank[t] = ((nAce[t] - 1) % 13) + 1;
- }
-
- int nCardSuit = ((nCard > 13) && (nCard < 40) ? 0 : 1),
- nCardRank = ((nCard - 1) % 13) + 1;
- bool bSpecial = false;
- int nCR[2], nCnt = 0;
-
- for(int t=0; t<4; t++)
- {
- if ((nCardSuit != nSuit[t]) && (t != k) && (nSuit[t] != -1))
- nCR[nCnt++] = nRank[t];
- }
-
- if ((nCnt == 2) && (nCR[0] == nCR[1])
- && (nCR[0] - nLowestAce == 2) && (nCardRank - nLowestAce == 3))
- bSpecial = true;
-
- if (((((nCard - 1) % 13) + 1) - nLowestAce) <= 2 || bSpecial)
- // OR difference is 3 and both opposite color are at 2 (tortuously checked above)
- {
- stack2p--;
-
- if (m_nNumToSplay != 1)
- m_nNumToSplay--;
-
- if (m_bAnimationsOn)
- AnimateCards(nCard, k, -1, -1);
-
- nAce[k] = nCard;
- bCheck = true;
-
- // Scoring...
-#if 0
- if (m_bVegasStyle)
- m_nScore += 5;
- else
- m_nScore += 10;
-#else
- m_nScore += (m_bVegasStyle ? 5 : 10);
-#endif
-
- emit UpdateScore(m_nScore);
- break;
- }
- }
- }
- }
- }
-}
-
-
-// Have two routines? One to initiate, the other to handle card movements?
-// Good idea! Implement it, you schmendrick!
-void GameWidget::AnimateCards(int nCard, int nAce, int nTabX, int nTabY)
-{
-//no mas--jeff no likee CWaitCursor wc; // Automagically reverts when it goes out of scope
- int nCX, nCY, nDX, nDY;
-
- // Step 1: figure out where card started from
- if (nTabX == -1)
- {
-// nCX = 5+CARD_WIDTH+6, nCY = 5;
- nCX = 5 + CARD_WIDTH + 6 + ((m_nNumToSplay - 1) * 12);
- nCY = 7 + ((m_nNumToSplay - 1) * 2);
- }
- else
- {
- nCX = 10 + (nTabX * (CARD_WIDTH + 8)), nCY = 130;
-
- for(int j=0; j<nTabY; j++)
- {
- if (solBoard[nTabX][j] != -1)
- {
- if (myDeck.IsFaceUp(solBoard[nTabX][j]))
- nCY += 18;
- else
- nCY += 4;
- }
- }
- }
- // Step 2: figure out where card is going
- nDX = 200 + ((CARD_WIDTH + 4) * nAce), nDY = 7;
- // Step 3: animate card flying from start to destination
- // Use Bresenham's algorithm to figure path...
- // (ideas for movement: increasing acceleration, curved paths, more than one at a time)
- m_bFreeCard = true;
- m_pFirstCard = new SCardInfo(nCard);
- int nDeltaX = nDX - nCX, nDeltaY = nDY - nCY;
- int nError = 0;
- int nUpdate = 0;
- update(); //will do it??? Seems to...
-//Doing this causes an image of the card to be drawn at (0, 0) :-/
-// repaint();
- QRect rcOld(nCX, nCY, CARD_WIDTH, CARD_HEIGHT), rcNew, rcUpdate;
-
- if (abs(nDeltaX) > abs(nDeltaY))
- {
- for(int i=0; i<abs(nDeltaX); i++)
- {
- // Put card draw stuff into OnDraw? (probably best way to do it...)
- nError += abs(nDeltaY);
-
- if (nError > abs(nDeltaX))
- nCY += (nDeltaY < 0 ? -1 : +1), nError -= abs(nDeltaX);
-
- m_pFirstCard->nXPos = nCX + (nDeltaX < 0 ? -i : +i), m_pFirstCard->nYPos = nCY;
- // Draw card
- nUpdate++;
-
- if (nUpdate == 10)
- {
- rcNew = QRect(m_pFirstCard->nXPos, m_pFirstCard->nYPos,
- CARD_WIDTH, CARD_HEIGHT);
- rcUpdate = rcOld.united(rcNew);
- nUpdate = 0;
- repaint(rcUpdate);
- rcOld = rcNew;
- // Pause
- Pause(3);
- }
- // calc new positions
- }
-
- m_pFirstCard->nXPos = nDX, m_pFirstCard->nYPos = nDY;
- rcNew = QRect(nDX, nDY, CARD_WIDTH, CARD_HEIGHT);
- rcUpdate = rcOld.united(rcNew);
- repaint(rcUpdate);
- }
- else
- {
- for(int i=0; i<abs(nDeltaY); i++)
- {
- // Put card draw stuff into OnDraw? (probably best way to do it...)
- nError += abs(nDeltaX);
-
- if (nError > abs(nDeltaY))
- nCX += (nDeltaX < 0 ? -1 : +1), nError -= abs(nDeltaY);
-
- m_pFirstCard->nXPos = nCX, m_pFirstCard->nYPos = nCY + (nDeltaY < 0 ? -i : +i);
- // Draw card
- nUpdate++;
-
- if (nUpdate == 10)
- {
- rcNew = QRect(m_pFirstCard->nXPos, m_pFirstCard->nYPos,
- CARD_WIDTH, CARD_HEIGHT);
- rcUpdate = rcOld.united(rcNew);
- nUpdate = 0;
- repaint(rcUpdate);//this is crappy. should only update what's needed!
- rcOld = rcNew;
- // Pause
- Pause(3);
- }
- // calc new positions
- }
-
- m_pFirstCard->nXPos = nDX, m_pFirstCard->nYPos = nDY;
- rcNew = QRect(nDX, nDY, CARD_WIDTH, CARD_HEIGHT);
- rcUpdate = rcOld.united(rcNew);
- repaint(rcUpdate);
- }
-
- m_bFreeCard = false;
- delete m_pFirstCard;
-}
-
-
-bool GameWidget::IsValidMoveToAce(int nAceM)
-{
- int nCards = 0;
-
- for(int k=stackStart.y(); k<19; k++)
- {
- if (solBoard[stackStart.x()][k] != -1)
- nCards++;
- }
-
- if ((hitStack && (nCards == 1)) || hitDiscard)
- {
- int nCardHit = (hitStack ? myDeck.GetCardAtPos(solBoard[stackStart.x()][stackStart.y()])
- : myDeck.GetCardAtPos(stack2[stack2p]));
- return IsValidMoveToAce(nAceM, nCardHit);
- }
- else if (nHitAce != 0)
- {
- return IsValidMoveToAce(nAceM, nAce[nHitAce - 1]);
- }
-
- return false;
-}
-
-
-bool GameWidget::IsValidMoveToAce(int nAce, int nCard)
-{
- if (((nAce == -1) && ((nCard % 13) == 1))
- || ((nAce == (nCard - 1)) && ((nAce % 13) != 0)))
- return true;
-
- return false;
-}
-
-
-bool GameWidget::IsValidMoveToTableaux(int nStack)
-{
- int nBottomCard = -1, nTopCard;
-
- for(int i=0; i<19; i++)
- {
- if ((solBoard[nStack][i] != -1) && (myDeck.IsFaceUp(solBoard[nStack][i])))
- nBottomCard = myDeck.GetCardAtPos(solBoard[nStack][i]);
- }
-
- if (hitStack)
- nTopCard = myDeck.GetCardAtPos(solBoard[stackStart.x()][stackStart.y()]);
- else if (hitDiscard)
- nTopCard = myDeck.GetCardAtPos(stack2[stack2p]);
- else if (nHitAce != 0)
- nTopCard = nAce[nHitAce - 1];
-
- int colorBC = ((nBottomCard > 13) && (nBottomCard < 40) ? 0 : 1);
- int colorTC = ((nTopCard > 13) && (nTopCard < 40) ? 0 : 1);
- int rankBC = (nBottomCard - 1) % 13;
- int rankTC = (nTopCard - 1) % 13;
-
- if (((rankBC == (rankTC + 1)) && (colorBC != colorTC))
- || ((nBottomCard == -1) && (rankTC == 12)))
- return true;
-
- return false;
-}
-
-
-bool GameWidget::PlayerWon(void)
-{
- for(int i=0; i<7; i++)
- if (solBoard[i][0] != -1)
- return false;
-
- if ((stack1p != -1) || (stack2p != -1))
- return false;
-
- return true;
-}
-
-
-void GameWidget::HandleStatistics(void)
-{
- if (PlayerWon())
- {
- m_nWins++;
-
- if (m_bWonLastGame)
- m_nStreakC++;
- else
- m_nStreakC = 1;
- }
- else
- {
- m_nLosses++;
-
- if (!m_bWonLastGame)
- m_nStreakC--;
- else
- m_nStreakC = -1;
- }
-
- if (m_nStreakC < 0) // Beat largest losing streak?
- {
- if (abs(m_nStreakC) > m_nStreakL)
- m_nStreakL = abs(m_nStreakC);
- }
- else // Check for longest winning streak
- {
- if (m_nStreakC > m_nStreakW)
- m_nStreakW = m_nStreakC;
- }
-
- if (m_bVegasStyle) // Check for high score
- {
- if (m_nScore > m_nVHiScore)
- m_nVHiScore = m_nScore;
- }
- else
- {
- if (m_nScore > m_nHiScore)
- m_nHiScore = m_nScore;
- }
-}
-#endif
-
-