From 2dc3ab0ac6dcf833826ddc000a73488a2c316752 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Thu, 5 Jun 2014 19:58:41 -0500 Subject: [PATCH] Added board titles. --- src/boards.cpp | 138 +++--- src/boards.h | 2 - src/gameboard.cpp | 5 +- src/gameboard.h | 3 +- src/gamewidget.cpp | 1111 +------------------------------------------- src/gamewidget.h | 1 + 6 files changed, 98 insertions(+), 1162 deletions(-) diff --git a/src/boards.cpp b/src/boards.cpp index d8c2a42..7ade832 100644 --- a/src/boards.cpp +++ b/src/boards.cpp @@ -21,22 +21,25 @@ // . = Spot to move box to // + = Spot to move box to, that already has a box on it // o = Player initial position +// - = Do not draw anything here // static const struct { unsigned int width, height; - unsigned char state[5 * 5 + 1]; } board001 = { 5, 5, + unsigned char state[5 * 5 + 40 + 1]; } board001 = { 5, 5, +// const char * state; } board001 = { 5, 5, "@@@@@" "@o @" "@ X @" "@ . @" "@@@@@" + "Neophyte" }; static const struct { unsigned int width, height; - unsigned char state[7 * 7 + 1]; } board002 = { 7, 7, + unsigned char state[7 * 7 + 40 + 1]; } board002 = { 7, 7, "@@@@@@@" "@ @" "@ X.X @" @@ -44,210 +47,227 @@ static const struct { "@ X.X @" "@o @" "@@@@@@@" + "A Little Bit Harder..." }; static const struct { unsigned int width, height; - unsigned char state[7 * 5 + 1]; } board003 = { 7, 5, + unsigned char state[7 * 5 + 40 + 1]; } board003 = { 7, 5, "@@@@@@@" "@. X .@" "@ XoX @" "@. X .@" "@@@@@@@" + "Boxed In" }; static const struct { unsigned int width, height; - unsigned char state[8 * 5 + 1]; } board004 = { 8, 5, + unsigned char state[8 * 5 + 40 + 1]; } board004 = { 8, 5, "@@@@@@@@" "@ ..X @" "@ Xo X @" "@ X.. @" "@@@@@@@@" + "Edging Out" }; static const struct { unsigned int width, height; - unsigned char state[8 * 7 + 1]; } board005 = { 8, 7, - " @@@@@@@" - " @ @" + unsigned char state[8 * 7 + 40 + 1]; } board005 = { 8, 7, + "-@@@@@@@" + "-@ @" "@@ .X. @" "@o X X @" "@ .X. @" "@@ @" - " @@@@@@@" + "-@@@@@@@" + "Rotation" }; static const struct { unsigned int width, height; - unsigned char state[8 * 8 + 1]; } board006 = { 8, 8, - " @@@@@ " + unsigned char state[8 * 8 + 40 + 1]; } board006 = { 8, 8, + "-@@@@@--" "@@ @@@" "@ @ @" "@ @ @ @" "@ X X@ @" "@.@ @" "@. o@@@@" - "@@@@@ " + "@@@@@---" + "Headless Chicken" }; static const struct { unsigned int width, height; - unsigned char state[8 * 6 + 1]; } board007 = { 8, 6, + unsigned char state[8 * 6 + 40 + 1]; } board007 = { 8, 6, "@@@@@@@@" "@ X. X.@" "@o.X X.@" "@ X. X.@" "@ .X X.@" "@@@@@@@@" + "Two Lines" }; static const struct { unsigned int width, height; - unsigned char state[10 * 8 + 1]; } board008 = { 10, 8, - " @@@@@@@" - " @@ @ o@" - " @ @ @" - " @X X X @" - " @ X@@ @" + unsigned char state[10 * 8 + 40 + 1]; } board008 = { 10, 8, + "---@@@@@@@" + "--@@ @ o@" + "--@ @ @" + "--@X X X @" + "--@ X@@ @" "@@@ X @ @@" - "@..... @ " - "@@@@@@@@@ " + "@..... @-" + "@@@@@@@@@-" + "Easy Does It" }; static const struct { unsigned int width, height; - unsigned char state[9 * 7 + 1]; } board009 = { 9, 7, + unsigned char state[9 * 7 + 40 + 1]; } board009 = { 9, 7, "@@@@@@@@@" "@ + @" "@ X.@.X @" "@ X.X @" "@@@.X.@@@" - " @@o@@ " - " @@@ " + "--@@o@@--" + "---@@@---" + "Claustrophobia" }; static const struct { unsigned int width, height; - unsigned char state[7 * 7 + 1]; } board010 = { 7, 7, - " @@@@@" + unsigned char state[7 * 7 + 40 + 1]; } board010 = { 7, 7, + "--@@@@@" "@@@ @" "@o .X.@" "@ X X@" "@@@.X.@" - " @ @" - " @@@@@" + "--@ @" + "--@@@@@" + "Tight Squeeze" }; static const struct { unsigned int width, height; - unsigned char state[10 * 8 + 1]; } board011 = { 10, 8, - " @@@@ " - " @ @ " + unsigned char state[10 * 8 + 40 + 1]; } board011 = { 10, 8, + "--@@@@----" + "--@ @----" "@@@ @@@@@" "@ ..X @" "@oX.. X @" "@@@ X@@@@@" - " @ @ " - " @@@@ " + "--@ @----" + "--@@@@----" + "Crossroads" }; static const struct { unsigned int width, height; - unsigned char state[10 * 6 + 1]; } board012 = { 10, 6, - " @@@@@@@@@" + unsigned char state[10 * 6 + 40 + 1]; } board012 = { 10, 6, + "-@@@@@@@@@" "@@ @" "@ @X@X @" "@ XX .X.@" "@ o@@@...@" - "@@@@ @@@@@" + "@@@@-@@@@@" + "In The Corner" }; static const struct { unsigned int width, height; - unsigned char state[9 * 7 + 1]; } board013 = { 9, 7, - " @@@@@ " + unsigned char state[9 * 7 + 40 + 1]; } board013 = { 9, 7, + "---@@@@@-" "@@@@ @@" "@ X X X @" "@o......@" "@ X X X @" "@@@@ @@" - " @@@@@ " + "---@@@@@-" + "Get In Line" }; static const struct { unsigned int width, height; - unsigned char state[8 * 7 + 1]; } board014 = { 8, 7, - " @@@@@ " - "@@@ o@ " + unsigned char state[8 * 7 + 40 + 1]; } board014 = { 8, 7, + "--@@@@@-" + "@@@ o@-" "@ X. @@" "@ .X. @" "@@@ +X @" - " @ @@" - " @@@@@ " + "--@ @@" + "--@@@@@-" + "Tighter Squeeze" }; static const struct { unsigned int width, height; - unsigned char state[8 * 7 + 1]; } board015 = { 8, 7, - "@@@@@@@ " + unsigned char state[8 * 7 + 40 + 1]; } board015 = { 8, 7, + "@@@@@@@-" "@ .X. @@" "@ X X @" "@ .X. @" "@ @@@ @@" - "@ o @ " - "@@@@@@@ " + "@ o @-" + "@@@@@@@-" + "Rotation #2" }; static const struct { unsigned int width, height; - unsigned char state[10 * 7 + 1]; } board016 = { 10, 7, - " @@@@@@ " - " @@@ @ " + unsigned char state[10 * 7 + 40 + 1]; } board016 = { 10, 7, + "---@@@@@@-" + "-@@@ @-" "@@. X@@ @@" "@..X X o@" "@.. X X @@" - "@@@@@@ @ " - " @@@@ " + "@@@@@@ @-" + "-----@@@@-" + "Up Against A Wall" }; static const struct { unsigned int width, height; - unsigned char state[7 * 7 + 1]; } board017 = { 7, 7, - " @@@@@ " + unsigned char state[7 * 7 + 40 + 1]; } board017 = { 7, 7, + "-@@@@@-" "@@ . @@" "@ X.X @" "@ .Xo@" "@ X.X @" "@@ . @@" - " @@@@@ " + "-@@@@@-" + "Lizard Eye" }; static const struct { unsigned int width, height; - unsigned char state[12 * 6 + 1]; } board018 = { 12, 6, - " @@@@@@@@@@ " + unsigned char state[12 * 6 + 40 + 1]; } board018 = { 12, 6, + "-@@@@@@@@@@-" "@@ @o @@" "@ X ....X @" "@ X@@@@ X @" - "@ @ @ @@" - "@@@@@ @@@@ " + "@ @--@ @@" + "@@@@@--@@@@-" + "Two Rooms" }; diff --git a/src/boards.h b/src/boards.h index fde5fcc..f2a8a2f 100644 --- a/src/boards.h +++ b/src/boards.h @@ -9,8 +9,6 @@ struct Board { unsigned int width; // Width of the board unsigned int height; // Height of the board -// unsigned int x; // Initial X position of player -// unsigned int y; // Initial Y position of player unsigned char state[]; // Board data }; diff --git a/src/gameboard.cpp b/src/gameboard.cpp index 0656e74..92a0bab 100644 --- a/src/gameboard.cpp +++ b/src/gameboard.cpp @@ -31,8 +31,7 @@ GameBoard::GameBoard(int boardNumber) boardLength = width * height; board = new char[boardLength]; initialBoard = new char[boardLength]; -// initialX = boardToUse->x; -// initialY = boardToUse->y; + name = (const char *)&(boardToUse->state[boardLength]); for(int i=0; isetTextFormat(Qt::PlainText); -// setFixedSize(580, 520); -// gameBoard = new GameBoard(1); } @@ -35,18 +33,15 @@ GameWidget::~GameWidget(void) void GameWidget::paintEvent(QPaintEvent * /*event*/) { - // TO DO: - // Optimizations: Create a member variable that has a bitmap in it, - // tile it with the felt in OnCreate(), blit as background instead of - // FillRect(r, brWhite). Also need to keep track of client rect. - // Possibly have 2 bitmaps as member vars, so keep bm construction to a minimum... - QPainter painter(this); -// QRect rcUpdate = dc.m_ps.rcPaint; // Update rect... -// QRect rcUpdate = QRect(0, 0, 580, 520); // Update rect? + QFont font; + + font.setPixelSize(titleBox.height() - 8); + painter.setFont(font); + painter.setPen(QPen(Qt::black, 1.0, Qt::SolidLine)); + painter.drawText(titleBox, Qt::AlignCenter, gameBoard->name); painter.translate(QPoint(offsetX, offsetY)); -// maxLength = 60; int ptr = 0; for(int y=0; yheight; y++) @@ -69,28 +64,6 @@ void GameWidget::paintEvent(QPaintEvent * /*event*/) painter.setBrush(QBrush(tile & GTBoxSpot ? Qt::green : Qt::red)); painter.drawRect(x * maxLength, y * maxLength, maxLength, maxLength); } -#if 0 - else if (tile == GTBoxSpot) - { - painter.setBrush(QBrush(Qt::magenta)); -// painter.drawRect((x * maxLength) + 20, (y * maxLength) + 20, maxLength - 40, maxLength - 40); - painter.drawRect((x * maxLength) + (int)(20.0/60.0*(float)maxLength), (y * maxLength) + (int)(20.0/60.0*(float)maxLength), maxLength - (int)(40.0/60.0*(float)maxLength), maxLength - (int)(40.0/60.0*(float)maxLength)); - } - else if (tile == (GTBox | GTBoxSpot)) - { - if (!(boxMoving && (movingBoxPositionX == x) && (movingBoxPositionY == y))) - { - painter.setBrush(QBrush(Qt::green)); - painter.drawRect(x * maxLength, y * maxLength, maxLength, maxLength); - } - else - { - painter.setBrush(QBrush(Qt::magenta)); -// painter.drawRect((x * maxLength) + 20, (y * maxLength) + 20, maxLength - 40, maxLength - 40); - painter.drawRect((x * maxLength) + (int)(20.0/60.0*(float)maxLength), (y * maxLength) + (int)(20.0/60.0*(float)maxLength), maxLength - (int)(40.0/60.0*(float)maxLength), maxLength - (int)(40.0/60.0*(float)maxLength)); - } - } -#endif else if ((tileType == GTSpace) || ((tileType == GTBox) && (boxMoving && (movingBoxPositionX == x) && (movingBoxPositionY == y)))) { @@ -364,12 +337,8 @@ void GameWidget::UndoLastMove(void) if (boxMoving) { -// movingBoxPositionX = gameBoard->playerX + (int)deltaX; -// movingBoxPositionY = gameBoard->playerY + (int)deltaY; movingBoxPositionX = gameBoard->playerX + dx; movingBoxPositionY = gameBoard->playerY + dy; -// bx += deltaX * (float)maxLength; -// by += deltaY * (float)maxLength; bx += (float)(dx * maxLength); by += (float)(dy * maxLength); } @@ -397,1077 +366,23 @@ void GameWidget::UndoLastMove(void) } -#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 -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 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 abs(nDeltaY)) - { - for(int i=0; i 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)) - 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 - - void GameWidget::ResizeGrid(void) { QSize s = size(); + // Set some room for the board title (7.5%) + float titleHeight = s.height() * 0.075; + // Find the constraints float boxSizeX = s.width() / gameBoard->width; - float boxSizeY = s.height() / gameBoard->height; + float boxSizeY = (s.height() - titleHeight) / gameBoard->height; maxLength = (int)(boxSizeX > boxSizeY ? boxSizeY : boxSizeX); offsetX = (s.width() - (maxLength * gameBoard->width)) / 2; - offsetY = (s.height() - (maxLength * gameBoard->height)) / 2; + offsetY = ((s.height() - titleHeight) - (maxLength * gameBoard->height)) / 2; + titleBox.setRect(0, offsetY, s.width(), titleHeight); + offsetY += titleHeight; // Add in the title's height } diff --git a/src/gamewidget.h b/src/gamewidget.h index 28ff3b4..f6ba76b 100644 --- a/src/gamewidget.h +++ b/src/gamewidget.h @@ -58,6 +58,7 @@ class GameWidget: public QWidget int movingBoxPositionX; int movingBoxPositionY; int offsetX, offsetY; + QRect titleBox; }; #endif // __GAMEWIDGET_H__ -- 2.37.2