// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
-// Licence: wxWindows licence
+// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0
/////////////////////////////////////////////////////////////////////////////
END_EVENT_TABLE()
FortyCanvas::FortyCanvas(wxWindow* parent, const wxPoint& pos, const wxSize& size) :
- wxScrolledWindow(parent, wxID_ANY, pos, size),
- m_helpingHand(true),
- m_rightBtnUndo(true),
- m_playerDialog(0),
- m_leftBtnDown(false)
+ wxScrolledWindow(parent, wxID_ANY, pos, size),
+ m_helpingHand(true),
+ m_rightBtnUndo(true),
+ m_playerDialog(0),
+ m_leftBtnDown(false)
{
#ifdef __WXGTK__
- m_font = wxTheFontList->FindOrCreateFont(12, wxROMAN, wxNORMAL, wxNORMAL);
+ m_font = wxTheFontList->FindOrCreateFont(12, wxROMAN, wxNORMAL, wxNORMAL);
#else
- m_font = wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxNORMAL);
+ m_font = wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxNORMAL);
#endif
- SetBackgroundColour(FortyApp::BackgroundColour());
+ SetBackgroundColour(FortyApp::BackgroundColour());
- m_handCursor = new wxCursor(wxCURSOR_HAND);
- m_arrowCursor = new wxCursor(wxCURSOR_ARROW);
+ m_handCursor = new wxCursor(wxCURSOR_HAND);
+ m_arrowCursor = new wxCursor(wxCURSOR_ARROW);
- wxString name = wxTheApp->GetAppName();
- if (name.Length() <= 0) name = _T("forty");
- m_scoreFile = new ScoreFile(name);
- m_game = new Game(0, 0, 0);
- m_game->Deal();
+ wxString name = wxTheApp->GetAppName();
+ if (name.Length() <= 0) name = _T("forty");
+ m_scoreFile = new ScoreFile(name);
+ m_game = new Game(0, 0, 0);
+ m_game->Deal();
}
FortyCanvas::~FortyCanvas()
{
- UpdateScores();
- delete m_game;
- delete m_scoreFile;
+ UpdateScores();
+ delete m_game;
+ delete m_scoreFile;
delete m_handCursor;
delete m_arrowCursor;
}
*/
void FortyCanvas::UpdateScores()
{
- if (m_player.Length() > 0 && m_scoreFile && m_game)
- {
- m_scoreFile->WritePlayersScore(
- m_player,
- m_game->GetNumWins(),
- m_game->GetNumGames(),
- m_game->GetScore()
- );
- }
+ if (m_player.Length() > 0 && m_scoreFile && m_game)
+ {
+ m_scoreFile->WritePlayersScore(
+ m_player,
+ m_game->GetNumWins(),
+ m_game->GetNumGames(),
+ m_game->GetScore()
+ );
+ }
}
void FortyCanvas::OnDraw(wxDC& dc)
{
- dc.SetFont(* m_font);
- m_game->Redraw(dc);
+ dc.SetFont(* m_font);
+ m_game->Redraw(dc);
#if 0
- // if player name not set (and selection dialog is not displayed)
- // then ask the player for their name
- if (m_player.Length() == 0 && !m_playerDialog)
- {
- m_playerDialog = new PlayerSelectionDialog(this, m_scoreFile);
- m_playerDialog->ShowModal();
- m_player = m_playerDialog->GetPlayersName();
- if (m_player.Length() > 0)
- {
- // user entered a name - lookup their score
- int wins, games, score;
- m_scoreFile->ReadPlayersScore(m_player, wins, games, score);
- m_game->NewPlayer(wins, games, score);
- m_game->DisplayScore(dc);
- m_playerDialog->Destroy();
- m_playerDialog = 0;
- Refresh(false);
- }
- else
- {
- // user cancelled the dialog - exit the app
- ((wxFrame*)GetParent())->Close(true);
- }
- }
+ // if player name not set (and selection dialog is not displayed)
+ // then ask the player for their name
+ if (m_player.Length() == 0 && !m_playerDialog)
+ {
+ m_playerDialog = new PlayerSelectionDialog(this, m_scoreFile);
+ m_playerDialog->ShowModal();
+ m_player = m_playerDialog->GetPlayersName();
+ if (m_player.Length() > 0)
+ {
+ // user entered a name - lookup their score
+ int wins, games, score;
+ m_scoreFile->ReadPlayersScore(m_player, wins, games, score);
+ m_game->NewPlayer(wins, games, score);
+ m_game->DisplayScore(dc);
+ m_playerDialog->Destroy();
+ m_playerDialog = 0;
+ Refresh(false);
+ }
+ else
+ {
+ // user cancelled the dialog - exit the app
+ ((wxFrame*)GetParent())->Close(true);
+ }
+ }
#endif
}
void FortyCanvas::ShowPlayerDialog()
{
- // if player name not set (and selection dialog is not displayed)
- // then ask the player for their name
- if (m_player.Length() == 0 && !m_playerDialog)
- {
- m_playerDialog = new PlayerSelectionDialog(this, m_scoreFile);
- m_playerDialog->ShowModal();
- m_player = m_playerDialog->GetPlayersName();
- if (m_player.Length() > 0)
- {
- // user entered a name - lookup their score
- int wins, games, score;
- m_scoreFile->ReadPlayersScore(m_player, wins, games, score);
- m_game->NewPlayer(wins, games, score);
+ // if player name not set (and selection dialog is not displayed)
+ // then ask the player for their name
+ if (m_player.Length() == 0 && !m_playerDialog)
+ {
+ m_playerDialog = new PlayerSelectionDialog(this, m_scoreFile);
+ m_playerDialog->ShowModal();
+ m_player = m_playerDialog->GetPlayersName();
+ if (m_player.Length() > 0)
+ {
+ // user entered a name - lookup their score
+ int wins, games, score;
+ m_scoreFile->ReadPlayersScore(m_player, wins, games, score);
+ m_game->NewPlayer(wins, games, score);
- wxClientDC dc(this);
- dc.SetFont(* m_font);
- m_game->DisplayScore(dc);
- m_playerDialog->Destroy();
- m_playerDialog = 0;
- Refresh(false);
- }
- else
- {
- // user cancelled the dialog - exit the app
- ((wxFrame*)GetParent())->Close(true);
- }
+ wxClientDC dc(this);
+ dc.SetFont(* m_font);
+ m_game->DisplayScore(dc);
+ m_playerDialog->Destroy();
+ m_playerDialog = 0;
+ Refresh(false);
}
+ else
+ {
+ // user cancelled the dialog - exit the app
+ ((wxFrame*)GetParent())->Close(true);
+ }
+ }
}
/*
*/
bool FortyCanvas::OnCloseCanvas()
{
- if (m_game->InPlay() &&
- wxMessageBox(_T("Are you sure you want to\nabandon the current game?"),
- _T("Warning"), wxYES_NO | wxICON_QUESTION) == wxNO)
- {
+ if (m_game->InPlay() &&
+ wxMessageBox(_T("Are you sure you want to\nabandon the current game?"),
+ _T("Warning"), wxYES_NO | wxICON_QUESTION) == wxNO)
+ {
return false;
- }
- return true;
+ }
+ return true;
}
void FortyCanvas::OnMouseEvent(wxMouseEvent& event)
{
- int mouseX = (int)event.GetX();
- int mouseY = (int)event.GetY();
+ int mouseX = (int)event.GetX();
+ int mouseY = (int)event.GetY();
- wxClientDC dc(this);
- PrepareDC(dc);
- dc.SetFont(* m_font);
+ wxClientDC dc(this);
+ PrepareDC(dc);
+ dc.SetFont(* m_font);
- if (event.LeftDClick())
- {
- if (m_leftBtnDown)
- {
- m_leftBtnDown = false;
- ReleaseMouse();
- m_game->LButtonUp(dc, mouseX, mouseY);
- }
- m_game->LButtonDblClk(dc, mouseX, mouseY);
- }
- else if (event.LeftDown())
- {
- if (!m_leftBtnDown)
- {
- m_leftBtnDown = true;
- CaptureMouse();
- m_game->LButtonDown(dc, mouseX, mouseY);
- }
- }
- else if (event.LeftUp())
- {
- if (m_leftBtnDown)
- {
- m_leftBtnDown = false;
- ReleaseMouse();
- m_game->LButtonUp(dc, mouseX, mouseY);
- }
- }
- else if (event.RightDown() && !event.LeftIsDown())
- {
- // only allow right button undo if m_rightBtnUndo is true
- if (m_rightBtnUndo)
- {
- if (event.ControlDown() || event.ShiftDown())
- {
- m_game->Redo(dc);
- }
- else
- {
- m_game->Undo(dc);
- }
- }
- }
- else if (event.Dragging())
- {
- m_game->MouseMove(dc, mouseX, mouseY);
- }
+ if (event.LeftDClick())
+ {
+ if (m_leftBtnDown)
+ {
+ m_leftBtnDown = false;
+ ReleaseMouse();
+ m_game->LButtonUp(dc, mouseX, mouseY);
+ }
+ m_game->LButtonDblClk(dc, mouseX, mouseY);
+ }
+ else if (event.LeftDown())
+ {
+ if (!m_leftBtnDown)
+ {
+ m_leftBtnDown = true;
+ CaptureMouse();
+ m_game->LButtonDown(dc, mouseX, mouseY);
+ }
+ }
+ else if (event.LeftUp())
+ {
+ if (m_leftBtnDown)
+ {
+ m_leftBtnDown = false;
+ ReleaseMouse();
+ m_game->LButtonUp(dc, mouseX, mouseY);
+ }
+ }
+ else if (event.RightDown() && !event.LeftIsDown())
+ {
+ // only allow right button undo if m_rightBtnUndo is true
+ if (m_rightBtnUndo)
+ {
+ if (event.ControlDown() || event.ShiftDown())
+ {
+ m_game->Redo(dc);
+ }
+ else
+ {
+ m_game->Undo(dc);
+ }
+ }
+ }
+ else if (event.Dragging())
+ {
+ m_game->MouseMove(dc, mouseX, mouseY);
+ }
- if (!event.LeftIsDown())
- {
- SetCursorStyle(mouseX, mouseY);
- }
+ if (!event.LeftIsDown())
+ {
+ SetCursorStyle(mouseX, mouseY);
+ }
}
void FortyCanvas::SetCursorStyle(int x, int y)
{
- // Only set cursor to a hand if 'helping hand' is enabled and
- // the card under the cursor can go somewhere
- if (m_game->CanYouGo(x, y) && m_helpingHand)
- {
- SetCursor(* m_handCursor);
- }
- else
- {
- SetCursor(* m_arrowCursor);
- }
+ // Only set cursor to a hand if 'helping hand' is enabled and
+ // the card under the cursor can go somewhere
+ if (m_game->CanYouGo(x, y) && m_helpingHand)
+ {
+ SetCursor(* m_handCursor);
+ }
+ else
+ {
+ SetCursor(* m_arrowCursor);
+ }
}
void FortyCanvas::NewGame()
{
- m_game->Deal();
- Refresh();
+ m_game->Deal();
+ Refresh();
}
void FortyCanvas::Undo()
{
- wxClientDC dc(this);
- PrepareDC(dc);
- dc.SetFont(* m_font);
- m_game->Undo(dc);
+ wxClientDC dc(this);
+ PrepareDC(dc);
+ dc.SetFont(* m_font);
+ m_game->Undo(dc);
}
void FortyCanvas::Redo()
{
- wxClientDC dc(this);
- PrepareDC(dc);
- dc.SetFont(* m_font);
- m_game->Redo(dc);
+ wxClientDC dc(this);
+ PrepareDC(dc);
+ dc.SetFont(* m_font);
+ m_game->Redo(dc);
}
void FortyCanvas::LayoutGame()
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
-// Licence: wxWindows licence
+// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0
/////////////////////////////////////////////////////////////////////////////
class FortyCanvas: public wxScrolledWindow
{
public:
- FortyCanvas(wxWindow* parent, const wxPoint& pos, const wxSize& size);
- virtual ~FortyCanvas();
+ FortyCanvas(wxWindow* parent, const wxPoint& pos, const wxSize& size);
+ virtual ~FortyCanvas();
- virtual void OnDraw(wxDC& dc);
- bool OnCloseCanvas();
- void OnMouseEvent(wxMouseEvent& event);
- void SetCursorStyle(int x, int y);
+ virtual void OnDraw(wxDC& dc);
+ bool OnCloseCanvas();
+ void OnMouseEvent(wxMouseEvent& event);
+ void SetCursorStyle(int x, int y);
- void NewGame();
- void Undo();
- void Redo();
+ void NewGame();
+ void Undo();
+ void Redo();
- ScoreFile* GetScoreFile() const { return m_scoreFile; }
- void UpdateScores();
- void EnableHelpingHand(bool enable) { m_helpingHand = enable; }
- void EnableRightButtonUndo(bool enable) { m_rightBtnUndo = enable; }
- void LayoutGame();
- void ShowPlayerDialog();
+ ScoreFile* GetScoreFile() const { return m_scoreFile; }
+ void UpdateScores();
+ void EnableHelpingHand(bool enable) { m_helpingHand = enable; }
+ void EnableRightButtonUndo(bool enable) { m_rightBtnUndo = enable; }
+ void LayoutGame();
+ void ShowPlayerDialog();
- DECLARE_EVENT_TABLE()
+ DECLARE_EVENT_TABLE()
private:
- wxFont* m_font;
- Game* m_game;
- ScoreFile* m_scoreFile;
- wxCursor* m_arrowCursor;
- wxCursor* m_handCursor;
- bool m_helpingHand;
- bool m_rightBtnUndo;
- wxString m_player;
- PlayerSelectionDialog* m_playerDialog;
- bool m_leftBtnDown;
+ wxFont* m_font;
+ Game* m_game;
+ ScoreFile* m_scoreFile;
+ wxCursor* m_arrowCursor;
+ wxCursor* m_handCursor;
+ bool m_helpingHand;
+ bool m_rightBtnUndo;
+ wxString m_player;
+ PlayerSelectionDialog* m_playerDialog;
+ bool m_leftBtnDown;
};
#endif
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
-// Licence: wxWindows licence
+// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0
/////////////////////////////////////////////////////////////////////////////
//+-------------------------------------------------------------+
//| Description
-//| A class for drawing playing cards.
-//| Currently assumes that the card symbols have been
-//| loaded into hbmap_symbols and the pictures for the
-//| Jack, Queen and King have been loaded into
-//| hbmap_pictures.
+//| A class for drawing playing cards.
+//| Currently assumes that the card symbols have been
+//| loaded into hbmap_symbols and the pictures for the
+//| Jack, Queen and King have been loaded into
+//| hbmap_pictures.
//+-------------------------------------------------------------+
#ifdef __GNUG__
int Card::m_height = 70;
//+-------------------------------------------------------------+
-//| Card::Card() |
+//| Card::Card() |
//+-------------------------------------------------------------+
-//| Description: |
-//| Constructor for a playing card. |
-//| Checks that the value is in the range 1..52 and then |
-//| initialises the suit, colour, pipValue and wayUp. |
+//| Description: |
+//| Constructor for a playing card. |
+//| Checks that the value is in the range 1..52 and then |
+//| initialises the suit, colour, pipValue and wayUp. |
//+-------------------------------------------------------------+
Card::Card(int value, WayUp way_up) :
- m_wayUp(way_up)
+ m_wayUp(way_up)
{
- if (!m_symbolBmap)
- {
+ if (!m_symbolBmap)
+ {
#ifdef __WXMSW__
- m_symbolBmap = new wxBitmap(_T("CardSymbols"), wxBITMAP_TYPE_BMP_RESOURCE);
+ m_symbolBmap = new wxBitmap(_T("CardSymbols"), wxBITMAP_TYPE_BMP_RESOURCE);
#else
- m_symbolBmap = new wxBitmap(Symbols_bits, Symbols_width, Symbols_height);
+ m_symbolBmap = new wxBitmap(Symbols_bits, Symbols_width, Symbols_height);
#endif
- if (!m_symbolBmap->Ok())
- {
- ::wxMessageBox(_T("Failed to load bitmap CardSymbols"), _T("Error"));
- }
- }
- if (!m_pictureBmap)
- {
+ if (!m_symbolBmap->Ok())
+ {
+ ::wxMessageBox(_T("Failed to load bitmap CardSymbols"), _T("Error"));
+ }
+ }
+ if (!m_pictureBmap)
+ {
#ifdef __WXMSW__
- m_pictureBmap = new wxBitmap(_T("CardPictures"), wxBITMAP_TYPE_BMP_RESOURCE);
+ m_pictureBmap = new wxBitmap(_T("CardPictures"), wxBITMAP_TYPE_BMP_RESOURCE);
#else
- m_pictureBmap = new wxBitmap(Pictures);
+ m_pictureBmap = new wxBitmap(Pictures);
#endif
- if (!m_pictureBmap->Ok())
- {
- ::wxMessageBox(_T("Failed to load bitmap CardPictures"), _T("Error"));
- }
- }
+ if (!m_pictureBmap->Ok())
+ {
+ ::wxMessageBox(_T("Failed to load bitmap CardPictures"), _T("Error"));
+ }
+ }
if (value >= 1 && value <= PackSize)
{
- switch ((value - 1) / 13)
- {
- case 0:
- m_suit = clubs;
- m_colour = black;
- break;
- case 1:
- m_suit = diamonds;
- m_colour = red;
- break;
- case 2:
- m_suit = hearts;
- m_colour = red;
- break;
- case 3:
- m_suit = spades;
- m_colour = black;
- break;
- }
- m_pipValue = 1 + (value - 1) % 13;
- m_status = true;
+ switch ((value - 1) / 13)
+ {
+ case 0:
+ m_suit = clubs;
+ m_colour = black;
+ break;
+ case 1:
+ m_suit = diamonds;
+ m_colour = red;
+ break;
+ case 2:
+ m_suit = hearts;
+ m_colour = red;
+ break;
+ case 3:
+ m_suit = spades;
+ m_colour = black;
+ break;
+ }
+ m_pipValue = 1 + (value - 1) % 13;
+ m_status = true;
}
else
{
//+-------------------------------------------------------------+
-//| Card::SetScale() |
+//| Card::SetScale() |
//+-------------------------------------------------------------+
-//| Description: |
-//| Scales the cards |
+//| Description: |
+//| Scales the cards |
//+-------------------------------------------------------------+
void Card::SetScale(double scale)
{
}
//+-------------------------------------------------------------+
-//| Card::~Card() |
+//| Card::~Card() |
//+-------------------------------------------------------------+
-//| Description: |
-//| Destructor - nothing to do at present. |
+//| Description: |
+//| Destructor - nothing to do at present. |
//+-------------------------------------------------------------+
Card::~Card()
{
//+-------------------------------------------------------------+
-//| Card::Erase() |
+//| Card::Erase() |
//+-------------------------------------------------------------+
-//| Description: |
-//| Erase the card at (x, y) by drawing a rectangle in the |
-//| background colour. |
+//| Description: |
+//| Erase the card at (x, y) by drawing a rectangle in the |
+//| background colour. |
//+-------------------------------------------------------------+
void Card::Erase(wxDC& dc, int x, int y)
{
- wxPen* pen = wxThePenList->FindOrCreatePen(
- FortyApp::BackgroundColour(),
- 1,
- wxSOLID
- );
- dc.SetPen(* pen);
- dc.SetBrush(FortyApp::BackgroundBrush());
+ wxPen* pen = wxThePenList->FindOrCreatePen(
+ FortyApp::BackgroundColour(),
+ 1,
+ wxSOLID
+ );
+ dc.SetPen(* pen);
+ dc.SetBrush(FortyApp::BackgroundBrush());
dc.DrawRectangle(x, y, m_width, m_height);
} // Card::Erase()
//+-------------------------------------------------------------+
-//| Card::Draw() |
+//| Card::Draw() |
//+-------------------------------------------------------------+
-//| Description: |
-//| Draw the card at (x, y). |
-//| If the card is facedown draw the back of the card. |
-//| If the card is faceup draw the front of the card. |
-//| Cards are not held in bitmaps, instead they are drawn |
-//| from their constituent parts when required. |
-//| hbmap_symbols contains large and small suit symbols and |
-//| pip values. These are copied to the appropriate part of |
-//| the card. Picture cards use the pictures defined in |
-//| hbmap_pictures. Note that only one picture is defined |
-//| for the Jack, Queen and King, unlike a real pack where |
-//| each suit is different. |
-//| |
-//| WARNING: |
-//| The locations of these symbols is 'hard-wired' into the |
-//| code. Editing the bitmaps or the numbers below will |
-//| result in the wrong symbols being displayed. |
+//| Description: |
+//| Draw the card at (x, y). |
+//| If the card is facedown draw the back of the card. |
+//| If the card is faceup draw the front of the card. |
+//| Cards are not held in bitmaps, instead they are drawn |
+//| from their constituent parts when required. |
+//| hbmap_symbols contains large and small suit symbols and |
+//| pip values. These are copied to the appropriate part of |
+//| the card. Picture cards use the pictures defined in |
+//| hbmap_pictures. Note that only one picture is defined |
+//| for the Jack, Queen and King, unlike a real pack where |
+//| each suit is different. |
+//| |
+//| WARNING: |
+//| The locations of these symbols is 'hard-wired' into the |
+//| code. Editing the bitmaps or the numbers below will |
+//| result in the wrong symbols being displayed. |
//+-------------------------------------------------------------+
void Card::Draw(wxDC& dc, int x, int y)
{
- wxBrush backgroundBrush( dc.GetBackground() );
- dc.SetBrush(* wxWHITE_BRUSH);
- dc.SetPen(* wxBLACK_PEN);
+ wxBrush backgroundBrush( dc.GetBackground() );
+ dc.SetBrush(* wxWHITE_BRUSH);
+ dc.SetPen(* wxBLACK_PEN);
dc.DrawRoundedRectangle(x, y, m_width, m_height, 4);
- if (m_wayUp == facedown)
- {
- dc.SetBackground(* wxRED_BRUSH);
- dc.SetBackgroundMode(wxSOLID);
- wxBrush* brush = wxTheBrushList->FindOrCreateBrush(
- _T("BLACK"), wxCROSSDIAG_HATCH
- );
- dc.SetBrush(* brush);
-
- dc.DrawRoundedRectangle(
- x + 4, y + 4,
- m_width - 8, m_height - 8,
- 2
- );
- }
- else
- {
- wxMemoryDC memoryDC;
-
- memoryDC.SelectObject(*m_symbolBmap);
-
-// dc.SetBackgroundMode(wxTRANSPARENT);
-
- dc.SetTextBackground(*wxWHITE);
- switch (m_suit)
- {
- case spades:
- case clubs:
- dc.SetTextForeground(*wxBLACK);
- break;
- case diamonds:
- case hearts:
- dc.SetTextForeground(*wxRED);
- break;
- }
-
- int symsize = 11;
- int sympos = 14;
- int sympos2 = 25;
- int symdist = 5;
- int symdist2 = 6;
-
- int pipsize,pippos,valueheight,valuewidth;
- int valuepos;
- if (m_scale > 1.2)
- {
- pipsize = symsize;
- pippos = sympos;
- valueheight = 10;
- valuewidth = 9;
- valuepos = 50;
- }
- else
- {
- pipsize = 7;
- pippos = 0;
- valueheight = 7;
- valuewidth = 6;
- valuepos = 36;
- }
-
- // Draw the value
- dc.Blit((wxCoord)(x + m_scale*3), (wxCoord)(y + m_scale*3), valuewidth, valueheight,
- &memoryDC, valuewidth * (m_pipValue - 1), valuepos, wxCOPY);
- dc.Blit((wxCoord)(x + m_width - m_scale*3 - valuewidth), (wxCoord)(y + m_height - valueheight - m_scale*3),
- valuewidth, valueheight,
- &memoryDC, valuewidth * (m_pipValue - 1), valuepos+valueheight, wxCOPY);
-
- // Draw the pips
- dc.Blit((wxCoord)(x + m_scale*3 + valuewidth+2), (wxCoord)(y + m_scale*3), pipsize, pipsize,
- &memoryDC, pipsize * m_suit, pippos, wxCOPY);
- dc.Blit((wxCoord)(x + m_width - m_scale*3-valuewidth-pipsize-2), (wxCoord)(y + m_height - pipsize - m_scale*3),
- pipsize, pipsize,
- &memoryDC, pipsize * m_suit, pipsize+pippos, wxCOPY);
-
- switch (m_pipValue)
- {
- case 1:
- dc.Blit((wxCoord)(x - symdist + m_width / 2), (wxCoord)(y - m_scale*5 + m_height / 2), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos, wxCOPY);
- break;
-
- case 3:
- dc.Blit((wxCoord)(x - symdist + m_width / 2), (wxCoord)(y - symdist + m_height / 2), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos, wxCOPY);
- case 2:
- dc.Blit((wxCoord)(x - symdist + m_width / 2),
- (wxCoord)(y - symdist + m_height / 4), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos, wxCOPY);
- dc.Blit((wxCoord)(x - symdist + m_width / 2),
- (wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos2, wxCOPY);
- break;
-
- case 5:
- dc.Blit((wxCoord)(x - symdist + m_width / 2), (wxCoord)(y - symdist + m_height / 2), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos, wxCOPY);
- case 4:
- dc.Blit((wxCoord)(x - symdist + m_width / 4),
- (wxCoord)(y - symdist + m_height / 4), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos, wxCOPY);
- dc.Blit((wxCoord)(x - symdist + m_width / 4),
- (wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos2, wxCOPY);
- dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
- (wxCoord)(y - symdist + m_height / 4), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos, wxCOPY);
- dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
- (wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos2, wxCOPY);
- break;
-
- case 8:
- dc.Blit((wxCoord)(x - symdist + 5 * m_width / 10),
- (wxCoord)(y - symdist + 5 * m_height / 8), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos2, wxCOPY);
- case 7:
- dc.Blit((wxCoord)(x - symdist + 5 * m_width / 10),
- (wxCoord)(y - symdist + 3 * m_height / 8), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos, wxCOPY);
- case 6:
- dc.Blit((wxCoord)(x - symdist + m_width / 4),
- (wxCoord)(y - symdist + m_height / 4), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos, wxCOPY);
- dc.Blit((wxCoord)(x - symdist + m_width / 4),
- (wxCoord)(y - symdist + m_height / 2), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos, wxCOPY);
- dc.Blit((wxCoord)(x - symdist + m_width / 4),
- (wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos2, wxCOPY);
- dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
- (wxCoord)(y - symdist + m_height / 4), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos, wxCOPY);
- dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
- (wxCoord)(y - symdist + m_height / 2), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos, wxCOPY);
- dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
- (wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos2, wxCOPY);
- break;
-
- case 10:
- dc.Blit((wxCoord)(x - symdist + m_width / 2),
- (wxCoord)(y - symdist + 2 * m_height / 3), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos2, wxCOPY);
- case 9:
- dc.Blit((wxCoord)(x - symdist + m_width / 4),
- (wxCoord)(y - symdist2 + m_height / 4), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos, wxCOPY);
- dc.Blit((wxCoord)(x - symdist + m_width / 4),
- (wxCoord)(y - symdist2 + 5 * m_height / 12), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos, wxCOPY);
- dc.Blit((wxCoord)(x - symdist + m_width / 4),
- (wxCoord)(y - symdist + 7 * m_height / 12), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos2, wxCOPY);
- dc.Blit((wxCoord)(x - symdist + m_width / 4),
- (wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos2, wxCOPY);
-
- dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
- (wxCoord)(y - symdist2 + m_height / 4), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos, wxCOPY);
- dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
- (wxCoord)(y - symdist2 + 5 * m_height / 12), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos, wxCOPY);
- dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
- (wxCoord)(y - symdist + 7 * m_height / 12), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos2, wxCOPY);
- dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
- (wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos2, wxCOPY);
- dc.Blit((wxCoord)(x - symdist + m_width / 2),
- (wxCoord)(y - symdist + m_height / 3), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos, wxCOPY);
- break;
- case 11:
- case 12:
- case 13:
- memoryDC.SelectObject(*m_pictureBmap);
- int picwidth = 40,picheight = 45;
- dc.Blit((wxCoord)(x + (m_width-picwidth)/2), (wxCoord)(y - picheight/2 + m_height/2),
- picwidth, picheight,
- &memoryDC, picwidth * (m_pipValue - 11), 0, wxCOPY);
-
- memoryDC.SelectObject(*m_symbolBmap);
- dc.Blit((wxCoord)(x + m_width-(m_width-picwidth)/2-symsize-3),(wxCoord)(y - picheight/2+m_height/2+1), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos, wxCOPY);
- dc.Blit((wxCoord)(x + (m_width-picwidth)/2+2),(wxCoord)(y + picheight/2 + m_height/2-symsize), symsize, symsize,
- &memoryDC, symsize * m_suit, sympos2, wxCOPY);
- break;
- }
-
- }
- dc.SetBackground( backgroundBrush );
+ if (m_wayUp == facedown)
+ {
+ dc.SetBackground(* wxRED_BRUSH);
+ dc.SetBackgroundMode(wxSOLID);
+ wxBrush* brush = wxTheBrushList->FindOrCreateBrush(
+ _T("BLACK"), wxCROSSDIAG_HATCH
+ );
+ dc.SetBrush(* brush);
+
+ dc.DrawRoundedRectangle(
+ x + 4, y + 4,
+ m_width - 8, m_height - 8,
+ 2
+ );
+ }
+ else
+ {
+ wxMemoryDC memoryDC;
+
+ memoryDC.SelectObject(*m_symbolBmap);
+
+// dc.SetBackgroundMode(wxTRANSPARENT);
+
+ dc.SetTextBackground(*wxWHITE);
+ switch (m_suit)
+ {
+ case spades:
+ case clubs:
+ dc.SetTextForeground(*wxBLACK);
+ break;
+ case diamonds:
+ case hearts:
+ dc.SetTextForeground(*wxRED);
+ break;
+ }
+
+ int symsize = 11;
+ int sympos = 14;
+ int sympos2 = 25;
+ int symdist = 5;
+ int symdist2 = 6;
+
+ int pipsize,pippos,valueheight,valuewidth;
+ int valuepos;
+ if (m_scale > 1.2)
+ {
+ pipsize = symsize;
+ pippos = sympos;
+ valueheight = 10;
+ valuewidth = 9;
+ valuepos = 50;
+ }
+ else
+ {
+ pipsize = 7;
+ pippos = 0;
+ valueheight = 7;
+ valuewidth = 6;
+ valuepos = 36;
+ }
+
+ // Draw the value
+ dc.Blit((wxCoord)(x + m_scale*3),
+ (wxCoord)(y + m_scale*3),
+ valuewidth,
+ valueheight,
+ &memoryDC,
+ valuewidth * (m_pipValue - 1),
+ valuepos,
+ wxCOPY);
+ dc.Blit((wxCoord)(x + m_width - m_scale*3 - valuewidth),
+ (wxCoord)(y + m_height - valueheight - m_scale*3),
+ valuewidth,
+ valueheight,
+ &memoryDC,
+ valuewidth * (m_pipValue - 1),
+ valuepos+valueheight,
+ wxCOPY);
+
+ // Draw the pips
+ dc.Blit((wxCoord)(x + m_scale*3 + valuewidth+2),
+ (wxCoord)(y + m_scale*3),
+ pipsize,
+ pipsize,
+ &memoryDC,
+ pipsize * m_suit,
+ pippos,
+ wxCOPY);
+ dc.Blit((wxCoord)(x + m_width - m_scale*3-valuewidth-pipsize-2),
+ (wxCoord)(y + m_height - pipsize - m_scale*3),
+ pipsize,
+ pipsize,
+ &memoryDC,
+ pipsize * m_suit,
+ pipsize+pippos,
+ wxCOPY);
+
+ switch (m_pipValue)
+ {
+ case 1:
+ dc.Blit((wxCoord)(x - symdist + m_width / 2),
+ (wxCoord)(y - m_scale*5 + m_height / 2),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos,
+ wxCOPY);
+ break;
+
+ case 3:
+ dc.Blit((wxCoord)(x - symdist + m_width / 2),
+ (wxCoord)(y - symdist + m_height / 2),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos,
+ wxCOPY);
+ case 2:
+ dc.Blit((wxCoord)(x - symdist + m_width / 2),
+ (wxCoord)(y - symdist + m_height / 4),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos,
+ wxCOPY);
+ dc.Blit((wxCoord)(x - symdist + m_width / 2),
+ (wxCoord)(y - symdist + 3 * m_height / 4),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos2,
+ wxCOPY);
+ break;
+
+ case 5:
+ dc.Blit((wxCoord)(x - symdist + m_width / 2),
+ (wxCoord)(y - symdist + m_height / 2),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos,
+ wxCOPY);
+ case 4:
+ dc.Blit((wxCoord)(x - symdist + m_width / 4),
+ (wxCoord)(y - symdist + m_height / 4),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos,
+ wxCOPY);
+ dc.Blit((wxCoord)(x - symdist + m_width / 4),
+ (wxCoord)(y - symdist + 3 * m_height / 4),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos2,
+ wxCOPY);
+ dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
+ (wxCoord)(y - symdist + m_height / 4),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos,
+ wxCOPY);
+ dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
+ (wxCoord)(y - symdist + 3 * m_height / 4),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos2,
+ wxCOPY);
+ break;
+
+ case 8:
+ dc.Blit((wxCoord)(x - symdist + 5 * m_width / 10),
+ (wxCoord)(y - symdist + 5 * m_height / 8),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos2,
+ wxCOPY);
+ case 7:
+ dc.Blit((wxCoord)(x - symdist + 5 * m_width / 10),
+ (wxCoord)(y - symdist + 3 * m_height / 8),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos,
+ wxCOPY);
+ case 6:
+ dc.Blit((wxCoord)(x - symdist + m_width / 4),
+ (wxCoord)(y - symdist + m_height / 4),
+ symsize,
+ symsize,
+ &memoryDC, symsize * m_suit, sympos, wxCOPY);
+ dc.Blit((wxCoord)(x - symdist + m_width / 4),
+ (wxCoord)(y - symdist + m_height / 2),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos,
+ wxCOPY);
+ dc.Blit((wxCoord)(x - symdist + m_width / 4),
+ (wxCoord)(y - symdist + 3 * m_height / 4),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos2,
+ wxCOPY);
+ dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
+ (wxCoord)(y - symdist + m_height / 4),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos,
+ wxCOPY);
+ dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
+ (wxCoord)(y - symdist + m_height / 2),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos,
+ wxCOPY);
+ dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
+ (wxCoord)(y - symdist + 3 * m_height / 4),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos2,
+ wxCOPY);
+ break;
+
+ case 10:
+ dc.Blit((wxCoord)(x - symdist + m_width / 2),
+ (wxCoord)(y - symdist + 2 * m_height / 3),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos2,
+ wxCOPY);
+ case 9:
+ dc.Blit((wxCoord)(x - symdist + m_width / 4),
+ (wxCoord)(y - symdist2 + m_height / 4),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos,
+ wxCOPY);
+ dc.Blit((wxCoord)(x - symdist + m_width / 4),
+ (wxCoord)(y - symdist2 + 5 * m_height / 12),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos,
+ wxCOPY);
+ dc.Blit((wxCoord)(x - symdist + m_width / 4),
+ (wxCoord)(y - symdist + 7 * m_height / 12),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos2,
+ wxCOPY);
+ dc.Blit((wxCoord)(x - symdist + m_width / 4),
+ (wxCoord)(y - symdist + 3 * m_height / 4),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos2,
+ wxCOPY);
+
+ dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
+ (wxCoord)(y - symdist2 + m_height / 4),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos,
+ wxCOPY);
+ dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
+ (wxCoord)(y - symdist2 + 5 * m_height / 12),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos,
+ wxCOPY);
+ dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
+ (wxCoord)(y - symdist + 7 * m_height / 12),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos2,
+ wxCOPY);
+ dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
+ (wxCoord)(y - symdist + 3 * m_height / 4),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos2,
+ wxCOPY);
+ dc.Blit((wxCoord)(x - symdist + m_width / 2),
+ (wxCoord)(y - symdist + m_height / 3),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos,
+ wxCOPY);
+ break;
+ case 11:
+ case 12:
+ case 13:
+ memoryDC.SelectObject(*m_pictureBmap);
+ int picwidth = 40,picheight = 45;
+ dc.Blit((wxCoord)(x + (m_width-picwidth)/2),
+ (wxCoord)(y - picheight/2 + m_height/2),
+ picwidth,
+ picheight,
+ &memoryDC,
+ picwidth * (m_pipValue - 11),
+ 0,
+ wxCOPY);
+
+ memoryDC.SelectObject(*m_symbolBmap);
+ dc.Blit((wxCoord)(x + m_width-(m_width-picwidth)/2-symsize-3),
+ (wxCoord)(y - picheight/2+m_height/2+1),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos,
+ wxCOPY);
+ dc.Blit((wxCoord)(x + (m_width-picwidth)/2+2),
+ (wxCoord)(y + picheight/2 + m_height/2-symsize),
+ symsize,
+ symsize,
+ &memoryDC,
+ symsize * m_suit,
+ sympos2,
+ wxCOPY);
+ break;
+ }
+
+ }
+ dc.SetBackground( backgroundBrush );
} // Card:Draw()
//+-------------------------------------------------------------+
-//| Card::DrawNullCard() |
+//| Card::DrawNullCard() |
//+-------------------------------------------------------------+
-//| Description: |
-//| Draws the outline of a card at (x, y). |
-//| Used to draw place holders for empty piles of cards. |
+//| Description: |
+//| Draws the outline of a card at (x, y). |
+//| Used to draw place holders for empty piles of cards. |
//+-------------------------------------------------------------+
void Card::DrawNullCard(wxDC& dc, int x, int y)
{
- wxPen* pen = wxThePenList->FindOrCreatePen(FortyApp::TextColour(), 1, wxSOLID);
- dc.SetBrush(FortyApp::BackgroundBrush());
- dc.SetPen(*pen);
- dc.DrawRoundedRectangle(x, y, m_width, m_height, 4);
+ wxPen* pen = wxThePenList->FindOrCreatePen(FortyApp::TextColour(), 1, wxSOLID);
+ dc.SetBrush(FortyApp::BackgroundBrush());
+ dc.SetPen(*pen);
+ dc.DrawRoundedRectangle(x, y, m_width, m_height, 4);
} // Card::DrawNullCard()
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
-// Licence: wxWindows licence
+// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0
/////////////////////////////////////////////////////////////////////////////
//+-------------------------------------------------------------+
-//| Description: |
-//| A class for drawing playing cards. |
-//| InitCards() must be called before using the Card class, |
-//| otherwise the card bitmaps will not be loaded. |
-//| CloseCards() must be called before terminating the |
-//| program so that the bitmaps are deleted and the memory |
-//| given back to Windows. |
+//| Description: |
+//| A class for drawing playing cards. |
+//| InitCards() must be called before using the Card class, |
+//| otherwise the card bitmaps will not be loaded. |
+//| CloseCards() must be called before terminating the |
+//| program so that the bitmaps are deleted and the memory |
+//| given back to Windows. |
//+-------------------------------------------------------------+
#ifndef _CARD_H_
#define _CARD_H_
- // Constants
+// Constants
const int PackSize = 52;
#define CardHeight Card::GetHeight()
#define CardWidth Card::GetWidth()
- // Data types
+// Data types
enum Suit { clubs = 0, diamonds = 1, hearts = 2, spades = 3 };
enum SuitColour { red = 0, black = 1 };
enum WayUp { faceup, facedown };
static int m_width,m_height;
public:
- Card(int value, WayUp way_up = facedown);
- virtual ~Card();
+ Card(int value, WayUp way_up = facedown);
+ virtual ~Card();
- void Draw(wxDC& pDC, int x, int y);
- static void DrawNullCard(wxDC& pDC, int x, int y); // Draw card place-holder
- void Erase(wxDC& pDC, int x, int y);
+ void Draw(wxDC& pDC, int x, int y);
+ static void DrawNullCard(wxDC& pDC, int x, int y); // Draw card place-holder
+ void Erase(wxDC& pDC, int x, int y);
- void TurnCard(WayUp way_up = faceup) { m_wayUp = way_up; }
- WayUp GetWayUp() const { return m_wayUp; }
- int GetPipValue() const { return m_pipValue; }
- Suit GetSuit() const { return m_suit; }
- SuitColour GetColour() const { return m_colour; }
- static void SetScale(double scale);
- static int GetHeight() { return m_height; };
- static int GetWidth() { return m_width; };
- static double GetScale() { return m_scale; };
+ void TurnCard(WayUp way_up = faceup) { m_wayUp = way_up; }
+ WayUp GetWayUp() const { return m_wayUp; }
+ int GetPipValue() const { return m_pipValue; }
+ Suit GetSuit() const { return m_suit; }
+ SuitColour GetColour() const { return m_colour; }
+ static void SetScale(double scale);
+ static int GetHeight() { return m_height; };
+ static int GetWidth() { return m_width; };
+ static double GetScale() { return m_scale; };
private:
- Suit m_suit;
- int m_pipValue; // in the range 1 (Ace) to 13 (King)
- SuitColour m_colour; // red or black
- bool m_status;
- WayUp m_wayUp;
+ Suit m_suit;
+ int m_pipValue; // in the range 1 (Ace) to 13 (King)
+ SuitColour m_colour; // red or black
+ bool m_status;
+ WayUp m_wayUp;
- static wxBitmap* m_symbolBmap;
- static wxBitmap* m_pictureBmap;
+ static wxBitmap* m_symbolBmap;
+ static wxBitmap* m_pictureBmap;
};
#endif // _CARD_H_
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
-// Licence: wxWindows licence
+// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0
/////////////////////////////////////////////////////////////////////////////
#endif
BEGIN_EVENT_TABLE(FortyFrame, wxFrame)
- EVT_MENU(NEW_GAME, FortyFrame::NewGame)
- EVT_MENU(wxID_EXIT, FortyFrame::Exit)
- EVT_MENU(wxID_ABOUT, FortyFrame::About)
- EVT_MENU(wxID_HELP_CONTENTS, FortyFrame::Help)
- EVT_MENU(UNDO, FortyFrame::Undo)
- EVT_MENU(REDO, FortyFrame::Redo)
- EVT_MENU(SCORES, FortyFrame::Scores)
- EVT_MENU(RIGHT_BUTTON_UNDO, FortyFrame::ToggleRightButtonUndo)
- EVT_MENU(HELPING_HAND, FortyFrame::ToggleHelpingHand)
- EVT_MENU(LARGE_CARDS, FortyFrame::ToggleCardSize)
+ EVT_MENU(NEW_GAME, FortyFrame::NewGame)
+ EVT_MENU(wxID_EXIT, FortyFrame::Exit)
+ EVT_MENU(wxID_ABOUT, FortyFrame::About)
+ EVT_MENU(wxID_HELP_CONTENTS, FortyFrame::Help)
+ EVT_MENU(UNDO, FortyFrame::Undo)
+ EVT_MENU(REDO, FortyFrame::Redo)
+ EVT_MENU(SCORES, FortyFrame::Scores)
+ EVT_MENU(RIGHT_BUTTON_UNDO, FortyFrame::ToggleRightButtonUndo)
+ EVT_MENU(HELPING_HAND, FortyFrame::ToggleHelpingHand)
+ EVT_MENU(LARGE_CARDS, FortyFrame::ToggleCardSize)
EVT_CLOSE(FortyFrame::OnCloseWindow)
END_EVENT_TABLE()
// Create a new application object
-IMPLEMENT_APP (FortyApp)
+IMPLEMENT_APP (FortyApp)
wxColour* FortyApp::m_backgroundColour = 0;
wxColour* FortyApp::m_textColour = 0;
bool FortyApp::OnInit()
{
- bool largecards = false;
+ bool largecards = false;
- wxSize size(668,510);
+ wxSize size(668,510);
- if ((argc > 1) && (!wxStrcmp(argv[1],_T("-L"))))
- {
- largecards = true;
- size = wxSize(1000,750);
- }
+ if ((argc > 1) && (!wxStrcmp(argv[1],_T("-L"))))
+ {
+ largecards = true;
+ size = wxSize(1000,750);
+ }
- FortyFrame* frame = new FortyFrame(
- 0,
- _T("Forty Thieves"),
- wxDefaultPosition,
- size,
- largecards
- );
+ FortyFrame* frame = new FortyFrame(
+ 0,
+ _T("Forty Thieves"),
+ wxDefaultPosition,
+ size,
+ largecards
+ );
- // Show the frame
- frame->Show(true);
+ // Show the frame
+ frame->Show(true);
- frame->GetCanvas()->ShowPlayerDialog();
+ frame->GetCanvas()->ShowPlayerDialog();
- return true;
+ return true;
}
const wxColour& FortyApp::BackgroundColour()
{
- if (!m_backgroundColour)
- {
- m_backgroundColour = new wxColour(0, 128, 0);
- }
+ if (!m_backgroundColour)
+ {
+ m_backgroundColour = new wxColour(0, 128, 0);
+ }
- return *m_backgroundColour;
+ return *m_backgroundColour;
}
const wxBrush& FortyApp::BackgroundBrush()
{
- if (!m_backgroundBrush)
- {
- m_backgroundBrush = new wxBrush(BackgroundColour(), wxSOLID);
- }
+ if (!m_backgroundBrush)
+ {
+ m_backgroundBrush = new wxBrush(BackgroundColour(), wxSOLID);
+ }
- return *m_backgroundBrush;
+ return *m_backgroundBrush;
}
const wxColour& FortyApp::TextColour()
{
- if (!m_textColour)
- {
- m_textColour = new wxColour(_T("BLACK"));
- }
+ if (!m_textColour)
+ {
+ m_textColour = new wxColour(_T("BLACK"));
+ }
- return *m_textColour;
+ return *m_textColour;
}
// My frame constructor
FortyFrame::FortyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos, const wxSize& size, bool largecards):
- wxFrame(frame, wxID_ANY, title, pos, size)
+ wxFrame(frame, wxID_ANY, title, pos, size)
{
#ifdef __WXMAC__
- wxApp::s_macAboutMenuItemId = wxID_ABOUT ;
+ wxApp::s_macAboutMenuItemId = wxID_ABOUT ;
#endif
- // set the icon
+ // set the icon
#ifdef __WXMSW__
- SetIcon(wxIcon(_T("CardsIcon")));
+ SetIcon(wxIcon(_T("CardsIcon")));
#else
#ifdef GTK_TBD
- SetIcon(wxIcon(Cards_bits, Cards_width, Cards_height));
+ SetIcon(wxIcon(Cards_bits, Cards_width, Cards_height));
#endif
#endif
- // Make a menu bar
- wxMenu* gameMenu = new wxMenu;
- gameMenu->Append(NEW_GAME, _T("&New"), _T("Start a new game"));
- gameMenu->Append(SCORES, _T("&Scores..."), _T("Displays scores"));
- gameMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exits Forty Thieves"));
-
- wxMenu* editMenu = new wxMenu;
- editMenu->Append(UNDO, _T("&Undo"), _T("Undo the last move"));
- editMenu->Append(REDO, _T("&Redo"), _T("Redo a move that has been undone"));
-
- wxMenu* optionsMenu = new wxMenu;
- optionsMenu->Append(RIGHT_BUTTON_UNDO,
- _T("&Right button undo"),
- _T("Enables/disables right mouse button undo and redo"),
- true
- );
- optionsMenu->Append(HELPING_HAND,
- _T("&Helping hand"),
- _T("Enables/disables hand cursor when a card can be moved"),
- true
- );
- optionsMenu->Append(LARGE_CARDS,
- _T("&Large cards"),
- _T("Enables/disables large cards for high resolution displays"),
- true
- );
- optionsMenu->Check(HELPING_HAND, true);
- optionsMenu->Check(RIGHT_BUTTON_UNDO, true);
- optionsMenu->Check(LARGE_CARDS, largecards ? true : false);
-
- wxMenu* helpMenu = new wxMenu;
- helpMenu->Append(wxID_HELP_CONTENTS, _T("&Help Contents"), _T("Displays information about playing the game"));
- helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About Forty Thieves"));
-
- m_menuBar = new wxMenuBar;
- m_menuBar->Append(gameMenu, _T("&Game"));
- m_menuBar->Append(editMenu, _T("&Edit"));
- m_menuBar->Append(optionsMenu, _T("&Options"));
- m_menuBar->Append(helpMenu, _T("&Help"));
-
- SetMenuBar(m_menuBar);
-
- if (largecards)
- Card::SetScale(1.3);
-
- m_canvas = new FortyCanvas(this, wxDefaultPosition, size);
-
- wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
- topsizer->Add( m_canvas, 1, wxEXPAND | wxALL, 0);
- SetSizer( topsizer );
- topsizer->SetSizeHints( this );
-
- CreateStatusBar();
+ // Make a menu bar
+ wxMenu* gameMenu = new wxMenu;
+ gameMenu->Append(NEW_GAME, _T("&New"), _T("Start a new game"));
+ gameMenu->Append(SCORES, _T("&Scores..."), _T("Displays scores"));
+ gameMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exits Forty Thieves"));
+
+ wxMenu* editMenu = new wxMenu;
+ editMenu->Append(UNDO, _T("&Undo"), _T("Undo the last move"));
+ editMenu->Append(REDO, _T("&Redo"), _T("Redo a move that has been undone"));
+
+ wxMenu* optionsMenu = new wxMenu;
+ optionsMenu->Append(RIGHT_BUTTON_UNDO,
+ _T("&Right button undo"),
+ _T("Enables/disables right mouse button undo and redo"),
+ true
+ );
+ optionsMenu->Append(HELPING_HAND,
+ _T("&Helping hand"),
+ _T("Enables/disables hand cursor when a card can be moved"),
+ true
+ );
+ optionsMenu->Append(LARGE_CARDS,
+ _T("&Large cards"),
+ _T("Enables/disables large cards for high resolution displays"),
+ true
+ );
+ optionsMenu->Check(HELPING_HAND, true);
+ optionsMenu->Check(RIGHT_BUTTON_UNDO, true);
+ optionsMenu->Check(LARGE_CARDS, largecards ? true : false);
+
+ wxMenu* helpMenu = new wxMenu;
+ helpMenu->Append(wxID_HELP_CONTENTS, _T("&Help Contents"), _T("Displays information about playing the game"));
+ helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About Forty Thieves"));
+
+ m_menuBar = new wxMenuBar;
+ m_menuBar->Append(gameMenu, _T("&Game"));
+ m_menuBar->Append(editMenu, _T("&Edit"));
+ m_menuBar->Append(optionsMenu, _T("&Options"));
+ m_menuBar->Append(helpMenu, _T("&Help"));
+
+ SetMenuBar(m_menuBar);
+
+ if (largecards)
+ Card::SetScale(1.3);
+
+ m_canvas = new FortyCanvas(this, wxDefaultPosition, size);
+
+ wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
+ topsizer->Add( m_canvas, 1, wxEXPAND | wxALL, 0);
+ SetSizer( topsizer );
+ topsizer->SetSizeHints( this );
+
+ CreateStatusBar();
}
FortyFrame::~FortyFrame()
void
FortyFrame::NewGame(wxCommandEvent&)
{
- m_canvas->NewGame();
+ m_canvas->NewGame();
}
void
FortyFrame::Exit(wxCommandEvent&)
{
- Close(true);
+ Close(true);
}
void
void
FortyFrame::Undo(wxCommandEvent&)
{
- m_canvas->Undo();
+ m_canvas->Undo();
}
void
FortyFrame::Redo(wxCommandEvent&)
{
- m_canvas->Redo();
+ m_canvas->Redo();
}
void
FortyFrame::Scores(wxCommandEvent&)
{
- m_canvas->UpdateScores();
- ScoreDialog scores(this, m_canvas->GetScoreFile());
- scores.Display();
+ m_canvas->UpdateScores();
+ ScoreDialog scores(this, m_canvas->GetScoreFile());
+ scores.Display();
}
void
FortyFrame::ToggleRightButtonUndo(wxCommandEvent& event)
{
- bool checked = m_menuBar->IsChecked(event.GetId());
- m_canvas->EnableRightButtonUndo(checked);
+ bool checked = m_menuBar->IsChecked(event.GetId());
+ m_canvas->EnableRightButtonUndo(checked);
}
void
FortyFrame::ToggleHelpingHand(wxCommandEvent& event)
{
- bool checked = m_menuBar->IsChecked(event.GetId());
- m_canvas->EnableHelpingHand(checked);
+ bool checked = m_menuBar->IsChecked(event.GetId());
+ m_canvas->EnableHelpingHand(checked);
}
void
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
-// Licence: wxWindows licence
+// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0
/////////////////////////////////////////////////////////////////////////////
public:
FortyApp();
~FortyApp();
- bool OnInit();
+ bool OnInit();
- static const wxColour& BackgroundColour();
- static const wxColour& TextColour();
- static const wxBrush& BackgroundBrush();
+ static const wxColour& BackgroundColour();
+ static const wxColour& TextColour();
+ static const wxBrush& BackgroundBrush();
private:
- static wxColour* m_backgroundColour;
- static wxColour* m_textColour;
- static wxBrush* m_backgroundBrush;
+ static wxColour* m_backgroundColour;
+ static wxColour* m_textColour;
+ static wxBrush* m_backgroundBrush;
};
class FortyCanvas;
{
public:
FortyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos, const wxSize& size, bool largecards);
- virtual ~FortyFrame();
+ virtual ~FortyFrame();
- void OnCloseWindow(wxCloseEvent& event);
+ void OnCloseWindow(wxCloseEvent& event);
- // Menu callbacks
- void NewGame(wxCommandEvent& event);
- void Exit(wxCommandEvent& event);
- void About(wxCommandEvent& event);
- void Help(wxCommandEvent& event);
- void Undo(wxCommandEvent& event);
- void Redo(wxCommandEvent& event);
- void Scores(wxCommandEvent& event);
- void ToggleRightButtonUndo(wxCommandEvent& event);
- void ToggleHelpingHand(wxCommandEvent& event);
- void ToggleCardSize(wxCommandEvent& event);
+ // Menu callbacks
+ void NewGame(wxCommandEvent& event);
+ void Exit(wxCommandEvent& event);
+ void About(wxCommandEvent& event);
+ void Help(wxCommandEvent& event);
+ void Undo(wxCommandEvent& event);
+ void Redo(wxCommandEvent& event);
+ void Scores(wxCommandEvent& event);
+ void ToggleRightButtonUndo(wxCommandEvent& event);
+ void ToggleHelpingHand(wxCommandEvent& event);
+ void ToggleCardSize(wxCommandEvent& event);
- FortyCanvas* GetCanvas() { return m_canvas; }
+ FortyCanvas* GetCanvas() { return m_canvas; }
- DECLARE_EVENT_TABLE()
+ DECLARE_EVENT_TABLE()
private:
- enum MenuCommands { NEW_GAME = 10, SCORES,
- UNDO, REDO,
- RIGHT_BUTTON_UNDO, HELPING_HAND, LARGE_CARDS
- };
+ enum MenuCommands {
+ NEW_GAME = 10,
+ SCORES,
+ UNDO,
+ REDO,
+ RIGHT_BUTTON_UNDO,
+ HELPING_HAND,
+ LARGE_CARDS
+ };
- wxMenuBar* m_menuBar;
- FortyCanvas* m_canvas;
+ wxMenuBar* m_menuBar;
+ FortyCanvas* m_canvas;
};
//----------------------------------------------------------------------------
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
-// Licence: wxWindows licence
+// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0
/////////////////////////////////////////////////////////////////////////////
#include "game.h"
Game::Game(int wins, int games, int score) :
- m_inPlay(false),
- m_moveIndex(0),
- m_redoIndex(0),
- m_bmap(0),
- m_bmapCard(0)
+ m_inPlay(false),
+ m_moveIndex(0),
+ m_redoIndex(0),
+ m_bmap(0),
+ m_bmapCard(0)
{
int i;
for (i = 0; i < 8; i++)
{
- m_foundations[i] = new Foundation(2 + (i / 4) * (CardWidth + 2),
- 2 + (i % 4) * (CardHeight + 2));
+ m_foundations[i] = new Foundation(2 + (i / 4) * (CardWidth + 2),
+ 2 + (i % 4) * (CardHeight + 2));
}
for (i = 0; i < 10; i++)
{
- m_bases[i] = new Base(8 + (i + 2) * (CardWidth + 2), 2);
+ m_bases[i] = new Base(8 + (i + 2) * (CardWidth + 2), 2);
}
Deal();
m_srcPile = 0;
m_liftedCard = 0;
- // copy the input parameters for future reference
+ // copy the input parameters for future reference
m_numWins = wins;
m_numGames = games;
m_totalScore = score;
delete m_discard;
for (i = 0; i < 8; i++)
{
- delete m_foundations[i];
+ delete m_foundations[i];
}
for (i = 0; i < 10; i++)
{
- delete m_bases[i];
+ delete m_bases[i];
}
- delete m_bmap;
- delete m_bmapCard;
+ delete m_bmap;
+ delete m_bmapCard;
}
/*
{
if (m_moveIndex > 0)
{
- m_moveIndex--;
- Card* card = m_moves[m_moveIndex].dest->RemoveTopCard(dc);
- m_moves[m_moveIndex].src->AddCard(dc, card);
- DisplayScore(dc);
+ m_moveIndex--;
+ Card* card = m_moves[m_moveIndex].dest->RemoveTopCard(dc);
+ m_moves[m_moveIndex].src->AddCard(dc, card);
+ DisplayScore(dc);
}
}
{
if (m_moveIndex < m_redoIndex)
{
- 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++;
+ 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++;
}
}
{
if (m_moveIndex < MaxMoves)
{
- 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++;
+ 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++;
- // when we do a move any moves in redo buffer are discarded
- m_redoIndex = m_moveIndex;
+ // when we do a move any moves in redo buffer are discarded
+ m_redoIndex = m_moveIndex;
}
else
{
- 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)
- {
- wxNode *node = (wxNode *)frame->GetChildren().GetFirst();
- 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);
- }
- }
+ 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)
+ {
+ wxNode *node = (wxNode *)frame->GetChildren().GetFirst();
+ 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);
+ }
+ }
}
void Game::DisplayScore(wxDC& dc)
{
wxColour bgColour = FortyApp::BackgroundColour();
- wxPen* pen = wxThePenList->FindOrCreatePen(bgColour, 1, wxSOLID);
+ wxPen* pen = wxThePenList->FindOrCreatePen(bgColour, 1, wxSOLID);
dc.SetTextBackground(bgColour);
dc.SetTextForeground(FortyApp::TextColour());
- dc.SetBrush(FortyApp::BackgroundBrush());
- dc.SetPen(* pen);
+ dc.SetBrush(FortyApp::BackgroundBrush());
+ dc.SetPen(* pen);
- // count the number of cards in foundations
+ // count the number of cards in foundations
m_currentScore = 0;
for (int i = 0; i < 8; i++)
{
- m_currentScore += m_foundations[i]->GetNumCards();
+ m_currentScore += m_foundations[i]->GetNumCards();
}
int x, y;
m_pack->GetTopCardPos(x, y);
x += 12 * CardWidth - 105;
- 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);
+ 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);
wxString str;
str.Printf(_T("%d"), m_currentScore);
y += h;
int average = 0;
- if (m_numGames > 0)
- {
- average = (2 * (m_currentScore + m_totalScore) + m_numGames ) / (2 * m_numGames);
- }
+ if (m_numGames > 0)
+ {
+ average = (2 * (m_currentScore + m_totalScore) + m_numGames ) / (2 * m_numGames);
+ }
str.Printf(_T("%d"), average);
dc.DrawText(_T("Average score:"), x, y);
dc.DrawText(str, x + w, y);
int i, j;
Card* card;
- // Reset all the piles, the undo buffer and shuffle the m_pack
+ // Reset all the piles, the undo buffer and shuffle the m_pack
m_moveIndex = 0;
m_pack->ResetPile();
for (i = 0; i < 5; i++)
- {
- m_pack->Shuffle();
- }
+ {
+ m_pack->Shuffle();
+ }
m_discard->ResetPile();
for (i = 0; i < 10; i++)
- {
- m_bases[i]->ResetPile();
- }
+ {
+ m_bases[i]->ResetPile();
+ }
for (i = 0; i < 8; i++)
- {
- m_foundations[i]->ResetPile();
- }
+ {
+ m_foundations[i]->ResetPile();
+ }
- // Deal the initial 40 cards onto the bases
+ // Deal the initial 40 cards onto the bases
for (i = 0; i < 10; i++)
{
- for (j = 1; j <= 4; j++)
- {
- card = m_pack->RemoveTopCard();
- card->TurnCard(faceup);
- m_bases[i]->AddCard(card);
- }
+ for (j = 1; j <= 4; j++)
+ {
+ card = m_pack->RemoveTopCard();
+ card->TurnCard(faceup);
+ m_bases[i]->AddCard(card);
+ }
}
if (m_inPlay)
- {
- // 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;
- }
+ {
+ // 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;
+ }
m_currentScore = 0;
m_inPlay = false;
}
// Redraw the m_pack, discard pile, the bases and the foundations
void Game::Redraw(wxDC& dc)
{
- 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);
+ 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);
memoryDC.SetPen( *wxTRANSPARENT_PEN );
- memoryDC.SetBrush(FortyApp::BackgroundBrush());
- memoryDC.DrawRectangle(0, 0, CardWidth, CardHeight);
- memoryDC.SelectObject(*m_bmap);
- memoryDC.DrawRectangle(0, 0, CardWidth, CardHeight);
- memoryDC.SelectObject(wxNullBitmap);
- }
+ memoryDC.SetBrush(FortyApp::BackgroundBrush());
+ memoryDC.DrawRectangle(0, 0, CardWidth, CardHeight);
+ memoryDC.SelectObject(*m_bmap);
+ memoryDC.DrawRectangle(0, 0, CardWidth, CardHeight);
+ memoryDC.SelectObject(wxNullBitmap);
+ }
}
// or the pile is empty
Pile* Game::WhichPile(int x, int y)
{
- 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;
+ 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;
}
m_srcPile = WhichPile(x, y);
if (m_srcPile == m_pack)
{
- 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);
- }
+ 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);
+ }
m_srcPile = 0;
}
else if (m_srcPile)
{
- 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);
- }
+ 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);
+ }
}
return m_srcPile != 0;
}
Pile* pile = WhichPile(x, y);
if (!pile) return;
- // Double click on m_pack is the same as left button down
+ // Double click on m_pack is the same as left button down
if (pile == m_pack)
{
- LButtonDown(dc, x, y);
+ LButtonDown(dc, x, y);
}
else
{
- Card* card = pile->GetTopCard();
+ Card* card = pile->GetTopCard();
- if (card)
- {
- int i;
+ if (card)
+ {
+ int i;
- // 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 )
+ // 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 )
{
- if (m_topCard->GetSuit() == card->GetSuit() &&
+ if (m_topCard->GetSuit() == card->GetSuit() &&
m_foundations[i + 4] != pile &&
- m_foundations[i + 4]->GetTopCard() == 0)
- {
- pile->RemoveTopCard(dc);
- m_foundations[i + 4]->AddCard(dc, card);
- DoMove(dc, pile, m_foundations[i + 4]);
- return;
- }
+ m_foundations[i + 4]->GetTopCard() == 0)
+ {
+ pile->RemoveTopCard(dc);
+ m_foundations[i + 4]->AddCard(dc, card);
+ DoMove(dc, pile, m_foundations[i + 4]);
+ return;
+ }
}
- }
- }
-
- // 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;
- }
+ }
}
- // 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;
- }
+
+ // 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;
+ }
}
- // 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;
- }
+ // 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;
+ }
}
- }
+ // 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;
+ }
+ }
+ }
}
}
if (m_discard->GetTopCard()) return false;
for(int i = 0; i < 10; i++)
{
- if (m_bases[i]->GetTopCard()) return false;
+ if (m_bases[i]->GetTopCard()) return false;
}
m_numWins++;
m_totalScore += m_currentScore;
Pile* pile = WhichPile(x, y);
if (pile && pile != m_pack)
{
- Card* card = pile->GetTopCard();
+ Card* card = pile->GetTopCard();
- if (card)
- {
- int i;
- for(i = 0; i < 8; i++)
- {
- if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile)
- {
+ if (card)
+ {
+ int i;
+ for(i = 0; i < 8; i++)
+ {
+ if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile)
+ {
return true;
- }
+ }
}
- for(i = 0; i < 10; i++)
- {
- if (m_bases[i]->GetTopCard() &&
- m_bases[i]->AcceptCard(card) &&
- m_bases[i] != pile)
- {
- return true;
- }
+ for(i = 0; i < 10; i++)
+ {
+ if (m_bases[i]->GetTopCard() &&
+ m_bases[i]->AcceptCard(card) &&
+ m_bases[i] != pile)
+ {
+ return true;
+ }
}
- }
+ }
}
return false;
}
{
if (m_srcPile)
{
- // work out the position of the dragged card
- x += m_xOffset;
+ // work out the position of the dragged card
+ x += m_xOffset;
y += m_yOffset;
- 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];
+ 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];
distance = nearestPile->CalcDistance(x, y);
}
}
- }
- for (i = 0; i < 10; i++)
- {
- if (DropCard(x, y, m_bases[i], m_liftedCard))
- {
- if (m_bases[i]->CalcDistance(x, y) < distance)
+ }
+ for (i = 0; i < 10; i++)
+ {
+ if (DropCard(x, y, m_bases[i], m_liftedCard))
+ {
+ if (m_bases[i]->CalcDistance(x, y) < distance)
{
- nearestPile = m_bases[i];
+ nearestPile = m_bases[i];
distance = nearestPile->CalcDistance(x, y);
}
}
- }
-
- // 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);
- }
- }
+ }
+
+ // 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);
+ }
+ }
else
{
- // Return card to src pile
- m_srcPile->AddCard(dc, m_liftedCard);
- }
- m_srcPile = 0;
- m_liftedCard = 0;
+ // Return card to src pile
+ m_srcPile->AddCard(dc, m_liftedCard);
+ }
+ m_srcPile = 0;
+ m_liftedCard = 0;
}
}
bool retval = false;
if (pile->Overlap(x, y))
{
- if (pile->AcceptCard(card))
- {
- retval = true;
+ if (pile->AcceptCard(card))
+ {
+ retval = true;
}
}
return retval;
{
if (m_liftedCard)
{
- wxMemoryDC memoryDC;
- memoryDC.SelectObject(*m_bmap);
+ wxMemoryDC memoryDC;
+ memoryDC.SelectObject(*m_bmap);
- int dx = mx + m_xOffset - m_xPos;
- int dy = my + m_yOffset - m_yPos;
+ int dx = mx + m_xOffset - m_xPos;
+ int dy = my + m_yOffset - m_yPos;
- if (abs(dx) >= CardWidth || abs(dy) >= CardHeight)
+ if (abs(dx) >= CardWidth || abs(dy) >= CardHeight)
{
- // 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);
+ // 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);
}
}
{
for (m_topCard = 0; m_topCard < NumCards; m_topCard++)
{
- m_cards[m_topCard] = new Card(1 + m_topCard / 2, facedown);
+ m_cards[m_topCard] = new Card(1 + m_topCard / 2, facedown);
}
m_topCard = NumCards - 1;
}
Card* temp[NumCards];
int i;
- // Don't try to shuffle an empty m_pack!
+ // Don't try to shuffle an empty m_pack!
if (m_topCard < 0) return;
- // 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.
+ // 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.
for (i = 0; i <= m_topCard; i++)
{
- temp[i] = 0;
+ temp[i] = 0;
}
for (i = 0; i <= m_topCard; i++)
{
- 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];
+ 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];
m_cards[i] = 0;
}
- // 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.
+ // 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.
for (i = 0; i <= m_topCard; i++)
{
- int pos = rand() % (m_topCard + 1);
- while (m_cards[pos])
- {
- pos++;
+ int pos = rand() % (m_topCard + 1);
+ while (m_cards[pos])
+ {
+ pos++;
if (pos > m_topCard) pos = 0;
- }
+ }
m_cards[pos] = temp[i];
}
}
str.Printf(_T("%d "), m_topCard + 1);
dc.SetBackgroundMode( wxSOLID );
- dc.SetTextBackground(FortyApp::BackgroundColour());
- dc.SetTextForeground(FortyApp::TextColour());
+ dc.SetTextBackground(FortyApp::BackgroundColour());
+ dc.SetTextForeground(FortyApp::TextColour());
dc.DrawText(str, m_x + CardWidth + 5, m_y + CardHeight / 2);
}
{
if (card == m_cards[m_topCard + 1])
{
- m_topCard++;
+ m_topCard++;
}
else
{
- wxMessageBox(_T("Pack::AddCard() Undo error"), _T("Forty Thieves: Warning"),
- wxOK | wxICON_EXCLAMATION);
+ wxMessageBox(_T("Pack::AddCard() Undo error"), _T("Forty Thieves: Warning"),
+ wxOK | wxICON_EXCLAMATION);
}
card->TurnCard(facedown);
}
{
for (m_topCard = 0; m_topCard < NumCards; m_topCard++)
{
- delete m_cards[m_topCard];
+ delete m_cards[m_topCard];
}
};
if (m_topCard >= 0)
{
- if (m_cards[m_topCard]->GetSuit() == card->GetSuit() &&
- m_cards[m_topCard]->GetPipValue() - 1 == card->GetPipValue())
- {
+ if (m_cards[m_topCard]->GetSuit() == card->GetSuit() &&
+ m_cards[m_topCard]->GetPipValue() - 1 == card->GetPipValue())
+ {
retval = true;
}
}
else
{
- // pile is empty - ACCEPT
+ // pile is empty - ACCEPT
retval = true;
}
return retval;
if (m_topCard >= 0)
{
- if (m_cards[m_topCard]->GetSuit() == card->GetSuit() &&
- m_cards[m_topCard]->GetPipValue() + 1 == card->GetPipValue())
- {
+ if (m_cards[m_topCard]->GetSuit() == card->GetSuit() &&
+ m_cards[m_topCard]->GetPipValue() + 1 == card->GetPipValue())
+ {
retval = true;
}
}
else if (card->GetPipValue() == 1)
{
- // It's an ace and the pile is empty - ACCEPT
+ // It's an ace and the pile is empty - ACCEPT
retval = true;
}
return retval;
{
if (m_topCard >= 0)
{
- if (m_dx == 0 && m_dy == 0)
- {
+ if (m_dx == 0 && m_dy == 0)
+ {
m_cards[m_topCard]->Draw(dc, m_x, m_y);
- }
- 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;
+ }
+ 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;
y = m_y + CardHeight / 3;
}
}
}
else
{
- Card::DrawNullCard(dc, m_x, m_y);
+ Card::DrawNullCard(dc, m_x, m_y);
}
}
{
if (m_topCard < 0)
{
- x = m_x;
- y = m_y;
+ x = m_x;
+ y = m_y;
}
else if (m_topCard > 31)
{
- x = m_x + m_dx * (m_topCard - 32);
- y = m_y + CardHeight / 3;
+ x = m_x + m_dx * (m_topCard - 32);
+ y = m_y + CardHeight / 3;
}
else
{
- x = m_x + m_dx * m_topCard;
- y = m_y;
+ x = m_x + m_dx * m_topCard;
+ y = m_y;
}
}
if (m_topCard <= 31)
{
- card = Pile::RemoveTopCard(dc, m_xOffset, m_yOffset);
+ card = Pile::RemoveTopCard(dc, m_xOffset, m_yOffset);
}
else
{
- 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();
+ 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();
}
return card;
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
-// Licence: wxWindows licence
+// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0
/////////////////////////////////////////////////////////////////////////////
//---------------------------------------//
class Pack : public Pile {
public:
- Pack(int x, int y);
- ~Pack();
- void Redraw(wxDC& dc);
- void ResetPile() { m_topCard = NumCards - 1; }
- void Shuffle();
- void AddCard(Card* card); // Add card
- void AddCard(wxDC& dc, Card* card) { AddCard(card); Redraw(dc); }
+ Pack(int x, int y);
+ ~Pack();
+ void Redraw(wxDC& dc);
+ void ResetPile() { m_topCard = NumCards - 1; }
+ void Shuffle();
+ void AddCard(Card* card); // Add card
+ void AddCard(wxDC& dc, Card* card) { AddCard(card); Redraw(dc); }
};
//----------------------------------------------------------//
class Base : public Pile {
public:
- Base(int x, int y);
- ~Base();
- bool AcceptCard(Card* card);
+ Base(int x, int y);
+ ~Base();
+ bool AcceptCard(Card* card);
};
//----------------------------------------------------//
class Foundation : public Pile {
public:
- Foundation(int x, int y);
- ~Foundation();
- bool AcceptCard(Card* card);
+ Foundation(int x, int y);
+ ~Foundation();
+ bool AcceptCard(Card* card);
};
//--------------------------------------//
class Discard : public Pile {
public:
- Discard(int x, int y);
- ~Discard();
- void Redraw(wxDC& dc);
- void GetTopCardPos(int& x, int& y);
- Card* RemoveTopCard(wxDC& dc, int m_xOffset, int m_yOffset);
+ Discard(int x, int y);
+ ~Discard();
+ void Redraw(wxDC& dc);
+ void GetTopCardPos(int& x, int& y);
+ Card* RemoveTopCard(wxDC& dc, int m_xOffset, int m_yOffset);
};
class Game {
public:
- Game(int wins, int games, int score);
- virtual ~Game();
+ Game(int wins, int games, int score);
+ virtual ~Game();
- void Layout();
- void NewPlayer(int wins, int games, int score);
- void Deal(); // Shuffle and deal a new game
- bool CanYouGo(int x, int y); // can card under (x,y) go somewhere?
- bool HaveYouWon(); // have you won the game?
+ void Layout();
+ void NewPlayer(int wins, int games, int score);
+ void Deal(); // Shuffle and deal a new game
+ bool CanYouGo(int x, int y); // can card under (x,y) go somewhere?
+ bool HaveYouWon(); // have you won the game?
- void Undo(wxDC& dc); // Undo the last go
- void Redo(wxDC& dc); // Redo the last go
+ void Undo(wxDC& dc); // Undo the last go
+ void Redo(wxDC& dc); // Redo the last go
- void Redraw(wxDC& dc);
- void DisplayScore(wxDC& dc);
- bool LButtonDown(wxDC& dc, int mx, int my); //
- void LButtonUp(wxDC& dc, int mx, int my);
- void LButtonDblClk(wxDC& dc, int mx, int my);
- void MouseMove(wxDC& dc, int mx, int my);
+ void Redraw(wxDC& dc);
+ void DisplayScore(wxDC& dc);
+ bool LButtonDown(wxDC& dc, int mx, int my);
+ void LButtonUp(wxDC& dc, int mx, int my);
+ void LButtonDblClk(wxDC& dc, int mx, int my);
+ void MouseMove(wxDC& dc, int mx, int my);
- int GetNumWins() const { return m_numWins; }
- int GetNumGames() const { return m_numGames; }
- int GetScore() const { return m_currentScore + m_totalScore; }
+ int GetNumWins() const { return m_numWins; }
+ int GetNumGames() const { return m_numGames; }
+ int GetScore() const { return m_currentScore + m_totalScore; }
- bool InPlay() const { return m_inPlay; }
+ bool InPlay() const { return m_inPlay; }
private:
- bool DropCard(int x, int y, Pile* pile, Card* card);
- // can the card at (x, y) be dropped on the pile?
- Pile* WhichPile(int x, int y); // which pile is (x, y) over?
- void DoMove(wxDC& dc, Pile* src, Pile* dest);
-
- bool m_inPlay; // flag indicating that the game has started
-
- // undo buffer
- struct {
- Pile* src;
- Pile* dest;
- } m_moves[MaxMoves];
- int m_moveIndex; // current position in undo/redo buffer
- int m_redoIndex; // max move index available for redo
-
- // the various piles of cards
- Pack* m_pack;
- Discard* m_discard;
- Base* m_bases[10];
- Foundation* m_foundations[8];
-
- // variables to do with dragging cards
- Pile* m_srcPile;
- Card* m_liftedCard;
- int m_xPos, m_yPos; // current coords of card being dragged
- int m_xOffset, m_yOffset; // card/mouse offset when dragging a card
-
- wxBitmap* m_bmap;
- wxBitmap* m_bmapCard;
-
- // variables to do with scoring
- int m_numGames;
- int m_numWins;
- int m_totalScore;
- int m_currentScore;
+ bool DropCard(int x, int y, Pile* pile, Card* card);
+ // can the card at (x, y) be dropped on the pile?
+ Pile* WhichPile(int x, int y); // which pile is (x, y) over?
+ void DoMove(wxDC& dc, Pile* src, Pile* dest);
+
+ bool m_inPlay; // flag indicating that the game has started
+
+ // undo buffer
+ struct {
+ Pile* src;
+ Pile* dest;
+ } m_moves[MaxMoves];
+ int m_moveIndex; // current position in undo/redo buffer
+ int m_redoIndex; // max move index available for redo
+
+ // the various piles of cards
+ Pack* m_pack;
+ Discard* m_discard;
+ Base* m_bases[10];
+ Foundation* m_foundations[8];
+
+ // variables to do with dragging cards
+ Pile* m_srcPile;
+ Card* m_liftedCard;
+ int m_xPos, m_yPos; // current coords of card being dragged
+ int m_xOffset, m_yOffset; // card/mouse offset when dragging a card
+
+ wxBitmap* m_bmap;
+ wxBitmap* m_bmapCard;
+
+ // variables to do with scoring
+ int m_numGames;
+ int m_numWins;
+ int m_totalScore;
+ int m_currentScore;
};
#endif // _GAME_H_
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
-// Licence: wxWindows licence
+// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0
/////////////////////////////////////////////////////////////////////////////
//+-------------------------------------------------------------+
-//| Description: |
-//| The base class for holding piles of playing cards. |
+//| Description: |
+//| The base class for holding piles of playing cards. |
//+-------------------------------------------------------------+
#ifdef __GNUG__
#include "wx/app.h"
//+-------------------------------------------------------------+
-//| Pile::Pile() |
+//| Pile::Pile() |
//+-------------------------------------------------------------+
-//| Description: |
-//| Initialise the pile to be empty of cards. |
+//| Description: |
+//| Initialise the pile to be empty of cards. |
//+-------------------------------------------------------------+
Pile::Pile(int x, int y, int dx, int dy)
{
m_dy = dy;
for (m_topCard = 0; m_topCard < NumCards; m_topCard++)
{
- m_cards[m_topCard] = 0;
+ m_cards[m_topCard] = 0;
}
- m_topCard = -1; // i.e. empty
+ m_topCard = -1; // i.e. empty
}
//+-------------------------------------------------------------+
-//| Pile::Redraw() |
+//| Pile::Redraw() |
//+-------------------------------------------------------------+
-//| Description: |
-//| Redraw the pile on the screen. If the pile is empty |
-//| just draw a NULL card as a place holder for the pile. |
-//| Otherwise draw the pile from the bottom up, starting |
-//| at the origin of the pile, shifting each subsequent |
-//| card by the pile's x and y offsets. |
+//| Description: |
+//| Redraw the pile on the screen. If the pile is empty |
+//| just draw a NULL card as a place holder for the pile. |
+//| Otherwise draw the pile from the bottom up, starting |
+//| at the origin of the pile, shifting each subsequent |
+//| card by the pile's x and y offsets. |
//+-------------------------------------------------------------+
void Pile::Redraw(wxDC& dc )
{
- FortyFrame *frame = (FortyFrame*) wxTheApp->GetTopWindow();
- wxWindow *canvas = (wxWindow *) NULL;
- if (frame)
- {
- canvas = frame->GetCanvas();
- }
-
- if (m_topCard >= 0)
- {
- if (m_dx == 0 && m_dy == 0)
- {
- if ((canvas) && (canvas->IsExposed(m_x,m_y,(int)(Card::GetScale()*60),(int)(Card::GetScale()*200))))
- m_cards[m_topCard]->Draw(dc, m_x, m_y);
- }
- else
- {
- int x = m_x;
- int y = m_y;
- for (int i = 0; i <= m_topCard; i++)
- {
- if ((canvas) && (canvas->IsExposed(x,y,(int)(Card::GetScale()*60),(int)(Card::GetScale()*200))))
- m_cards[i]->Draw(dc, x, y);
+ FortyFrame *frame = (FortyFrame*) wxTheApp->GetTopWindow();
+ wxWindow *canvas = (wxWindow *) NULL;
+ if (frame)
+ {
+ canvas = frame->GetCanvas();
+ }
+
+ if (m_topCard >= 0)
+ {
+ if (m_dx == 0 && m_dy == 0)
+ {
+ if ((canvas) && (canvas->IsExposed(m_x,m_y,(int)(Card::GetScale()*60),(int)(Card::GetScale()*200))))
+ m_cards[m_topCard]->Draw(dc, m_x, m_y);
+ }
+ else
+ {
+ int x = m_x;
+ int y = m_y;
+ for (int i = 0; i <= m_topCard; i++)
+ {
+ if ((canvas) && (canvas->IsExposed(x,y,(int)(Card::GetScale()*60),(int)(Card::GetScale()*200))))
+ m_cards[i]->Draw(dc, x, y);
x += (int)Card::GetScale()*m_dx;
y += (int)Card::GetScale()*m_dy;
- }
- }
- }
- else
- {
- if ((canvas) && (canvas->IsExposed(m_x,m_y,(int)(Card::GetScale()*60),(int)(Card::GetScale()*200))))
- Card::DrawNullCard(dc, m_x, m_y);
- }
+ }
+ }
+ }
+ else
+ {
+ if ((canvas) && (canvas->IsExposed(m_x,m_y,(int)(Card::GetScale()*60),(int)(Card::GetScale()*200))))
+ Card::DrawNullCard(dc, m_x, m_y);
+ }
}
//+-------------------------------------------------------------+
-//| Pile::GetTopCard() |
+//| Pile::GetTopCard() |
//+-------------------------------------------------------------+
-//| Description: |
-//| Return a pointer to the top card in the pile or NULL |
-//| if the pile is empty. |
-//| NB: Gets a copy of the card without removing it from the |
-//| pile. |
+//| Description: |
+//| Return a pointer to the top card in the pile or NULL |
+//| if the pile is empty. |
+//| NB: Gets a copy of the card without removing it from the |
+//| pile. |
//+-------------------------------------------------------------+
Card* Pile::GetTopCard()
{
if (m_topCard >= 0)
{
- card = m_cards[m_topCard];
+ card = m_cards[m_topCard];
}
return card;
}
//+-------------------------------------------------------------+
//| Pile::RemoveTopCard() |
//+-------------------------------------------------------------+
-//| Description: |
-//| If the pile is not empty, remove the top card from the |
-//| pile and return the pointer to the removed card. |
-//| If the pile is empty return a NULL pointer. |
+//| Description: |
+//| If the pile is not empty, remove the top card from the |
+//| pile and return the pointer to the removed card. |
+//| If the pile is empty return a NULL pointer. |
//+-------------------------------------------------------------+
Card* Pile::RemoveTopCard()
{
if (m_topCard >= 0)
{
- card = m_cards[m_topCard--];
+ card = m_cards[m_topCard--];
}
return card;
}
//+-------------------------------------------------------------+
//| Pile::RemoveTopCard() |
//+-------------------------------------------------------------+
-//| Description: |
-//| As RemoveTopCard() but also redraw the top of the pile |
-//| after the card has been removed. |
-//| NB: the offset allows for the redrawn area to be in a |
-//| bitmap ready for 'dragging' cards acrosss the screen. |
+//| Description: |
+//| As RemoveTopCard() but also redraw the top of the pile |
+//| after the card has been removed. |
+//| NB: the offset allows for the redrawn area to be in a |
+//| bitmap ready for 'dragging' cards acrosss the screen. |
//+-------------------------------------------------------------+
Card* Pile::RemoveTopCard(wxDC& dc, int xOffset, int yOffset)
{
- int topX, topY, x, y;
-
- GetTopCardPos(topX, topY);
- Card* card = RemoveTopCard();
-
- if (card)
- {
- card->Erase(dc, topX - xOffset, topY - yOffset);
- GetTopCardPos(x, y);
- if (m_topCard < 0)
- {
- Card::DrawNullCard(dc, x - xOffset, y - yOffset);
- }
- else
- {
- m_cards[m_topCard]->Draw(dc, x - xOffset, y - yOffset);
- }
- }
-
- return card;
+ int topX, topY, x, y;
+
+ GetTopCardPos(topX, topY);
+ Card* card = RemoveTopCard();
+
+ if (card)
+ {
+ card->Erase(dc, topX - xOffset, topY - yOffset);
+ GetTopCardPos(x, y);
+ if (m_topCard < 0)
+ {
+ Card::DrawNullCard(dc, x - xOffset, y - yOffset);
+ }
+ else
+ {
+ m_cards[m_topCard]->Draw(dc, x - xOffset, y - yOffset);
+ }
+ }
+
+ return card;
}
void Pile::GetTopCardPos(int& x, int& y)
{
- if (m_topCard < 0)
- {
- x = m_x;
- y = m_y;
- }
- else
- {
- x = m_x + (int)Card::GetScale()*m_dx * m_topCard;
- y = m_y + (int)Card::GetScale()*m_dy * m_topCard;
- }
+ if (m_topCard < 0)
+ {
+ x = m_x;
+ y = m_y;
+ }
+ else
+ {
+ x = m_x + (int)Card::GetScale()*m_dx * m_topCard;
+ y = m_y + (int)Card::GetScale()*m_dy * m_topCard;
+ }
}
void Pile::AddCard(Card* card)
{
for (int i = 0; i <= m_topCard; i++)
{
- if (card == m_cards[i]) return true;
+ if (card == m_cards[i]) return true;
}
return false;
}
// to the card, otherwise return NULL
Card* Pile::GetCard(int x, int y)
{
- int cardX;
- int cardY;
- GetTopCardPos(cardX, cardY);
-
- for (int i = m_topCard; i >= 0; i--)
- {
- if (x >= cardX && x <= cardX + Card::GetWidth() &&
- y >= cardY && y <= cardY + Card::GetHeight())
- {
- return m_cards[i];
- }
- cardX -= (int)Card::GetScale()*m_dx;
- cardY -= (int)Card::GetScale()*m_dy;
- }
- return 0;
+ int cardX;
+ int cardY;
+ GetTopCardPos(cardX, cardY);
+
+ for (int i = m_topCard; i >= 0; i--)
+ {
+ if (x >= cardX && x <= cardX + Card::GetWidth() &&
+ y >= cardY && y <= cardY + Card::GetHeight())
+ {
+ return m_cards[i];
+ }
+ cardX -= (int)Card::GetScale()*m_dx;
+ cardY -= (int)Card::GetScale()*m_dy;
+ }
+ return 0;
}
// return the origin of the pile.
void Pile::GetCardPos(Card* card, int& x, int& y)
{
- x = m_x;
- y = m_y;
-
- for (int i = 0; i <= m_topCard; i++)
- {
- if (card == m_cards[i])
- {
- return;
- }
- x += (int)Card::GetScale()*m_dx;
- y += (int)Card::GetScale()*m_dy;
- }
-
- // card not found in pile, return origin of pile
- x = m_x;
- y = m_y;
+ x = m_x;
+ y = m_y;
+
+ for (int i = 0; i <= m_topCard; i++)
+ {
+ if (card == m_cards[i])
+ {
+ return;
+ }
+ x += (int)Card::GetScale()*m_dx;
+ y += (int)Card::GetScale()*m_dy;
+ }
+
+ // card not found in pile, return origin of pile
+ x = m_x;
+ y = m_y;
}
if (x >= cardX - Card::GetWidth() && x <= cardX + Card::GetWidth() &&
y >= cardY - Card::GetHeight() && y <= cardY + Card::GetHeight())
{
- return true;
+ return true;
}
return false;
}
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
-// Licence: wxWindows licence
+// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0
/////////////////////////////////////////////////////////////////////////////
//+-------------------------------------------------------------+
-//| Description: |
-//| The base class for holding piles of playing cards. |
-//| This is the basic building block for card games. A pile |
-//| has a position on the screen and an offset for each |
-//| card placed on it e.g. a pack has no offset, but the |
-//| discard pile may be fanned out across the screen. |
-//| |
-//| The pile knows how to draw itself, though this may be |
-//| overridden if the default layout needs to be changed. |
-//| One or more cards can be removed from the top of a pile, |
-//| and single cards can be added to the top of a pile. |
-//| Functions are provided which redraw the screen when |
-//| cards are added or removed. |
-//| |
-//| Cards know which way up they are and how to draw |
-//| themselves. Piles are lists of cards. Piles know which |
-//| cards they contain and where they are to be drawn. |
+//| Description: |
+//| The base class for holding piles of playing cards. |
+//| This is the basic building block for card games. A pile |
+//| has a position on the screen and an offset for each |
+//| card placed on it e.g. a pack has no offset, but the |
+//| discard pile may be fanned out across the screen. |
+//| |
+//| The pile knows how to draw itself, though this may be |
+//| overridden if the default layout needs to be changed. |
+//| One or more cards can be removed from the top of a pile, |
+//| and single cards can be added to the top of a pile. |
+//| Functions are provided which redraw the screen when |
+//| cards are added or removed. |
+//| |
+//| Cards know which way up they are and how to draw |
+//| themselves. Piles are lists of cards. Piles know which |
+//| cards they contain and where they are to be drawn. |
//+-------------------------------------------------------------+
#ifndef _PILE_H_
#define _PILE_H_
//----------------------------------------------------------------//
class Pile {
public:
- Pile(int x, int y, int dx = 0, int dy = 0);
- virtual ~Pile();
+ Pile(int x, int y, int dx = 0, int dy = 0);
+ virtual ~Pile();
- // General functions
- virtual void ResetPile() { m_topCard = -1; }
- virtual void Redraw(wxDC& pDC);
+ // General functions
+ virtual void ResetPile() { m_topCard = -1; }
+ virtual void Redraw(wxDC& pDC);
- // Card query functions
- virtual Card* GetCard(int x, int y); // Get pointer to card at x, y
- Card* GetTopCard(); // Get pointer to top card
- virtual void GetCardPos(Card* card, int& x, int& y);
- // Get position of a card
- virtual void GetTopCardPos(int& x, int& y);
- // Get position of the top card
- int GetNumCards() { return m_topCard + 1; } // Number of cards in pile
- bool Overlap(int x, int y); // does card at x,y overlap the pile?
- int CalcDistance(int x, int y); // calculates the square of the distance
- // of a card at (x,y) from the top of the pile
+ // Card query functions
+ virtual Card* GetCard(int x, int y); // Get pointer to card at x, y
+ Card* GetTopCard(); // Get pointer to top card
+ virtual void GetCardPos(Card* card, int& x, int& y);
+ // Get position of a card
+ virtual void GetTopCardPos(int& x, int& y);
+ // Get position of the top card
+ int GetNumCards() { return m_topCard + 1; } // Number of cards in pile
+ bool Overlap(int x, int y); // does card at x,y overlap the pile?
+ int CalcDistance(int x, int y); // calculates the square of the distance
+ // of a card at (x,y) from the top of the pile
- // Functions removing one or more cards from the top of a pile
- virtual bool CanCardLeave(Card* card);
- Card* RemoveTopCard();
- virtual Card* RemoveTopCard(wxDC& pDC, int xOffset = 0, int yOffset = 0);
+ // Functions removing one or more cards from the top of a pile
+ virtual bool CanCardLeave(Card* card);
+ Card* RemoveTopCard();
+ virtual Card* RemoveTopCard(wxDC& pDC, int xOffset = 0, int yOffset = 0);
- // Functions to add a card to the top of a pile
- virtual bool AcceptCard(Card*) { return false; }
- virtual void AddCard(Card* card); // Add card to top of pile
- virtual void AddCard(wxDC& pDC, Card* card); // Add card + redraw it
+ // Functions to add a card to the top of a pile
+ virtual bool AcceptCard(Card*) { return false; }
+ virtual void AddCard(Card* card); // Add card to top of pile
+ virtual void AddCard(wxDC& pDC, Card* card); // Add card + redraw it
void SetPos(int x,int y) {m_x = x;m_y = y;};
protected:
- int m_x, m_y; // Position of the pile on the screen
- int m_dx, m_dy; // Offset when drawing the pile
- Card* m_cards[NumCards]; // Array of cards in this pile
- int m_topCard; // Array index of the top card
+ int m_x, m_y; // Position of the pile on the screen
+ int m_dx, m_dy; // Offset when drawing the pile
+ Card* m_cards[NumCards]; // Array of cards in this pile
+ int m_topCard; // Array index of the top card
};
#endif // _PILE_H_
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
-// Licence: wxWindows licence
+// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0
/////////////////////////////////////////////////////////////////////////////
class PlayerSelectionDialog : public wxDialog
{
public:
- PlayerSelectionDialog(wxWindow* parent, ScoreFile* file);
- virtual ~PlayerSelectionDialog();
+ PlayerSelectionDialog(wxWindow* parent, ScoreFile* file);
+ virtual ~PlayerSelectionDialog();
- const wxString& GetPlayersName();
- void ButtonCallback(wxCommandEvent& event);
- void SelectCallback(wxCommandEvent& event);
- void OnSize(wxSizeEvent& event);
+ const wxString& GetPlayersName();
+ void ButtonCallback(wxCommandEvent& event);
+ void SelectCallback(wxCommandEvent& event);
+ void OnSize(wxSizeEvent& event);
- DECLARE_EVENT_TABLE()
+ DECLARE_EVENT_TABLE()
protected:
- friend void SelectCallback(wxListBox&, wxCommandEvent&);
- void OnCloseWindow(wxCloseEvent& event);
+ friend void SelectCallback(wxListBox&, wxCommandEvent&);
+ void OnCloseWindow(wxCloseEvent& event);
private:
- ScoreFile* m_scoreFile;
- wxString m_player;
- wxButton* m_OK;
- wxButton* m_cancel;
- wxTextCtrl* m_textField;
+ ScoreFile* m_scoreFile;
+ wxString m_player;
+ wxButton* m_OK;
+ wxButton* m_cancel;
+ wxTextCtrl* m_textField;
};
#endif
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
-// Licence: wxWindows licence
+// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0
/////////////////////////////////////////////////////////////////////////////
class ScoreDialog : public wxDialog
{
public:
- ScoreDialog(wxWindow* parent, ScoreFile* file);
- virtual ~ScoreDialog();
+ ScoreDialog(wxWindow* parent, ScoreFile* file);
+ virtual ~ScoreDialog();
- void Display();
+ void Display();
protected:
- void OnCloseWindow(wxCloseEvent& event);
+ void OnCloseWindow(wxCloseEvent& event);
private:
- ScoreFile* m_scoreFile;
- wxButton* m_OK;
+ ScoreFile* m_scoreFile;
+ wxButton* m_OK;
DECLARE_EVENT_TABLE()
};
// Created: 21/07/97
// RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze
-// Licence: wxWindows licence
+// Licence: wxWindows licence
//---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0
/////////////////////////////////////////////////////////////////////////////
class ScoreFile {
public:
- ScoreFile(const wxString& appName);
- virtual ~ScoreFile();
+ ScoreFile(const wxString& appName);
+ virtual ~ScoreFile();
- void GetPlayerList( wxArrayString &list );
- wxString GetPreviousPlayer() const;
+ void GetPlayerList( wxArrayString &list );
+ wxString GetPreviousPlayer() const;
- void ReadPlayersScore(const wxString& player, int& wins, int& games, int &score);
- void WritePlayersScore(const wxString& player, int wins, int games, int score);
+ void ReadPlayersScore(const wxString& player, int& wins, int& games, int &score);
+ void WritePlayersScore(const wxString& player, int wins, int games, int score);
private:
- long CalcCheck(const wxString& name, int p1, int p2, int p3);
- wxString m_configFilename;
- wxConfig* m_config;
+ long CalcCheck(const wxString& name, int p1, int p2, int p3);
+ wxString m_configFilename;
+ wxConfig* m_config;
};
#endif