1998-07-24 15:43:32 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: game.cpp
|
|
|
|
// Purpose: Forty Thieves patience game
|
|
|
|
// Author: Chris Breeze
|
|
|
|
// Modified by:
|
|
|
|
// Created: 21/07/97
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1993-1998 Chris Breeze
|
2004-06-02 05:14:59 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-07-24 15:43:32 -04:00
|
|
|
//---------------------------------------------------------------------------
|
2004-05-25 07:20:37 -04:00
|
|
|
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0
|
1998-07-24 15:43:32 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "forty.h"
|
|
|
|
#include "game.h"
|
|
|
|
|
|
|
|
Game::Game(int wins, int games, int score) :
|
2004-06-02 05:14:59 -04:00
|
|
|
m_inPlay(false),
|
|
|
|
m_moveIndex(0),
|
|
|
|
m_redoIndex(0),
|
|
|
|
m_bmap(0),
|
|
|
|
m_bmapCard(0)
|
1998-07-24 15:43:32 -04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
m_pack = new Pack(2, 2 + 4 * (CardHeight + 2));
|
|
|
|
srand(time(0));
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++) m_pack->Shuffle();
|
|
|
|
|
|
|
|
m_discard = new Discard(2, 2 + 5 * (CardHeight + 2));
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
m_foundations[i] = new Foundation(2 + (i / 4) * (CardWidth + 2),
|
|
|
|
2 + (i % 4) * (CardHeight + 2));
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
m_bases[i] = new Base(8 + (i + 2) * (CardWidth + 2), 2);
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
Deal();
|
|
|
|
m_srcPile = 0;
|
|
|
|
m_liftedCard = 0;
|
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
// copy the input parameters for future reference
|
1998-07-24 15:43:32 -04:00
|
|
|
m_numWins = wins;
|
|
|
|
m_numGames = games;
|
|
|
|
m_totalScore = score;
|
|
|
|
m_currentScore = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-06 12:50:52 -05:00
|
|
|
void Game::Layout()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
m_pack->SetPos(2, 2 + 4 * (CardHeight + 2));
|
|
|
|
|
|
|
|
m_discard->SetPos(2, 2 + 5 * (CardHeight + 2));
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
m_foundations[i]->SetPos(2 + (i / 4) * (CardWidth + 2),
|
|
|
|
2 + (i % 4) * (CardHeight + 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
m_bases[i]->SetPos(8 + (i + 2) * (CardWidth + 2), 2);
|
|
|
|
}
|
|
|
|
delete m_bmap;
|
|
|
|
delete m_bmapCard;
|
|
|
|
m_bmap = 0;
|
|
|
|
m_bmapCard = 0;
|
|
|
|
}
|
|
|
|
|
1998-07-24 15:43:32 -04:00
|
|
|
// Make sure we delete all objects created by the game object
|
|
|
|
Game::~Game()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
delete m_pack;
|
|
|
|
delete m_discard;
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
delete m_foundations[i];
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
delete m_bases[i];
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
2004-06-02 05:14:59 -04:00
|
|
|
delete m_bmap;
|
|
|
|
delete m_bmapCard;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Set the score for a new player.
|
|
|
|
NB: call Deal() first if the new player is to start
|
|
|
|
a new game
|
|
|
|
*/
|
|
|
|
void Game::NewPlayer(int wins, int games, int score)
|
|
|
|
{
|
|
|
|
m_numWins = wins;
|
|
|
|
m_numGames = games;
|
|
|
|
m_totalScore = score;
|
|
|
|
m_currentScore = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Undo the last move
|
|
|
|
void Game::Undo(wxDC& dc)
|
|
|
|
{
|
|
|
|
if (m_moveIndex > 0)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
m_moveIndex--;
|
|
|
|
Card* card = m_moves[m_moveIndex].dest->RemoveTopCard(dc);
|
|
|
|
m_moves[m_moveIndex].src->AddCard(dc, card);
|
|
|
|
DisplayScore(dc);
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redo the last move
|
|
|
|
void Game::Redo(wxDC& dc)
|
|
|
|
{
|
|
|
|
if (m_moveIndex < m_redoIndex)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
Card* card = m_moves[m_moveIndex].src->RemoveTopCard(dc);
|
|
|
|
if (m_moves[m_moveIndex].src == m_pack)
|
|
|
|
{
|
|
|
|
m_pack->Redraw(dc);
|
|
|
|
card->TurnCard(faceup);
|
|
|
|
}
|
|
|
|
m_moves[m_moveIndex].dest->AddCard(dc, card);
|
|
|
|
DisplayScore(dc);
|
|
|
|
m_moveIndex++;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::DoMove(wxDC& dc, Pile* src, Pile* dest)
|
|
|
|
{
|
|
|
|
if (m_moveIndex < MaxMoves)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
if (src == dest)
|
|
|
|
{
|
|
|
|
wxMessageBox(_T("Game::DoMove() src == dest"), _T("Debug message"),
|
|
|
|
wxOK | wxICON_EXCLAMATION);
|
|
|
|
}
|
|
|
|
m_moves[m_moveIndex].src = src;
|
|
|
|
m_moves[m_moveIndex].dest = dest;
|
|
|
|
m_moveIndex++;
|
1998-07-24 15:43:32 -04:00
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
// when we do a move any moves in redo buffer are discarded
|
|
|
|
m_redoIndex = m_moveIndex;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
wxMessageBox(_T("Game::DoMove() Undo buffer full"), _T("Debug message"),
|
|
|
|
wxOK | wxICON_EXCLAMATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_inPlay)
|
|
|
|
{
|
|
|
|
m_inPlay = true;
|
|
|
|
m_numGames++;
|
|
|
|
}
|
|
|
|
DisplayScore(dc);
|
|
|
|
|
|
|
|
if (HaveYouWon())
|
|
|
|
{
|
|
|
|
wxWindow *frame = wxTheApp->GetTopWindow();
|
|
|
|
wxWindow *canvas = (wxWindow *) NULL;
|
|
|
|
|
|
|
|
if (frame)
|
|
|
|
{
|
2004-07-23 04:58:29 -04:00
|
|
|
wxWindowList::compatibility_iterator node = frame->GetChildren().GetFirst();
|
2004-06-02 05:14:59 -04:00
|
|
|
if (node) canvas = (wxWindow*)node->GetData();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This game is over
|
|
|
|
m_inPlay = false;
|
|
|
|
|
|
|
|
// Redraw the score box to update games won
|
|
|
|
DisplayScore(dc);
|
|
|
|
|
|
|
|
if (wxMessageBox(_T("Do you wish to play again?"),
|
|
|
|
_T("Well Done, You have won!"), wxYES_NO | wxICON_QUESTION) == wxYES)
|
|
|
|
{
|
|
|
|
Deal();
|
|
|
|
canvas->Refresh();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// user cancelled the dialog - exit the app
|
|
|
|
((wxFrame*)canvas->GetParent())->Close(true);
|
|
|
|
}
|
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Game::DisplayScore(wxDC& dc)
|
|
|
|
{
|
1998-12-11 04:59:20 -05:00
|
|
|
wxColour bgColour = FortyApp::BackgroundColour();
|
2004-06-02 05:14:59 -04:00
|
|
|
wxPen* pen = wxThePenList->FindOrCreatePen(bgColour, 1, wxSOLID);
|
1998-12-11 04:59:20 -05:00
|
|
|
dc.SetTextBackground(bgColour);
|
|
|
|
dc.SetTextForeground(FortyApp::TextColour());
|
2004-06-02 05:14:59 -04:00
|
|
|
dc.SetBrush(FortyApp::BackgroundBrush());
|
|
|
|
dc.SetPen(* pen);
|
1998-07-24 15:43:32 -04:00
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
// count the number of cards in foundations
|
1998-07-24 15:43:32 -04:00
|
|
|
m_currentScore = 0;
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
m_currentScore += m_foundations[i]->GetNumCards();
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int x, y;
|
|
|
|
m_pack->GetTopCardPos(x, y);
|
|
|
|
x += 12 * CardWidth - 105;
|
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
int w, h;
|
|
|
|
{
|
|
|
|
long width, height;
|
|
|
|
dc.GetTextExtent(_T("Average score:m_x"), &width, &height);
|
|
|
|
w = width;
|
|
|
|
h = height;
|
|
|
|
}
|
|
|
|
dc.DrawRectangle(x + w, y, 20, 4 * h);
|
1998-07-24 15:43:32 -04:00
|
|
|
|
2002-12-22 14:57:17 -05:00
|
|
|
wxString str;
|
|
|
|
str.Printf(_T("%d"), m_currentScore);
|
|
|
|
dc.DrawText(_T("Score:"), x, y);
|
1998-07-24 15:43:32 -04:00
|
|
|
dc.DrawText(str, x + w, y);
|
|
|
|
y += h;
|
|
|
|
|
2002-12-22 14:57:17 -05:00
|
|
|
str.Printf(_T("%d"), m_numGames);
|
|
|
|
dc.DrawText(_T("Games played:"), x, y);
|
1998-07-24 15:43:32 -04:00
|
|
|
dc.DrawText(str, x + w, y);
|
|
|
|
y += h;
|
|
|
|
|
2002-12-22 14:57:17 -05:00
|
|
|
str.Printf(_T("%d"), m_numWins);
|
|
|
|
dc.DrawText(_T("Games won:"), x, y);
|
1998-07-24 15:43:32 -04:00
|
|
|
dc.DrawText(str, x + w, y);
|
|
|
|
y += h;
|
|
|
|
|
|
|
|
int average = 0;
|
2004-06-02 05:14:59 -04:00
|
|
|
if (m_numGames > 0)
|
|
|
|
{
|
|
|
|
average = (2 * (m_currentScore + m_totalScore) + m_numGames ) / (2 * m_numGames);
|
|
|
|
}
|
2002-12-22 14:57:17 -05:00
|
|
|
str.Printf(_T("%d"), average);
|
|
|
|
dc.DrawText(_T("Average score:"), x, y);
|
1998-07-24 15:43:32 -04:00
|
|
|
dc.DrawText(str, x + w, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Shuffle the m_pack and deal the cards
|
|
|
|
void Game::Deal()
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
Card* card;
|
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
// Reset all the piles, the undo buffer and shuffle the m_pack
|
1998-07-24 15:43:32 -04:00
|
|
|
m_moveIndex = 0;
|
|
|
|
m_pack->ResetPile();
|
|
|
|
for (i = 0; i < 5; i++)
|
2004-06-02 05:14:59 -04:00
|
|
|
{
|
|
|
|
m_pack->Shuffle();
|
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
m_discard->ResetPile();
|
|
|
|
for (i = 0; i < 10; i++)
|
2004-06-02 05:14:59 -04:00
|
|
|
{
|
|
|
|
m_bases[i]->ResetPile();
|
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
for (i = 0; i < 8; i++)
|
2004-06-02 05:14:59 -04:00
|
|
|
{
|
|
|
|
m_foundations[i]->ResetPile();
|
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
// Deal the initial 40 cards onto the bases
|
1998-07-24 15:43:32 -04:00
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
for (j = 1; j <= 4; j++)
|
|
|
|
{
|
|
|
|
card = m_pack->RemoveTopCard();
|
|
|
|
card->TurnCard(faceup);
|
|
|
|
m_bases[i]->AddCard(card);
|
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_inPlay)
|
2004-06-02 05:14:59 -04:00
|
|
|
{
|
|
|
|
// player has started the game and then redealt
|
|
|
|
// and so we must add the score for this game to the total score
|
|
|
|
m_totalScore += m_currentScore;
|
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
m_currentScore = 0;
|
2004-03-23 16:23:17 -05:00
|
|
|
m_inPlay = false;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Redraw the m_pack, discard pile, the bases and the foundations
|
|
|
|
void Game::Redraw(wxDC& dc)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
int i;
|
|
|
|
m_pack->Redraw(dc);
|
|
|
|
m_discard->Redraw(dc);
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
m_foundations[i]->Redraw(dc);
|
|
|
|
}
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
m_bases[i]->Redraw(dc);
|
|
|
|
}
|
|
|
|
DisplayScore(dc);
|
|
|
|
|
|
|
|
if (m_bmap == 0)
|
|
|
|
{
|
|
|
|
m_bmap = new wxBitmap(CardWidth, CardHeight);
|
|
|
|
m_bmapCard = new wxBitmap(CardWidth, CardHeight);
|
|
|
|
|
|
|
|
// Initialise the card bitmap to the background colour
|
|
|
|
wxMemoryDC memoryDC;
|
|
|
|
memoryDC.SelectObject(*m_bmapCard);
|
2000-01-12 12:57:18 -05:00
|
|
|
memoryDC.SetPen( *wxTRANSPARENT_PEN );
|
2004-06-02 05:14:59 -04:00
|
|
|
memoryDC.SetBrush(FortyApp::BackgroundBrush());
|
|
|
|
memoryDC.DrawRectangle(0, 0, CardWidth, CardHeight);
|
|
|
|
memoryDC.SelectObject(*m_bmap);
|
|
|
|
memoryDC.DrawRectangle(0, 0, CardWidth, CardHeight);
|
|
|
|
memoryDC.SelectObject(wxNullBitmap);
|
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test to see if the point (x, y) is over the top card of one of the piles
|
|
|
|
// Returns pointer to the pile, or 0 if (x, y) is not over a pile
|
|
|
|
// or the pile is empty
|
|
|
|
Pile* Game::WhichPile(int x, int y)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
if (m_pack->GetCard(x, y) &&
|
|
|
|
m_pack->GetCard(x, y) == m_pack->GetTopCard())
|
|
|
|
{
|
|
|
|
return m_pack;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_discard->GetCard(x, y) &&
|
|
|
|
m_discard->GetCard(x, y) == m_discard->GetTopCard())
|
|
|
|
{
|
|
|
|
return m_discard;
|
|
|
|
}
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
if (m_foundations[i]->GetCard(x, y) &&
|
|
|
|
m_foundations[i]->GetCard(x, y) == m_foundations[i]->GetTopCard())
|
|
|
|
{
|
|
|
|
return m_foundations[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
if (m_bases[i]->GetCard(x, y) &&
|
|
|
|
m_bases[i]->GetCard(x, y) == m_bases[i]->GetTopCard())
|
|
|
|
{
|
|
|
|
return m_bases[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Left button is pressed - if cursor is over the m_pack then deal a card
|
|
|
|
// otherwise if it is over a card pick it up ready to be dragged - see MouseMove()
|
|
|
|
bool Game::LButtonDown(wxDC& dc, int x, int y)
|
|
|
|
{
|
|
|
|
m_srcPile = WhichPile(x, y);
|
|
|
|
if (m_srcPile == m_pack)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
Card* card = m_pack->RemoveTopCard();
|
|
|
|
if (card)
|
|
|
|
{
|
|
|
|
m_pack->Redraw(dc);
|
|
|
|
card->TurnCard(faceup);
|
|
|
|
m_discard->AddCard(dc, card);
|
|
|
|
DoMove(dc, m_pack, m_discard);
|
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
m_srcPile = 0;
|
|
|
|
}
|
|
|
|
else if (m_srcPile)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
m_srcPile->GetTopCardPos(m_xPos, m_yPos);
|
|
|
|
m_xOffset = m_xPos - x;
|
|
|
|
m_yOffset = m_yPos - y;
|
|
|
|
|
|
|
|
// Copy the area under the card
|
|
|
|
// Initialise the card bitmap to the background colour
|
|
|
|
{
|
|
|
|
wxMemoryDC memoryDC;
|
|
|
|
memoryDC.SelectObject(*m_bmap);
|
|
|
|
m_liftedCard = m_srcPile->RemoveTopCard(memoryDC, m_xPos, m_yPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the card in card bitmap ready for blitting onto
|
|
|
|
// the screen
|
|
|
|
{
|
|
|
|
wxMemoryDC memoryDC;
|
|
|
|
memoryDC.SelectObject(*m_bmapCard);
|
|
|
|
m_liftedCard->Draw(memoryDC, 0, 0);
|
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
return m_srcPile != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called when the left button is double clicked
|
|
|
|
// If a card is under the pointer and it can move elsewhere then move it.
|
|
|
|
// Move onto a foundation as first choice, a populated base as second and
|
|
|
|
// an empty base as third choice.
|
|
|
|
// NB Cards in the m_pack cannot be moved in this way - they aren't in play
|
|
|
|
// yet
|
|
|
|
void Game::LButtonDblClk(wxDC& dc, int x, int y)
|
|
|
|
{
|
|
|
|
Pile* pile = WhichPile(x, y);
|
|
|
|
if (!pile) return;
|
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
// Double click on m_pack is the same as left button down
|
1998-07-24 15:43:32 -04:00
|
|
|
if (pile == m_pack)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
LButtonDown(dc, x, y);
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
Card* card = pile->GetTopCard();
|
1998-07-24 15:43:32 -04:00
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
if (card)
|
|
|
|
{
|
|
|
|
int i;
|
1998-07-24 15:43:32 -04:00
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
// if the card is an ace then try to place it next
|
|
|
|
// to an ace of the same suit
|
|
|
|
if (card->GetPipValue() == 1)
|
|
|
|
{
|
|
|
|
for(i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
Card* m_topCard = m_foundations[i]->GetTopCard();
|
|
|
|
if ( m_topCard )
|
1998-07-24 15:43:32 -04:00
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
if (m_topCard->GetSuit() == card->GetSuit() &&
|
1998-07-24 15:43:32 -04:00
|
|
|
m_foundations[i + 4] != pile &&
|
2004-06-02 05:14:59 -04:00
|
|
|
m_foundations[i + 4]->GetTopCard() == 0)
|
|
|
|
{
|
|
|
|
pile->RemoveTopCard(dc);
|
|
|
|
m_foundations[i + 4]->AddCard(dc, card);
|
|
|
|
DoMove(dc, pile, m_foundations[i + 4]);
|
|
|
|
return;
|
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
2004-06-02 05:14:59 -04:00
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
2004-06-02 05:14:59 -04:00
|
|
|
|
|
|
|
// try to place the card on a foundation
|
|
|
|
for(i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile)
|
|
|
|
{
|
|
|
|
pile->RemoveTopCard(dc);
|
|
|
|
m_foundations[i]->AddCard(dc, card);
|
|
|
|
DoMove(dc, pile, m_foundations[i]);
|
|
|
|
return;
|
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
2004-06-02 05:14:59 -04:00
|
|
|
// try to place the card on a populated base
|
|
|
|
for(i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
if (m_bases[i]->AcceptCard(card) &&
|
|
|
|
m_bases[i] != pile &&
|
|
|
|
m_bases[i]->GetTopCard())
|
|
|
|
{
|
|
|
|
pile->RemoveTopCard(dc);
|
|
|
|
m_bases[i]->AddCard(dc, card);
|
|
|
|
DoMove(dc, pile, m_bases[i]);
|
|
|
|
return;
|
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
2004-06-02 05:14:59 -04:00
|
|
|
// try to place the card on any base
|
|
|
|
for(i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
if (m_bases[i]->AcceptCard(card) && m_bases[i] != pile)
|
|
|
|
{
|
|
|
|
pile->RemoveTopCard(dc);
|
|
|
|
m_bases[i]->AddCard(dc, card);
|
|
|
|
DoMove(dc, pile, m_bases[i]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test to see whether the game has been won:
|
|
|
|
// i.e. m_pack, discard and bases are empty
|
|
|
|
bool Game::HaveYouWon()
|
|
|
|
{
|
2004-03-23 16:23:17 -05:00
|
|
|
if (m_pack->GetTopCard()) return false;
|
|
|
|
if (m_discard->GetTopCard()) return false;
|
1998-07-24 15:43:32 -04:00
|
|
|
for(int i = 0; i < 10; i++)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
if (m_bases[i]->GetTopCard()) return false;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
m_numWins++;
|
|
|
|
m_totalScore += m_currentScore;
|
|
|
|
m_currentScore = 0;
|
2004-03-23 16:23:17 -05:00
|
|
|
return true;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// See whether the card under the cursor can be moved somewhere else
|
2004-03-23 16:23:17 -05:00
|
|
|
// Returns 'true' if it can be moved, 'false' otherwise
|
1998-07-24 15:43:32 -04:00
|
|
|
bool Game::CanYouGo(int x, int y)
|
|
|
|
{
|
|
|
|
Pile* pile = WhichPile(x, y);
|
|
|
|
if (pile && pile != m_pack)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
Card* card = pile->GetTopCard();
|
1998-07-24 15:43:32 -04:00
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
if (card)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile)
|
|
|
|
{
|
2004-03-23 16:23:17 -05:00
|
|
|
return true;
|
2004-06-02 05:14:59 -04:00
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
2004-06-02 05:14:59 -04:00
|
|
|
for(i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
if (m_bases[i]->GetTopCard() &&
|
|
|
|
m_bases[i]->AcceptCard(card) &&
|
|
|
|
m_bases[i] != pile)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
2004-06-02 05:14:59 -04:00
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
2004-03-23 16:23:17 -05:00
|
|
|
return false;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Called when the left button is released after dragging a card
|
|
|
|
// Scan the piles to see if this card overlaps a pile and can be added
|
|
|
|
// to the pile. If the card overlaps more than one pile on which it can be placed
|
|
|
|
// then put it on the nearest pile.
|
|
|
|
void Game::LButtonUp(wxDC& dc, int x, int y)
|
|
|
|
{
|
|
|
|
if (m_srcPile)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
// work out the position of the dragged card
|
|
|
|
x += m_xOffset;
|
1998-07-24 15:43:32 -04:00
|
|
|
y += m_yOffset;
|
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
Pile* nearestPile = 0;
|
|
|
|
int distance = (CardHeight + CardWidth) * (CardHeight + CardWidth);
|
|
|
|
|
|
|
|
// find the nearest pile which will accept the card
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
if (DropCard(x, y, m_foundations[i], m_liftedCard))
|
|
|
|
{
|
|
|
|
if (m_foundations[i]->CalcDistance(x, y) < distance)
|
|
|
|
{
|
|
|
|
nearestPile = m_foundations[i];
|
1998-07-24 15:43:32 -04:00
|
|
|
distance = nearestPile->CalcDistance(x, y);
|
|
|
|
}
|
|
|
|
}
|
2004-06-02 05:14:59 -04:00
|
|
|
}
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
if (DropCard(x, y, m_bases[i], m_liftedCard))
|
|
|
|
{
|
|
|
|
if (m_bases[i]->CalcDistance(x, y) < distance)
|
1998-07-24 15:43:32 -04:00
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
nearestPile = m_bases[i];
|
1998-07-24 15:43:32 -04:00
|
|
|
distance = nearestPile->CalcDistance(x, y);
|
|
|
|
}
|
|
|
|
}
|
2004-06-02 05:14:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Restore the area under the card
|
|
|
|
wxMemoryDC memoryDC;
|
|
|
|
memoryDC.SelectObject(*m_bmap);
|
|
|
|
dc.Blit(m_xPos, m_yPos, CardWidth, CardHeight,
|
|
|
|
&memoryDC, 0, 0, wxCOPY);
|
|
|
|
|
|
|
|
// Draw the card in its new position
|
|
|
|
if (nearestPile)
|
|
|
|
{
|
|
|
|
// Add to new pile
|
|
|
|
nearestPile->AddCard(dc, m_liftedCard);
|
|
|
|
if (nearestPile != m_srcPile)
|
|
|
|
{
|
|
|
|
DoMove(dc, m_srcPile, nearestPile);
|
|
|
|
}
|
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
else
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
// Return card to src pile
|
|
|
|
m_srcPile->AddCard(dc, m_liftedCard);
|
|
|
|
}
|
|
|
|
m_srcPile = 0;
|
|
|
|
m_liftedCard = 0;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Game::DropCard(int x, int y, Pile* pile, Card* card)
|
|
|
|
{
|
2004-03-23 16:23:17 -05:00
|
|
|
bool retval = false;
|
1998-07-24 15:43:32 -04:00
|
|
|
if (pile->Overlap(x, y))
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
if (pile->AcceptCard(card))
|
|
|
|
{
|
|
|
|
retval = true;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Game::MouseMove(wxDC& dc, int mx, int my)
|
|
|
|
{
|
|
|
|
if (m_liftedCard)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
wxMemoryDC memoryDC;
|
|
|
|
memoryDC.SelectObject(*m_bmap);
|
1998-07-24 15:43:32 -04:00
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
int dx = mx + m_xOffset - m_xPos;
|
|
|
|
int dy = my + m_yOffset - m_yPos;
|
1998-07-24 15:43:32 -04:00
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
if (abs(dx) >= CardWidth || abs(dy) >= CardHeight)
|
1998-07-24 15:43:32 -04:00
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
// Restore the area under the card
|
|
|
|
dc.Blit(m_xPos, m_yPos, CardWidth, CardHeight,
|
|
|
|
&memoryDC, 0, 0, wxCOPY);
|
|
|
|
|
|
|
|
// Copy the area under the card in the new position
|
|
|
|
memoryDC.Blit(0, 0, CardWidth, CardHeight,
|
|
|
|
&dc, m_xPos + dx, m_yPos + dy, wxCOPY);
|
|
|
|
}
|
|
|
|
else if (dx >= 0)
|
|
|
|
{
|
|
|
|
// dx >= 0
|
|
|
|
dc.Blit(m_xPos, m_yPos, dx, CardHeight, &memoryDC, 0, 0, wxCOPY);
|
|
|
|
if (dy >= 0)
|
|
|
|
{
|
|
|
|
// dy >= 0
|
|
|
|
dc.Blit(m_xPos + dx, m_yPos, CardWidth - dx, dy, &memoryDC, dx, 0, wxCOPY);
|
|
|
|
memoryDC.Blit(0, 0, CardWidth - dx, CardHeight - dy,
|
|
|
|
&memoryDC, dx, dy, wxCOPY);
|
|
|
|
memoryDC.Blit(0, CardHeight - dy, CardWidth - dx, dy,
|
|
|
|
&dc, m_xPos + dx, m_yPos + CardHeight, wxCOPY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// dy < 0
|
|
|
|
dc.Blit(m_xPos + dx, m_yPos + dy + CardHeight, CardWidth - dx, -dy,
|
|
|
|
&memoryDC, dx, CardHeight + dy, wxCOPY);
|
|
|
|
memoryDC.Blit(0, -dy, CardWidth - dx, CardHeight + dy,
|
|
|
|
&memoryDC, dx, 0, wxCOPY);
|
|
|
|
memoryDC.Blit(0, 0, CardWidth - dx, -dy,
|
|
|
|
&dc, m_xPos + dx, m_yPos + dy, wxCOPY);
|
|
|
|
}
|
|
|
|
memoryDC.Blit(CardWidth - dx, 0, dx, CardHeight,
|
|
|
|
&dc, m_xPos + CardWidth, m_yPos + dy, wxCOPY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// dx < 0
|
|
|
|
dc.Blit(m_xPos + CardWidth + dx, m_yPos, -dx, CardHeight,
|
|
|
|
&memoryDC, CardWidth + dx, 0, wxCOPY);
|
|
|
|
if (dy >= 0)
|
|
|
|
{
|
|
|
|
dc.Blit(m_xPos, m_yPos, CardWidth + dx, dy, &memoryDC, 0, 0, wxCOPY);
|
|
|
|
memoryDC.Blit(-dx, 0, CardWidth + dx, CardHeight - dy,
|
|
|
|
&memoryDC, 0, dy, wxCOPY);
|
|
|
|
memoryDC.Blit(-dx, CardHeight - dy, CardWidth + dx, dy,
|
|
|
|
&dc, m_xPos, m_yPos + CardHeight, wxCOPY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// dy < 0
|
|
|
|
dc.Blit(m_xPos, m_yPos + CardHeight + dy, CardWidth + dx, -dy,
|
|
|
|
&memoryDC, 0, CardHeight + dy, wxCOPY);
|
|
|
|
memoryDC.Blit(-dx, -dy, CardWidth + dx, CardHeight + dy,
|
|
|
|
&memoryDC, 0, 0, wxCOPY);
|
|
|
|
memoryDC.Blit(-dx, 0, CardWidth + dx, -dy,
|
|
|
|
&dc, m_xPos, m_yPos + dy, wxCOPY);
|
|
|
|
}
|
|
|
|
memoryDC.Blit(0, 0, -dx, CardHeight,
|
|
|
|
&dc, m_xPos + dx, m_yPos + dy, wxCOPY);
|
|
|
|
}
|
|
|
|
m_xPos += dx;
|
|
|
|
m_yPos += dy;
|
|
|
|
|
|
|
|
// draw the card in its new position
|
|
|
|
memoryDC.SelectObject(*m_bmapCard);
|
|
|
|
dc.Blit(m_xPos, m_yPos, CardWidth, CardHeight,
|
|
|
|
&memoryDC, 0, 0, wxCOPY);
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------//
|
|
|
|
// The Pack class: holds the two decks of cards //
|
|
|
|
//----------------------------------------------//
|
|
|
|
Pack::Pack(int x, int y) : Pile(x, y, 0, 0)
|
|
|
|
{
|
|
|
|
for (m_topCard = 0; m_topCard < NumCards; m_topCard++)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
m_cards[m_topCard] = new Card(1 + m_topCard / 2, facedown);
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
m_topCard = NumCards - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Pack::Shuffle()
|
|
|
|
{
|
|
|
|
Card* temp[NumCards];
|
|
|
|
int i;
|
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
// Don't try to shuffle an empty m_pack!
|
1998-07-24 15:43:32 -04:00
|
|
|
if (m_topCard < 0) return;
|
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
// Copy the cards into a temporary array. Start by clearing
|
|
|
|
// the array and then copy the card into a random position.
|
|
|
|
// If the position is occupied then find the next lower position.
|
1998-07-24 15:43:32 -04:00
|
|
|
for (i = 0; i <= m_topCard; i++)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
temp[i] = 0;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
for (i = 0; i <= m_topCard; i++)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
int pos = rand() % (m_topCard + 1);
|
|
|
|
while (temp[pos])
|
|
|
|
{
|
|
|
|
pos--;
|
|
|
|
if (pos < 0) pos = m_topCard;
|
|
|
|
}
|
|
|
|
m_cards[i]->TurnCard(facedown);
|
|
|
|
temp[pos] = m_cards[i];
|
1998-07-24 15:43:32 -04:00
|
|
|
m_cards[i] = 0;
|
|
|
|
}
|
|
|
|
|
2004-06-02 05:14:59 -04:00
|
|
|
// Copy each card back into the m_pack in a random
|
|
|
|
// position. If position is occupied then find nearest
|
|
|
|
// unoccupied position after the random position.
|
1998-07-24 15:43:32 -04:00
|
|
|
for (i = 0; i <= m_topCard; i++)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
int pos = rand() % (m_topCard + 1);
|
|
|
|
while (m_cards[pos])
|
|
|
|
{
|
|
|
|
pos++;
|
1998-07-24 15:43:32 -04:00
|
|
|
if (pos > m_topCard) pos = 0;
|
2004-06-02 05:14:59 -04:00
|
|
|
}
|
1998-07-24 15:43:32 -04:00
|
|
|
m_cards[pos] = temp[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Pack::Redraw(wxDC& dc)
|
|
|
|
{
|
|
|
|
Pile::Redraw(dc);
|
|
|
|
|
2002-12-22 14:57:17 -05:00
|
|
|
wxString str;
|
|
|
|
str.Printf(_T("%d "), m_topCard + 1);
|
1998-07-24 15:43:32 -04:00
|
|
|
|
2000-01-12 12:57:18 -05:00
|
|
|
dc.SetBackgroundMode( wxSOLID );
|
2004-06-02 05:14:59 -04:00
|
|
|
dc.SetTextBackground(FortyApp::BackgroundColour());
|
|
|
|
dc.SetTextForeground(FortyApp::TextColour());
|
1998-07-24 15:43:32 -04:00
|
|
|
dc.DrawText(str, m_x + CardWidth + 5, m_y + CardHeight / 2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Pack::AddCard(Card* card)
|
|
|
|
{
|
|
|
|
if (card == m_cards[m_topCard + 1])
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
m_topCard++;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
wxMessageBox(_T("Pack::AddCard() Undo error"), _T("Forty Thieves: Warning"),
|
|
|
|
wxOK | wxICON_EXCLAMATION);
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
card->TurnCard(facedown);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Pack::~Pack()
|
|
|
|
{
|
|
|
|
for (m_topCard = 0; m_topCard < NumCards; m_topCard++)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
delete m_cards[m_topCard];
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------//
|
|
|
|
// The Base class: holds the initial pile of four cards //
|
|
|
|
//------------------------------------------------------//
|
|
|
|
Base::Base(int x, int y) : Pile(x, y, 0, 12)
|
|
|
|
{
|
|
|
|
m_topCard = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Base::AcceptCard(Card* card)
|
|
|
|
{
|
2004-03-23 16:23:17 -05:00
|
|
|
bool retval = false;
|
1998-07-24 15:43:32 -04:00
|
|
|
|
|
|
|
if (m_topCard >= 0)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
if (m_cards[m_topCard]->GetSuit() == card->GetSuit() &&
|
|
|
|
m_cards[m_topCard]->GetPipValue() - 1 == card->GetPipValue())
|
|
|
|
{
|
2004-03-23 16:23:17 -05:00
|
|
|
retval = true;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
// pile is empty - ACCEPT
|
2004-03-23 16:23:17 -05:00
|
|
|
retval = true;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
Base::~Base()
|
|
|
|
{
|
|
|
|
// nothing special at the moment
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------//
|
|
|
|
// The Foundation class: holds the cards built up from the ace... //
|
|
|
|
//----------------------------------------------------------------//
|
|
|
|
Foundation::Foundation(int x, int y) : Pile(x, y, 0, 0)
|
|
|
|
{
|
|
|
|
m_topCard = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Foundation::AcceptCard(Card* card)
|
|
|
|
{
|
2004-03-23 16:23:17 -05:00
|
|
|
bool retval = false;
|
1998-07-24 15:43:32 -04:00
|
|
|
|
|
|
|
if (m_topCard >= 0)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
if (m_cards[m_topCard]->GetSuit() == card->GetSuit() &&
|
|
|
|
m_cards[m_topCard]->GetPipValue() + 1 == card->GetPipValue())
|
|
|
|
{
|
2004-03-23 16:23:17 -05:00
|
|
|
retval = true;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (card->GetPipValue() == 1)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
// It's an ace and the pile is empty - ACCEPT
|
2004-03-23 16:23:17 -05:00
|
|
|
retval = true;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
Foundation::~Foundation()
|
|
|
|
{
|
|
|
|
// nothing special at the moment
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------//
|
|
|
|
// The Discard class: holds cards dealt from the m_pack //
|
|
|
|
//----------------------------------------------------//
|
|
|
|
Discard::Discard(int x, int y) : Pile(x, y, 19, 0)
|
|
|
|
{
|
|
|
|
m_topCard = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Discard::Redraw(wxDC& dc)
|
|
|
|
{
|
|
|
|
if (m_topCard >= 0)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
if (m_dx == 0 && m_dy == 0)
|
|
|
|
{
|
1998-07-24 15:43:32 -04:00
|
|
|
m_cards[m_topCard]->Draw(dc, m_x, m_y);
|
2004-06-02 05:14:59 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int x = m_x;
|
|
|
|
int y = m_y;
|
|
|
|
for (int i = 0; i <= m_topCard; i++)
|
|
|
|
{
|
|
|
|
m_cards[i]->Draw(dc, x, y);
|
|
|
|
x += m_dx;
|
|
|
|
y += m_dy;
|
|
|
|
if (i == 31)
|
|
|
|
{
|
|
|
|
x = m_x;
|
1998-07-24 15:43:32 -04:00
|
|
|
y = m_y + CardHeight / 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
Card::DrawNullCard(dc, m_x, m_y);
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Discard::GetTopCardPos(int& x, int& y)
|
|
|
|
{
|
|
|
|
if (m_topCard < 0)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
x = m_x;
|
|
|
|
y = m_y;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
else if (m_topCard > 31)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
x = m_x + m_dx * (m_topCard - 32);
|
|
|
|
y = m_y + CardHeight / 3;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
x = m_x + m_dx * m_topCard;
|
|
|
|
y = m_y;
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Card* Discard::RemoveTopCard(wxDC& dc, int m_xOffset, int m_yOffset)
|
|
|
|
{
|
|
|
|
Card* card;
|
|
|
|
|
|
|
|
if (m_topCard <= 31)
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
card = Pile::RemoveTopCard(dc, m_xOffset, m_yOffset);
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-06-02 05:14:59 -04:00
|
|
|
int topX, topY, x, y;
|
|
|
|
GetTopCardPos(topX, topY);
|
|
|
|
card = Pile::RemoveTopCard();
|
|
|
|
card->Erase(dc, topX - m_xOffset, topY - m_yOffset);
|
|
|
|
GetTopCardPos(x, y);
|
|
|
|
dc.SetClippingRegion(topX - m_xOffset, topY - m_yOffset,
|
|
|
|
CardWidth, CardHeight);
|
|
|
|
|
|
|
|
for (int i = m_topCard - 31; i <= m_topCard - 31 + CardWidth / m_dx; i++)
|
|
|
|
{
|
|
|
|
m_cards[i]->Draw(dc, m_x - m_xOffset + i * m_dx, m_y - m_yOffset);
|
|
|
|
}
|
|
|
|
if (m_topCard > 31)
|
|
|
|
{
|
|
|
|
m_cards[m_topCard]->Draw(dc, topX - m_xOffset - m_dx, topY - m_yOffset);
|
|
|
|
}
|
|
|
|
dc.DestroyClippingRegion();
|
1998-07-24 15:43:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return card;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Discard::~Discard()
|
|
|
|
{
|
|
|
|
// nothing special at the moment
|
|
|
|
};
|