Removed tabs.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27580 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Włodzimierz Skiba 2004-06-02 09:14:59 +00:00
parent 5c6e85adcf
commit 010216e3bc
13 changed files with 1525 additions and 1346 deletions

View File

@ -6,7 +6,7 @@
// Created: 21/07/97 // Created: 21/07/97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze // Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence // Licence: wxWindows licence
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0 // Last modified: 22nd July 1998 - ported to wxWidgets 2.0
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -39,35 +39,35 @@ BEGIN_EVENT_TABLE(FortyCanvas, wxScrolledWindow)
END_EVENT_TABLE() END_EVENT_TABLE()
FortyCanvas::FortyCanvas(wxWindow* parent, const wxPoint& pos, const wxSize& size) : FortyCanvas::FortyCanvas(wxWindow* parent, const wxPoint& pos, const wxSize& size) :
wxScrolledWindow(parent, wxID_ANY, pos, size), wxScrolledWindow(parent, wxID_ANY, pos, size),
m_helpingHand(true), m_helpingHand(true),
m_rightBtnUndo(true), m_rightBtnUndo(true),
m_playerDialog(0), m_playerDialog(0),
m_leftBtnDown(false) m_leftBtnDown(false)
{ {
#ifdef __WXGTK__ #ifdef __WXGTK__
m_font = wxTheFontList->FindOrCreateFont(12, wxROMAN, wxNORMAL, wxNORMAL); m_font = wxTheFontList->FindOrCreateFont(12, wxROMAN, wxNORMAL, wxNORMAL);
#else #else
m_font = wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxNORMAL); m_font = wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxNORMAL);
#endif #endif
SetBackgroundColour(FortyApp::BackgroundColour()); SetBackgroundColour(FortyApp::BackgroundColour());
m_handCursor = new wxCursor(wxCURSOR_HAND); m_handCursor = new wxCursor(wxCURSOR_HAND);
m_arrowCursor = new wxCursor(wxCURSOR_ARROW); m_arrowCursor = new wxCursor(wxCURSOR_ARROW);
wxString name = wxTheApp->GetAppName(); wxString name = wxTheApp->GetAppName();
if (name.Length() <= 0) name = _T("forty"); if (name.Length() <= 0) name = _T("forty");
m_scoreFile = new ScoreFile(name); m_scoreFile = new ScoreFile(name);
m_game = new Game(0, 0, 0); m_game = new Game(0, 0, 0);
m_game->Deal(); m_game->Deal();
} }
FortyCanvas::~FortyCanvas() FortyCanvas::~FortyCanvas()
{ {
UpdateScores(); UpdateScores();
delete m_game; delete m_game;
delete m_scoreFile; delete m_scoreFile;
delete m_handCursor; delete m_handCursor;
delete m_arrowCursor; delete m_arrowCursor;
} }
@ -78,79 +78,79 @@ Write the current player's score back to the score file
*/ */
void FortyCanvas::UpdateScores() void FortyCanvas::UpdateScores()
{ {
if (m_player.Length() > 0 && m_scoreFile && m_game) if (m_player.Length() > 0 && m_scoreFile && m_game)
{ {
m_scoreFile->WritePlayersScore( m_scoreFile->WritePlayersScore(
m_player, m_player,
m_game->GetNumWins(), m_game->GetNumWins(),
m_game->GetNumGames(), m_game->GetNumGames(),
m_game->GetScore() m_game->GetScore()
); );
} }
} }
void FortyCanvas::OnDraw(wxDC& dc) void FortyCanvas::OnDraw(wxDC& dc)
{ {
dc.SetFont(* m_font); dc.SetFont(* m_font);
m_game->Redraw(dc); m_game->Redraw(dc);
#if 0 #if 0
// if player name not set (and selection dialog is not displayed) // if player name not set (and selection dialog is not displayed)
// then ask the player for their name // then ask the player for their name
if (m_player.Length() == 0 && !m_playerDialog) if (m_player.Length() == 0 && !m_playerDialog)
{ {
m_playerDialog = new PlayerSelectionDialog(this, m_scoreFile); m_playerDialog = new PlayerSelectionDialog(this, m_scoreFile);
m_playerDialog->ShowModal(); m_playerDialog->ShowModal();
m_player = m_playerDialog->GetPlayersName(); m_player = m_playerDialog->GetPlayersName();
if (m_player.Length() > 0) if (m_player.Length() > 0)
{ {
// user entered a name - lookup their score // user entered a name - lookup their score
int wins, games, score; int wins, games, score;
m_scoreFile->ReadPlayersScore(m_player, wins, games, score); m_scoreFile->ReadPlayersScore(m_player, wins, games, score);
m_game->NewPlayer(wins, games, score); m_game->NewPlayer(wins, games, score);
m_game->DisplayScore(dc); m_game->DisplayScore(dc);
m_playerDialog->Destroy(); m_playerDialog->Destroy();
m_playerDialog = 0; m_playerDialog = 0;
Refresh(false); Refresh(false);
} }
else else
{ {
// user cancelled the dialog - exit the app // user cancelled the dialog - exit the app
((wxFrame*)GetParent())->Close(true); ((wxFrame*)GetParent())->Close(true);
} }
} }
#endif #endif
} }
void FortyCanvas::ShowPlayerDialog() void FortyCanvas::ShowPlayerDialog()
{ {
// if player name not set (and selection dialog is not displayed) // if player name not set (and selection dialog is not displayed)
// then ask the player for their name // then ask the player for their name
if (m_player.Length() == 0 && !m_playerDialog) if (m_player.Length() == 0 && !m_playerDialog)
{ {
m_playerDialog = new PlayerSelectionDialog(this, m_scoreFile); m_playerDialog = new PlayerSelectionDialog(this, m_scoreFile);
m_playerDialog->ShowModal(); m_playerDialog->ShowModal();
m_player = m_playerDialog->GetPlayersName(); m_player = m_playerDialog->GetPlayersName();
if (m_player.Length() > 0) if (m_player.Length() > 0)
{ {
// user entered a name - lookup their score // user entered a name - lookup their score
int wins, games, score; int wins, games, score;
m_scoreFile->ReadPlayersScore(m_player, wins, games, score); m_scoreFile->ReadPlayersScore(m_player, wins, games, score);
m_game->NewPlayer(wins, games, score); m_game->NewPlayer(wins, games, score);
wxClientDC dc(this); wxClientDC dc(this);
dc.SetFont(* m_font); dc.SetFont(* m_font);
m_game->DisplayScore(dc); m_game->DisplayScore(dc);
m_playerDialog->Destroy(); m_playerDialog->Destroy();
m_playerDialog = 0; m_playerDialog = 0;
Refresh(false); Refresh(false);
}
else
{
// user cancelled the dialog - exit the app
((wxFrame*)GetParent())->Close(true);
}
} }
else
{
// user cancelled the dialog - exit the app
((wxFrame*)GetParent())->Close(true);
}
}
} }
/* /*
@ -158,113 +158,113 @@ Called when the main frame is closed
*/ */
bool FortyCanvas::OnCloseCanvas() bool FortyCanvas::OnCloseCanvas()
{ {
if (m_game->InPlay() && if (m_game->InPlay() &&
wxMessageBox(_T("Are you sure you want to\nabandon the current game?"), wxMessageBox(_T("Are you sure you want to\nabandon the current game?"),
_T("Warning"), wxYES_NO | wxICON_QUESTION) == wxNO) _T("Warning"), wxYES_NO | wxICON_QUESTION) == wxNO)
{ {
return false; return false;
} }
return true; return true;
} }
void FortyCanvas::OnMouseEvent(wxMouseEvent& event) void FortyCanvas::OnMouseEvent(wxMouseEvent& event)
{ {
int mouseX = (int)event.GetX(); int mouseX = (int)event.GetX();
int mouseY = (int)event.GetY(); int mouseY = (int)event.GetY();
wxClientDC dc(this); wxClientDC dc(this);
PrepareDC(dc); PrepareDC(dc);
dc.SetFont(* m_font); dc.SetFont(* m_font);
if (event.LeftDClick()) if (event.LeftDClick())
{ {
if (m_leftBtnDown) if (m_leftBtnDown)
{ {
m_leftBtnDown = false; m_leftBtnDown = false;
ReleaseMouse(); ReleaseMouse();
m_game->LButtonUp(dc, mouseX, mouseY); m_game->LButtonUp(dc, mouseX, mouseY);
} }
m_game->LButtonDblClk(dc, mouseX, mouseY); m_game->LButtonDblClk(dc, mouseX, mouseY);
} }
else if (event.LeftDown()) else if (event.LeftDown())
{ {
if (!m_leftBtnDown) if (!m_leftBtnDown)
{ {
m_leftBtnDown = true; m_leftBtnDown = true;
CaptureMouse(); CaptureMouse();
m_game->LButtonDown(dc, mouseX, mouseY); m_game->LButtonDown(dc, mouseX, mouseY);
} }
} }
else if (event.LeftUp()) else if (event.LeftUp())
{ {
if (m_leftBtnDown) if (m_leftBtnDown)
{ {
m_leftBtnDown = false; m_leftBtnDown = false;
ReleaseMouse(); ReleaseMouse();
m_game->LButtonUp(dc, mouseX, mouseY); m_game->LButtonUp(dc, mouseX, mouseY);
} }
} }
else if (event.RightDown() && !event.LeftIsDown()) else if (event.RightDown() && !event.LeftIsDown())
{ {
// only allow right button undo if m_rightBtnUndo is true // only allow right button undo if m_rightBtnUndo is true
if (m_rightBtnUndo) if (m_rightBtnUndo)
{ {
if (event.ControlDown() || event.ShiftDown()) if (event.ControlDown() || event.ShiftDown())
{ {
m_game->Redo(dc); m_game->Redo(dc);
} }
else else
{ {
m_game->Undo(dc); m_game->Undo(dc);
} }
} }
} }
else if (event.Dragging()) else if (event.Dragging())
{ {
m_game->MouseMove(dc, mouseX, mouseY); m_game->MouseMove(dc, mouseX, mouseY);
} }
if (!event.LeftIsDown()) if (!event.LeftIsDown())
{ {
SetCursorStyle(mouseX, mouseY); SetCursorStyle(mouseX, mouseY);
} }
} }
void FortyCanvas::SetCursorStyle(int x, int y) void FortyCanvas::SetCursorStyle(int x, int y)
{ {
// Only set cursor to a hand if 'helping hand' is enabled and // Only set cursor to a hand if 'helping hand' is enabled and
// the card under the cursor can go somewhere // the card under the cursor can go somewhere
if (m_game->CanYouGo(x, y) && m_helpingHand) if (m_game->CanYouGo(x, y) && m_helpingHand)
{ {
SetCursor(* m_handCursor); SetCursor(* m_handCursor);
} }
else else
{ {
SetCursor(* m_arrowCursor); SetCursor(* m_arrowCursor);
} }
} }
void FortyCanvas::NewGame() void FortyCanvas::NewGame()
{ {
m_game->Deal(); m_game->Deal();
Refresh(); Refresh();
} }
void FortyCanvas::Undo() void FortyCanvas::Undo()
{ {
wxClientDC dc(this); wxClientDC dc(this);
PrepareDC(dc); PrepareDC(dc);
dc.SetFont(* m_font); dc.SetFont(* m_font);
m_game->Undo(dc); m_game->Undo(dc);
} }
void FortyCanvas::Redo() void FortyCanvas::Redo()
{ {
wxClientDC dc(this); wxClientDC dc(this);
PrepareDC(dc); PrepareDC(dc);
dc.SetFont(* m_font); dc.SetFont(* m_font);
m_game->Redo(dc); m_game->Redo(dc);
} }
void FortyCanvas::LayoutGame() void FortyCanvas::LayoutGame()

View File

@ -6,7 +6,7 @@
// Created: 21/07/97 // Created: 21/07/97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze // Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence // Licence: wxWindows licence
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0 // Last modified: 22nd July 1998 - ported to wxWidgets 2.0
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -21,38 +21,38 @@ class PlayerSelectionDialog;
class FortyCanvas: public wxScrolledWindow class FortyCanvas: public wxScrolledWindow
{ {
public: public:
FortyCanvas(wxWindow* parent, const wxPoint& pos, const wxSize& size); FortyCanvas(wxWindow* parent, const wxPoint& pos, const wxSize& size);
virtual ~FortyCanvas(); virtual ~FortyCanvas();
virtual void OnDraw(wxDC& dc); virtual void OnDraw(wxDC& dc);
bool OnCloseCanvas(); bool OnCloseCanvas();
void OnMouseEvent(wxMouseEvent& event); void OnMouseEvent(wxMouseEvent& event);
void SetCursorStyle(int x, int y); void SetCursorStyle(int x, int y);
void NewGame(); void NewGame();
void Undo(); void Undo();
void Redo(); void Redo();
ScoreFile* GetScoreFile() const { return m_scoreFile; } ScoreFile* GetScoreFile() const { return m_scoreFile; }
void UpdateScores(); void UpdateScores();
void EnableHelpingHand(bool enable) { m_helpingHand = enable; } void EnableHelpingHand(bool enable) { m_helpingHand = enable; }
void EnableRightButtonUndo(bool enable) { m_rightBtnUndo = enable; } void EnableRightButtonUndo(bool enable) { m_rightBtnUndo = enable; }
void LayoutGame(); void LayoutGame();
void ShowPlayerDialog(); void ShowPlayerDialog();
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
private: private:
wxFont* m_font; wxFont* m_font;
Game* m_game; Game* m_game;
ScoreFile* m_scoreFile; ScoreFile* m_scoreFile;
wxCursor* m_arrowCursor; wxCursor* m_arrowCursor;
wxCursor* m_handCursor; wxCursor* m_handCursor;
bool m_helpingHand; bool m_helpingHand;
bool m_rightBtnUndo; bool m_rightBtnUndo;
wxString m_player; wxString m_player;
PlayerSelectionDialog* m_playerDialog; PlayerSelectionDialog* m_playerDialog;
bool m_leftBtnDown; bool m_leftBtnDown;
}; };
#endif #endif

View File

@ -6,17 +6,17 @@
// Created: 21/07/97 // Created: 21/07/97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze // Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence // Licence: wxWindows licence
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0 // Last modified: 22nd July 1998 - ported to wxWidgets 2.0
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Description //| Description
//| A class for drawing playing cards. //| A class for drawing playing cards.
//| Currently assumes that the card symbols have been //| Currently assumes that the card symbols have been
//| loaded into hbmap_symbols and the pictures for the //| loaded into hbmap_symbols and the pictures for the
//| Jack, Queen and King have been loaded into //| Jack, Queen and King have been loaded into
//| hbmap_pictures. //| hbmap_pictures.
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
#ifdef __GNUG__ #ifdef __GNUG__
@ -54,64 +54,64 @@ int Card::m_width = 50;
int Card::m_height = 70; int Card::m_height = 70;
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Card::Card() | //| Card::Card() |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Description: | //| Description: |
//| Constructor for a playing card. | //| Constructor for a playing card. |
//| Checks that the value is in the range 1..52 and then | //| Checks that the value is in the range 1..52 and then |
//| initialises the suit, colour, pipValue and wayUp. | //| initialises the suit, colour, pipValue and wayUp. |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
Card::Card(int value, WayUp way_up) : Card::Card(int value, WayUp way_up) :
m_wayUp(way_up) m_wayUp(way_up)
{ {
if (!m_symbolBmap) if (!m_symbolBmap)
{ {
#ifdef __WXMSW__ #ifdef __WXMSW__
m_symbolBmap = new wxBitmap(_T("CardSymbols"), wxBITMAP_TYPE_BMP_RESOURCE); m_symbolBmap = new wxBitmap(_T("CardSymbols"), wxBITMAP_TYPE_BMP_RESOURCE);
#else #else
m_symbolBmap = new wxBitmap(Symbols_bits, Symbols_width, Symbols_height); m_symbolBmap = new wxBitmap(Symbols_bits, Symbols_width, Symbols_height);
#endif #endif
if (!m_symbolBmap->Ok()) if (!m_symbolBmap->Ok())
{ {
::wxMessageBox(_T("Failed to load bitmap CardSymbols"), _T("Error")); ::wxMessageBox(_T("Failed to load bitmap CardSymbols"), _T("Error"));
} }
} }
if (!m_pictureBmap) if (!m_pictureBmap)
{ {
#ifdef __WXMSW__ #ifdef __WXMSW__
m_pictureBmap = new wxBitmap(_T("CardPictures"), wxBITMAP_TYPE_BMP_RESOURCE); m_pictureBmap = new wxBitmap(_T("CardPictures"), wxBITMAP_TYPE_BMP_RESOURCE);
#else #else
m_pictureBmap = new wxBitmap(Pictures); m_pictureBmap = new wxBitmap(Pictures);
#endif #endif
if (!m_pictureBmap->Ok()) if (!m_pictureBmap->Ok())
{ {
::wxMessageBox(_T("Failed to load bitmap CardPictures"), _T("Error")); ::wxMessageBox(_T("Failed to load bitmap CardPictures"), _T("Error"));
} }
} }
if (value >= 1 && value <= PackSize) if (value >= 1 && value <= PackSize)
{ {
switch ((value - 1) / 13) switch ((value - 1) / 13)
{ {
case 0: case 0:
m_suit = clubs; m_suit = clubs;
m_colour = black; m_colour = black;
break; break;
case 1: case 1:
m_suit = diamonds; m_suit = diamonds;
m_colour = red; m_colour = red;
break; break;
case 2: case 2:
m_suit = hearts; m_suit = hearts;
m_colour = red; m_colour = red;
break; break;
case 3: case 3:
m_suit = spades; m_suit = spades;
m_colour = black; m_colour = black;
break; break;
} }
m_pipValue = 1 + (value - 1) % 13; m_pipValue = 1 + (value - 1) % 13;
m_status = true; m_status = true;
} }
else else
{ {
@ -121,10 +121,10 @@ Card::Card(int value, WayUp way_up) :
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Card::SetScale() | //| Card::SetScale() |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Description: | //| Description: |
//| Scales the cards | //| Scales the cards |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
void Card::SetScale(double scale) void Card::SetScale(double scale)
{ {
@ -134,10 +134,10 @@ void Card::SetScale(double scale)
} }
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Card::~Card() | //| Card::~Card() |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Description: | //| Description: |
//| Destructor - nothing to do at present. | //| Destructor - nothing to do at present. |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
Card::~Card() Card::~Card()
{ {
@ -145,262 +145,436 @@ Card::~Card()
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Card::Erase() | //| Card::Erase() |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Description: | //| Description: |
//| Erase the card at (x, y) by drawing a rectangle in the | //| Erase the card at (x, y) by drawing a rectangle in the |
//| background colour. | //| background colour. |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
void Card::Erase(wxDC& dc, int x, int y) void Card::Erase(wxDC& dc, int x, int y)
{ {
wxPen* pen = wxThePenList->FindOrCreatePen( wxPen* pen = wxThePenList->FindOrCreatePen(
FortyApp::BackgroundColour(), FortyApp::BackgroundColour(),
1, 1,
wxSOLID wxSOLID
); );
dc.SetPen(* pen); dc.SetPen(* pen);
dc.SetBrush(FortyApp::BackgroundBrush()); dc.SetBrush(FortyApp::BackgroundBrush());
dc.DrawRectangle(x, y, m_width, m_height); dc.DrawRectangle(x, y, m_width, m_height);
} // Card::Erase() } // Card::Erase()
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Card::Draw() | //| Card::Draw() |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Description: | //| Description: |
//| Draw the card at (x, y). | //| Draw the card at (x, y). |
//| If the card is facedown draw the back of the card. | //| If the card is facedown draw the back of the card. |
//| If the card is faceup draw the front of the card. | //| If the card is faceup draw the front of the card. |
//| Cards are not held in bitmaps, instead they are drawn | //| Cards are not held in bitmaps, instead they are drawn |
//| from their constituent parts when required. | //| from their constituent parts when required. |
//| hbmap_symbols contains large and small suit symbols and | //| hbmap_symbols contains large and small suit symbols and |
//| pip values. These are copied to the appropriate part of | //| pip values. These are copied to the appropriate part of |
//| the card. Picture cards use the pictures defined in | //| the card. Picture cards use the pictures defined in |
//| hbmap_pictures. Note that only one picture is defined | //| hbmap_pictures. Note that only one picture is defined |
//| for the Jack, Queen and King, unlike a real pack where | //| for the Jack, Queen and King, unlike a real pack where |
//| each suit is different. | //| each suit is different. |
//| | //| |
//| WARNING: | //| WARNING: |
//| The locations of these symbols is 'hard-wired' into the | //| The locations of these symbols is 'hard-wired' into the |
//| code. Editing the bitmaps or the numbers below will | //| code. Editing the bitmaps or the numbers below will |
//| result in the wrong symbols being displayed. | //| result in the wrong symbols being displayed. |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
void Card::Draw(wxDC& dc, int x, int y) void Card::Draw(wxDC& dc, int x, int y)
{ {
wxBrush backgroundBrush( dc.GetBackground() ); wxBrush backgroundBrush( dc.GetBackground() );
dc.SetBrush(* wxWHITE_BRUSH); dc.SetBrush(* wxWHITE_BRUSH);
dc.SetPen(* wxBLACK_PEN); dc.SetPen(* wxBLACK_PEN);
dc.DrawRoundedRectangle(x, y, m_width, m_height, 4); dc.DrawRoundedRectangle(x, y, m_width, m_height, 4);
if (m_wayUp == facedown) if (m_wayUp == facedown)
{ {
dc.SetBackground(* wxRED_BRUSH); dc.SetBackground(* wxRED_BRUSH);
dc.SetBackgroundMode(wxSOLID); dc.SetBackgroundMode(wxSOLID);
wxBrush* brush = wxTheBrushList->FindOrCreateBrush( wxBrush* brush = wxTheBrushList->FindOrCreateBrush(
_T("BLACK"), wxCROSSDIAG_HATCH _T("BLACK"), wxCROSSDIAG_HATCH
); );
dc.SetBrush(* brush); dc.SetBrush(* brush);
dc.DrawRoundedRectangle( dc.DrawRoundedRectangle(
x + 4, y + 4, x + 4, y + 4,
m_width - 8, m_height - 8, m_width - 8, m_height - 8,
2 2
); );
} }
else else
{ {
wxMemoryDC memoryDC; wxMemoryDC memoryDC;
memoryDC.SelectObject(*m_symbolBmap); memoryDC.SelectObject(*m_symbolBmap);
// dc.SetBackgroundMode(wxTRANSPARENT); // dc.SetBackgroundMode(wxTRANSPARENT);
dc.SetTextBackground(*wxWHITE); dc.SetTextBackground(*wxWHITE);
switch (m_suit) switch (m_suit)
{ {
case spades: case spades:
case clubs: case clubs:
dc.SetTextForeground(*wxBLACK); dc.SetTextForeground(*wxBLACK);
break; break;
case diamonds: case diamonds:
case hearts: case hearts:
dc.SetTextForeground(*wxRED); dc.SetTextForeground(*wxRED);
break; break;
} }
int symsize = 11; int symsize = 11;
int sympos = 14; int sympos = 14;
int sympos2 = 25; int sympos2 = 25;
int symdist = 5; int symdist = 5;
int symdist2 = 6; int symdist2 = 6;
int pipsize,pippos,valueheight,valuewidth; int pipsize,pippos,valueheight,valuewidth;
int valuepos; int valuepos;
if (m_scale > 1.2) if (m_scale > 1.2)
{ {
pipsize = symsize; pipsize = symsize;
pippos = sympos; pippos = sympos;
valueheight = 10; valueheight = 10;
valuewidth = 9; valuewidth = 9;
valuepos = 50; valuepos = 50;
} }
else else
{ {
pipsize = 7; pipsize = 7;
pippos = 0; pippos = 0;
valueheight = 7; valueheight = 7;
valuewidth = 6; valuewidth = 6;
valuepos = 36; valuepos = 36;
} }
// Draw the value // Draw the value
dc.Blit((wxCoord)(x + m_scale*3), (wxCoord)(y + m_scale*3), valuewidth, valueheight, dc.Blit((wxCoord)(x + m_scale*3),
&memoryDC, valuewidth * (m_pipValue - 1), valuepos, wxCOPY); (wxCoord)(y + m_scale*3),
dc.Blit((wxCoord)(x + m_width - m_scale*3 - valuewidth), (wxCoord)(y + m_height - valueheight - m_scale*3), valuewidth,
valuewidth, valueheight, valueheight,
&memoryDC, valuewidth * (m_pipValue - 1), valuepos+valueheight, wxCOPY); &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 // Draw the pips
dc.Blit((wxCoord)(x + m_scale*3 + valuewidth+2), (wxCoord)(y + m_scale*3), pipsize, pipsize, dc.Blit((wxCoord)(x + m_scale*3 + valuewidth+2),
&memoryDC, pipsize * m_suit, pippos, wxCOPY); (wxCoord)(y + m_scale*3),
dc.Blit((wxCoord)(x + m_width - m_scale*3-valuewidth-pipsize-2), (wxCoord)(y + m_height - pipsize - m_scale*3), pipsize,
pipsize, pipsize, pipsize,
&memoryDC, pipsize * m_suit, pipsize+pippos, wxCOPY); &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) switch (m_pipValue)
{ {
case 1: case 1:
dc.Blit((wxCoord)(x - symdist + m_width / 2), (wxCoord)(y - m_scale*5 + m_height / 2), symsize, symsize, dc.Blit((wxCoord)(x - symdist + m_width / 2),
&memoryDC, symsize * m_suit, sympos, wxCOPY); (wxCoord)(y - m_scale*5 + m_height / 2),
break; symsize,
symsize,
&memoryDC,
symsize * m_suit,
sympos,
wxCOPY);
break;
case 3: case 3:
dc.Blit((wxCoord)(x - symdist + m_width / 2), (wxCoord)(y - symdist + m_height / 2), symsize, symsize, dc.Blit((wxCoord)(x - symdist + m_width / 2),
&memoryDC, symsize * m_suit, sympos, wxCOPY); (wxCoord)(y - symdist + m_height / 2),
case 2: symsize,
dc.Blit((wxCoord)(x - symdist + m_width / 2), symsize,
(wxCoord)(y - symdist + m_height / 4), symsize, symsize, &memoryDC,
&memoryDC, symsize * m_suit, sympos, wxCOPY); symsize * m_suit,
dc.Blit((wxCoord)(x - symdist + m_width / 2), sympos,
(wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize, wxCOPY);
&memoryDC, symsize * m_suit, sympos2, wxCOPY); case 2:
break; 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: case 5:
dc.Blit((wxCoord)(x - symdist + m_width / 2), (wxCoord)(y - symdist + m_height / 2), symsize, symsize, dc.Blit((wxCoord)(x - symdist + m_width / 2),
&memoryDC, symsize * m_suit, sympos, wxCOPY); (wxCoord)(y - symdist + m_height / 2),
case 4: symsize,
dc.Blit((wxCoord)(x - symdist + m_width / 4), symsize,
(wxCoord)(y - symdist + m_height / 4), symsize, symsize, &memoryDC,
&memoryDC, symsize * m_suit, sympos, wxCOPY); symsize * m_suit,
dc.Blit((wxCoord)(x - symdist + m_width / 4), sympos,
(wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize, wxCOPY);
&memoryDC, symsize * m_suit, sympos2, wxCOPY); case 4:
dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4), dc.Blit((wxCoord)(x - symdist + m_width / 4),
(wxCoord)(y - symdist + m_height / 4), symsize, symsize, (wxCoord)(y - symdist + m_height / 4),
&memoryDC, symsize * m_suit, sympos, wxCOPY); symsize,
dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4), symsize,
(wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize, &memoryDC,
&memoryDC, symsize * m_suit, sympos2, wxCOPY); symsize * m_suit,
break; 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: case 8:
dc.Blit((wxCoord)(x - symdist + 5 * m_width / 10), dc.Blit((wxCoord)(x - symdist + 5 * m_width / 10),
(wxCoord)(y - symdist + 5 * m_height / 8), symsize, symsize, (wxCoord)(y - symdist + 5 * m_height / 8),
&memoryDC, symsize * m_suit, sympos2, wxCOPY); symsize,
case 7: symsize,
dc.Blit((wxCoord)(x - symdist + 5 * m_width / 10), &memoryDC,
(wxCoord)(y - symdist + 3 * m_height / 8), symsize, symsize, symsize * m_suit,
&memoryDC, symsize * m_suit, sympos, wxCOPY); sympos2,
case 6: wxCOPY);
dc.Blit((wxCoord)(x - symdist + m_width / 4), case 7:
(wxCoord)(y - symdist + m_height / 4), symsize, symsize, dc.Blit((wxCoord)(x - symdist + 5 * m_width / 10),
&memoryDC, symsize * m_suit, sympos, wxCOPY); (wxCoord)(y - symdist + 3 * m_height / 8),
dc.Blit((wxCoord)(x - symdist + m_width / 4), symsize,
(wxCoord)(y - symdist + m_height / 2), symsize, symsize, symsize,
&memoryDC, symsize * m_suit, sympos, wxCOPY); &memoryDC,
dc.Blit((wxCoord)(x - symdist + m_width / 4), symsize * m_suit,
(wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize, sympos,
&memoryDC, symsize * m_suit, sympos2, wxCOPY); wxCOPY);
dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4), case 6:
(wxCoord)(y - symdist + m_height / 4), symsize, symsize, dc.Blit((wxCoord)(x - symdist + m_width / 4),
&memoryDC, symsize * m_suit, sympos, wxCOPY); (wxCoord)(y - symdist + m_height / 4),
dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4), symsize,
(wxCoord)(y - symdist + m_height / 2), symsize, symsize, symsize,
&memoryDC, symsize * m_suit, sympos, wxCOPY); &memoryDC, symsize * m_suit, sympos, wxCOPY);
dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4), dc.Blit((wxCoord)(x - symdist + m_width / 4),
(wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize, (wxCoord)(y - symdist + m_height / 2),
&memoryDC, symsize * m_suit, sympos2, wxCOPY); symsize,
break; 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: case 10:
dc.Blit((wxCoord)(x - symdist + m_width / 2), dc.Blit((wxCoord)(x - symdist + m_width / 2),
(wxCoord)(y - symdist + 2 * m_height / 3), symsize, symsize, (wxCoord)(y - symdist + 2 * m_height / 3),
&memoryDC, symsize * m_suit, sympos2, wxCOPY); symsize,
case 9: symsize,
dc.Blit((wxCoord)(x - symdist + m_width / 4), &memoryDC,
(wxCoord)(y - symdist2 + m_height / 4), symsize, symsize, symsize * m_suit,
&memoryDC, symsize * m_suit, sympos, wxCOPY); sympos2,
dc.Blit((wxCoord)(x - symdist + m_width / 4), wxCOPY);
(wxCoord)(y - symdist2 + 5 * m_height / 12), symsize, symsize, case 9:
&memoryDC, symsize * m_suit, sympos, wxCOPY); dc.Blit((wxCoord)(x - symdist + m_width / 4),
dc.Blit((wxCoord)(x - symdist + m_width / 4), (wxCoord)(y - symdist2 + m_height / 4),
(wxCoord)(y - symdist + 7 * m_height / 12), symsize, symsize, symsize,
&memoryDC, symsize * m_suit, sympos2, wxCOPY); symsize,
dc.Blit((wxCoord)(x - symdist + m_width / 4), &memoryDC,
(wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize, symsize * m_suit,
&memoryDC, symsize * m_suit, sympos2, wxCOPY); 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), dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
(wxCoord)(y - symdist2 + m_height / 4), symsize, symsize, (wxCoord)(y - symdist2 + m_height / 4),
&memoryDC, symsize * m_suit, sympos, wxCOPY); symsize,
dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4), symsize,
(wxCoord)(y - symdist2 + 5 * m_height / 12), symsize, symsize, &memoryDC,
&memoryDC, symsize * m_suit, sympos, wxCOPY); symsize * m_suit,
dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4), sympos,
(wxCoord)(y - symdist + 7 * m_height / 12), symsize, symsize, wxCOPY);
&memoryDC, symsize * m_suit, sympos2, wxCOPY); dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4), (wxCoord)(y - symdist2 + 5 * m_height / 12),
(wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize, symsize,
&memoryDC, symsize * m_suit, sympos2, wxCOPY); symsize,
dc.Blit((wxCoord)(x - symdist + m_width / 2), &memoryDC,
(wxCoord)(y - symdist + m_height / 3), symsize, symsize, symsize * m_suit,
&memoryDC, symsize * m_suit, sympos, wxCOPY); sympos,
break; wxCOPY);
case 11: dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4),
case 12: (wxCoord)(y - symdist + 7 * m_height / 12),
case 13: symsize,
memoryDC.SelectObject(*m_pictureBmap); symsize,
int picwidth = 40,picheight = 45; &memoryDC,
dc.Blit((wxCoord)(x + (m_width-picwidth)/2), (wxCoord)(y - picheight/2 + m_height/2), symsize * m_suit,
picwidth, picheight, sympos2,
&memoryDC, picwidth * (m_pipValue - 11), 0, wxCOPY); 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); 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, dc.Blit((wxCoord)(x + m_width-(m_width-picwidth)/2-symsize-3),
&memoryDC, symsize * m_suit, sympos, wxCOPY); (wxCoord)(y - picheight/2+m_height/2+1),
dc.Blit((wxCoord)(x + (m_width-picwidth)/2+2),(wxCoord)(y + picheight/2 + m_height/2-symsize), symsize, symsize, symsize,
&memoryDC, symsize * m_suit, sympos2, wxCOPY); symsize,
break; &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 ); dc.SetBackground( backgroundBrush );
} // Card:Draw() } // Card:Draw()
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Card::DrawNullCard() | //| Card::DrawNullCard() |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Description: | //| Description: |
//| Draws the outline of a card at (x, y). | //| Draws the outline of a card at (x, y). |
//| Used to draw place holders for empty piles of cards. | //| Used to draw place holders for empty piles of cards. |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
void Card::DrawNullCard(wxDC& dc, int x, int y) void Card::DrawNullCard(wxDC& dc, int x, int y)
{ {
wxPen* pen = wxThePenList->FindOrCreatePen(FortyApp::TextColour(), 1, wxSOLID); wxPen* pen = wxThePenList->FindOrCreatePen(FortyApp::TextColour(), 1, wxSOLID);
dc.SetBrush(FortyApp::BackgroundBrush()); dc.SetBrush(FortyApp::BackgroundBrush());
dc.SetPen(*pen); dc.SetPen(*pen);
dc.DrawRoundedRectangle(x, y, m_width, m_height, 4); dc.DrawRoundedRectangle(x, y, m_width, m_height, 4);
} // Card::DrawNullCard() } // Card::DrawNullCard()

View File

@ -6,29 +6,29 @@
// Created: 21/07/97 // Created: 21/07/97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze // Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence // Licence: wxWindows licence
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0 // Last modified: 22nd July 1998 - ported to wxWidgets 2.0
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Description: | //| Description: |
//| A class for drawing playing cards. | //| A class for drawing playing cards. |
//| InitCards() must be called before using the Card class, | //| InitCards() must be called before using the Card class, |
//| otherwise the card bitmaps will not be loaded. | //| otherwise the card bitmaps will not be loaded. |
//| CloseCards() must be called before terminating the | //| CloseCards() must be called before terminating the |
//| program so that the bitmaps are deleted and the memory | //| program so that the bitmaps are deleted and the memory |
//| given back to Windows. | //| given back to Windows. |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
#ifndef _CARD_H_ #ifndef _CARD_H_
#define _CARD_H_ #define _CARD_H_
// Constants // Constants
const int PackSize = 52; const int PackSize = 52;
#define CardHeight Card::GetHeight() #define CardHeight Card::GetHeight()
#define CardWidth Card::GetWidth() #define CardWidth Card::GetWidth()
// Data types // Data types
enum Suit { clubs = 0, diamonds = 1, hearts = 2, spades = 3 }; enum Suit { clubs = 0, diamonds = 1, hearts = 2, spades = 3 };
enum SuitColour { red = 0, black = 1 }; enum SuitColour { red = 0, black = 1 };
enum WayUp { faceup, facedown }; enum WayUp { faceup, facedown };
@ -43,32 +43,32 @@ class Card {
static int m_width,m_height; static int m_width,m_height;
public: public:
Card(int value, WayUp way_up = facedown); Card(int value, WayUp way_up = facedown);
virtual ~Card(); virtual ~Card();
void Draw(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 static void DrawNullCard(wxDC& pDC, int x, int y); // Draw card place-holder
void Erase(wxDC& pDC, int x, int y); void Erase(wxDC& pDC, int x, int y);
void TurnCard(WayUp way_up = faceup) { m_wayUp = way_up; } void TurnCard(WayUp way_up = faceup) { m_wayUp = way_up; }
WayUp GetWayUp() const { return m_wayUp; } WayUp GetWayUp() const { return m_wayUp; }
int GetPipValue() const { return m_pipValue; } int GetPipValue() const { return m_pipValue; }
Suit GetSuit() const { return m_suit; } Suit GetSuit() const { return m_suit; }
SuitColour GetColour() const { return m_colour; } SuitColour GetColour() const { return m_colour; }
static void SetScale(double scale); static void SetScale(double scale);
static int GetHeight() { return m_height; }; static int GetHeight() { return m_height; };
static int GetWidth() { return m_width; }; static int GetWidth() { return m_width; };
static double GetScale() { return m_scale; }; static double GetScale() { return m_scale; };
private: private:
Suit m_suit; Suit m_suit;
int m_pipValue; // in the range 1 (Ace) to 13 (King) int m_pipValue; // in the range 1 (Ace) to 13 (King)
SuitColour m_colour; // red or black SuitColour m_colour; // red or black
bool m_status; bool m_status;
WayUp m_wayUp; WayUp m_wayUp;
static wxBitmap* m_symbolBmap; static wxBitmap* m_symbolBmap;
static wxBitmap* m_pictureBmap; static wxBitmap* m_pictureBmap;
}; };
#endif // _CARD_H_ #endif // _CARD_H_

View File

@ -6,7 +6,7 @@
// Created: 21/07/97 // Created: 21/07/97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze // Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence // Licence: wxWindows licence
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0 // Last modified: 22nd July 1998 - ported to wxWidgets 2.0
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -38,21 +38,21 @@
#endif #endif
BEGIN_EVENT_TABLE(FortyFrame, wxFrame) BEGIN_EVENT_TABLE(FortyFrame, wxFrame)
EVT_MENU(NEW_GAME, FortyFrame::NewGame) EVT_MENU(NEW_GAME, FortyFrame::NewGame)
EVT_MENU(wxID_EXIT, FortyFrame::Exit) EVT_MENU(wxID_EXIT, FortyFrame::Exit)
EVT_MENU(wxID_ABOUT, FortyFrame::About) EVT_MENU(wxID_ABOUT, FortyFrame::About)
EVT_MENU(wxID_HELP_CONTENTS, FortyFrame::Help) EVT_MENU(wxID_HELP_CONTENTS, FortyFrame::Help)
EVT_MENU(UNDO, FortyFrame::Undo) EVT_MENU(UNDO, FortyFrame::Undo)
EVT_MENU(REDO, FortyFrame::Redo) EVT_MENU(REDO, FortyFrame::Redo)
EVT_MENU(SCORES, FortyFrame::Scores) EVT_MENU(SCORES, FortyFrame::Scores)
EVT_MENU(RIGHT_BUTTON_UNDO, FortyFrame::ToggleRightButtonUndo) EVT_MENU(RIGHT_BUTTON_UNDO, FortyFrame::ToggleRightButtonUndo)
EVT_MENU(HELPING_HAND, FortyFrame::ToggleHelpingHand) EVT_MENU(HELPING_HAND, FortyFrame::ToggleHelpingHand)
EVT_MENU(LARGE_CARDS, FortyFrame::ToggleCardSize) EVT_MENU(LARGE_CARDS, FortyFrame::ToggleCardSize)
EVT_CLOSE(FortyFrame::OnCloseWindow) EVT_CLOSE(FortyFrame::OnCloseWindow)
END_EVENT_TABLE() END_EVENT_TABLE()
// Create a new application object // Create a new application object
IMPLEMENT_APP (FortyApp) IMPLEMENT_APP (FortyApp)
wxColour* FortyApp::m_backgroundColour = 0; wxColour* FortyApp::m_backgroundColour = 0;
wxColour* FortyApp::m_textColour = 0; wxColour* FortyApp::m_textColour = 0;
@ -74,131 +74,131 @@ FortyApp::~FortyApp()
bool FortyApp::OnInit() 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")))) if ((argc > 1) && (!wxStrcmp(argv[1],_T("-L"))))
{ {
largecards = true; largecards = true;
size = wxSize(1000,750); size = wxSize(1000,750);
} }
FortyFrame* frame = new FortyFrame( FortyFrame* frame = new FortyFrame(
0, 0,
_T("Forty Thieves"), _T("Forty Thieves"),
wxDefaultPosition, wxDefaultPosition,
size, size,
largecards largecards
); );
// Show the frame // Show the frame
frame->Show(true); frame->Show(true);
frame->GetCanvas()->ShowPlayerDialog(); frame->GetCanvas()->ShowPlayerDialog();
return true; return true;
} }
const wxColour& FortyApp::BackgroundColour() const wxColour& FortyApp::BackgroundColour()
{ {
if (!m_backgroundColour) if (!m_backgroundColour)
{ {
m_backgroundColour = new wxColour(0, 128, 0); m_backgroundColour = new wxColour(0, 128, 0);
} }
return *m_backgroundColour; return *m_backgroundColour;
} }
const wxBrush& FortyApp::BackgroundBrush() const wxBrush& FortyApp::BackgroundBrush()
{ {
if (!m_backgroundBrush) if (!m_backgroundBrush)
{ {
m_backgroundBrush = new wxBrush(BackgroundColour(), wxSOLID); m_backgroundBrush = new wxBrush(BackgroundColour(), wxSOLID);
} }
return *m_backgroundBrush; return *m_backgroundBrush;
} }
const wxColour& FortyApp::TextColour() const wxColour& FortyApp::TextColour()
{ {
if (!m_textColour) if (!m_textColour)
{ {
m_textColour = new wxColour(_T("BLACK")); m_textColour = new wxColour(_T("BLACK"));
} }
return *m_textColour; return *m_textColour;
} }
// My frame constructor // My frame constructor
FortyFrame::FortyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos, const wxSize& size, bool largecards): 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__ #ifdef __WXMAC__
wxApp::s_macAboutMenuItemId = wxID_ABOUT ; wxApp::s_macAboutMenuItemId = wxID_ABOUT ;
#endif #endif
// set the icon // set the icon
#ifdef __WXMSW__ #ifdef __WXMSW__
SetIcon(wxIcon(_T("CardsIcon"))); SetIcon(wxIcon(_T("CardsIcon")));
#else #else
#ifdef GTK_TBD #ifdef GTK_TBD
SetIcon(wxIcon(Cards_bits, Cards_width, Cards_height)); SetIcon(wxIcon(Cards_bits, Cards_width, Cards_height));
#endif #endif
#endif #endif
// Make a menu bar // Make a menu bar
wxMenu* gameMenu = new wxMenu; wxMenu* gameMenu = new wxMenu;
gameMenu->Append(NEW_GAME, _T("&New"), _T("Start a new game")); gameMenu->Append(NEW_GAME, _T("&New"), _T("Start a new game"));
gameMenu->Append(SCORES, _T("&Scores..."), _T("Displays scores")); gameMenu->Append(SCORES, _T("&Scores..."), _T("Displays scores"));
gameMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exits Forty Thieves")); gameMenu->Append(wxID_EXIT, _T("E&xit"), _T("Exits Forty Thieves"));
wxMenu* editMenu = new wxMenu; wxMenu* editMenu = new wxMenu;
editMenu->Append(UNDO, _T("&Undo"), _T("Undo the last move")); editMenu->Append(UNDO, _T("&Undo"), _T("Undo the last move"));
editMenu->Append(REDO, _T("&Redo"), _T("Redo a move that has been undone")); editMenu->Append(REDO, _T("&Redo"), _T("Redo a move that has been undone"));
wxMenu* optionsMenu = new wxMenu; wxMenu* optionsMenu = new wxMenu;
optionsMenu->Append(RIGHT_BUTTON_UNDO, optionsMenu->Append(RIGHT_BUTTON_UNDO,
_T("&Right button undo"), _T("&Right button undo"),
_T("Enables/disables right mouse button undo and redo"), _T("Enables/disables right mouse button undo and redo"),
true true
); );
optionsMenu->Append(HELPING_HAND, optionsMenu->Append(HELPING_HAND,
_T("&Helping hand"), _T("&Helping hand"),
_T("Enables/disables hand cursor when a card can be moved"), _T("Enables/disables hand cursor when a card can be moved"),
true true
); );
optionsMenu->Append(LARGE_CARDS, optionsMenu->Append(LARGE_CARDS,
_T("&Large cards"), _T("&Large cards"),
_T("Enables/disables large cards for high resolution displays"), _T("Enables/disables large cards for high resolution displays"),
true true
); );
optionsMenu->Check(HELPING_HAND, true); optionsMenu->Check(HELPING_HAND, true);
optionsMenu->Check(RIGHT_BUTTON_UNDO, true); optionsMenu->Check(RIGHT_BUTTON_UNDO, true);
optionsMenu->Check(LARGE_CARDS, largecards ? true : false); optionsMenu->Check(LARGE_CARDS, largecards ? true : false);
wxMenu* helpMenu = new wxMenu; wxMenu* helpMenu = new wxMenu;
helpMenu->Append(wxID_HELP_CONTENTS, _T("&Help Contents"), _T("Displays information about playing the game")); 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")); helpMenu->Append(wxID_ABOUT, _T("&About..."), _T("About Forty Thieves"));
m_menuBar = new wxMenuBar; m_menuBar = new wxMenuBar;
m_menuBar->Append(gameMenu, _T("&Game")); m_menuBar->Append(gameMenu, _T("&Game"));
m_menuBar->Append(editMenu, _T("&Edit")); m_menuBar->Append(editMenu, _T("&Edit"));
m_menuBar->Append(optionsMenu, _T("&Options")); m_menuBar->Append(optionsMenu, _T("&Options"));
m_menuBar->Append(helpMenu, _T("&Help")); m_menuBar->Append(helpMenu, _T("&Help"));
SetMenuBar(m_menuBar); SetMenuBar(m_menuBar);
if (largecards) if (largecards)
Card::SetScale(1.3); Card::SetScale(1.3);
m_canvas = new FortyCanvas(this, wxDefaultPosition, size); m_canvas = new FortyCanvas(this, wxDefaultPosition, size);
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
topsizer->Add( m_canvas, 1, wxEXPAND | wxALL, 0); topsizer->Add( m_canvas, 1, wxEXPAND | wxALL, 0);
SetSizer( topsizer ); SetSizer( topsizer );
topsizer->SetSizeHints( this ); topsizer->SetSizeHints( this );
CreateStatusBar(); CreateStatusBar();
} }
FortyFrame::~FortyFrame() FortyFrame::~FortyFrame()
@ -218,13 +218,13 @@ void FortyFrame::OnCloseWindow(wxCloseEvent& event)
void void
FortyFrame::NewGame(wxCommandEvent&) FortyFrame::NewGame(wxCommandEvent&)
{ {
m_canvas->NewGame(); m_canvas->NewGame();
} }
void void
FortyFrame::Exit(wxCommandEvent&) FortyFrame::Exit(wxCommandEvent&)
{ {
Close(true); Close(true);
} }
void void
@ -262,35 +262,35 @@ FortyFrame::About(wxCommandEvent&)
void void
FortyFrame::Undo(wxCommandEvent&) FortyFrame::Undo(wxCommandEvent&)
{ {
m_canvas->Undo(); m_canvas->Undo();
} }
void void
FortyFrame::Redo(wxCommandEvent&) FortyFrame::Redo(wxCommandEvent&)
{ {
m_canvas->Redo(); m_canvas->Redo();
} }
void void
FortyFrame::Scores(wxCommandEvent&) FortyFrame::Scores(wxCommandEvent&)
{ {
m_canvas->UpdateScores(); m_canvas->UpdateScores();
ScoreDialog scores(this, m_canvas->GetScoreFile()); ScoreDialog scores(this, m_canvas->GetScoreFile());
scores.Display(); scores.Display();
} }
void void
FortyFrame::ToggleRightButtonUndo(wxCommandEvent& event) FortyFrame::ToggleRightButtonUndo(wxCommandEvent& event)
{ {
bool checked = m_menuBar->IsChecked(event.GetId()); bool checked = m_menuBar->IsChecked(event.GetId());
m_canvas->EnableRightButtonUndo(checked); m_canvas->EnableRightButtonUndo(checked);
} }
void void
FortyFrame::ToggleHelpingHand(wxCommandEvent& event) FortyFrame::ToggleHelpingHand(wxCommandEvent& event)
{ {
bool checked = m_menuBar->IsChecked(event.GetId()); bool checked = m_menuBar->IsChecked(event.GetId());
m_canvas->EnableHelpingHand(checked); m_canvas->EnableHelpingHand(checked);
} }
void void

View File

@ -6,7 +6,7 @@
// Created: 21/07/97 // Created: 21/07/97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze // Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence // Licence: wxWindows licence
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0 // Last modified: 22nd July 1998 - ported to wxWidgets 2.0
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -18,16 +18,16 @@ class FortyApp: public wxApp
public: public:
FortyApp(); FortyApp();
~FortyApp(); ~FortyApp();
bool OnInit(); bool OnInit();
static const wxColour& BackgroundColour(); static const wxColour& BackgroundColour();
static const wxColour& TextColour(); static const wxColour& TextColour();
static const wxBrush& BackgroundBrush(); static const wxBrush& BackgroundBrush();
private: private:
static wxColour* m_backgroundColour; static wxColour* m_backgroundColour;
static wxColour* m_textColour; static wxColour* m_textColour;
static wxBrush* m_backgroundBrush; static wxBrush* m_backgroundBrush;
}; };
class FortyCanvas; class FortyCanvas;
@ -35,34 +35,39 @@ class FortyFrame: public wxFrame
{ {
public: public:
FortyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos, const wxSize& size, bool largecards); 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 // Menu callbacks
void NewGame(wxCommandEvent& event); void NewGame(wxCommandEvent& event);
void Exit(wxCommandEvent& event); void Exit(wxCommandEvent& event);
void About(wxCommandEvent& event); void About(wxCommandEvent& event);
void Help(wxCommandEvent& event); void Help(wxCommandEvent& event);
void Undo(wxCommandEvent& event); void Undo(wxCommandEvent& event);
void Redo(wxCommandEvent& event); void Redo(wxCommandEvent& event);
void Scores(wxCommandEvent& event); void Scores(wxCommandEvent& event);
void ToggleRightButtonUndo(wxCommandEvent& event); void ToggleRightButtonUndo(wxCommandEvent& event);
void ToggleHelpingHand(wxCommandEvent& event); void ToggleHelpingHand(wxCommandEvent& event);
void ToggleCardSize(wxCommandEvent& event); void ToggleCardSize(wxCommandEvent& event);
FortyCanvas* GetCanvas() { return m_canvas; } FortyCanvas* GetCanvas() { return m_canvas; }
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
private: private:
enum MenuCommands { NEW_GAME = 10, SCORES, enum MenuCommands {
UNDO, REDO, NEW_GAME = 10,
RIGHT_BUTTON_UNDO, HELPING_HAND, LARGE_CARDS SCORES,
}; UNDO,
REDO,
RIGHT_BUTTON_UNDO,
HELPING_HAND,
LARGE_CARDS
};
wxMenuBar* m_menuBar; wxMenuBar* m_menuBar;
FortyCanvas* m_canvas; FortyCanvas* m_canvas;
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@
// Created: 21/07/97 // Created: 21/07/97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze // Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence // Licence: wxWindows licence
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0 // Last modified: 22nd July 1998 - ported to wxWidgets 2.0
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -23,13 +23,13 @@ const int MaxMoves = 800;
//---------------------------------------// //---------------------------------------//
class Pack : public Pile { class Pack : public Pile {
public: public:
Pack(int x, int y); Pack(int x, int y);
~Pack(); ~Pack();
void Redraw(wxDC& dc); void Redraw(wxDC& dc);
void ResetPile() { m_topCard = NumCards - 1; } void ResetPile() { m_topCard = NumCards - 1; }
void Shuffle(); void Shuffle();
void AddCard(Card* card); // Add card void AddCard(Card* card); // Add card
void AddCard(wxDC& dc, Card* card) { AddCard(card); Redraw(dc); } void AddCard(wxDC& dc, Card* card) { AddCard(card); Redraw(dc); }
}; };
@ -38,9 +38,9 @@ public:
//----------------------------------------------------------// //----------------------------------------------------------//
class Base : public Pile { class Base : public Pile {
public: public:
Base(int x, int y); Base(int x, int y);
~Base(); ~Base();
bool AcceptCard(Card* card); bool AcceptCard(Card* card);
}; };
@ -49,9 +49,9 @@ public:
//----------------------------------------------------// //----------------------------------------------------//
class Foundation : public Pile { class Foundation : public Pile {
public: public:
Foundation(int x, int y); Foundation(int x, int y);
~Foundation(); ~Foundation();
bool AcceptCard(Card* card); bool AcceptCard(Card* card);
}; };
@ -60,77 +60,77 @@ public:
//--------------------------------------// //--------------------------------------//
class Discard : public Pile { class Discard : public Pile {
public: public:
Discard(int x, int y); Discard(int x, int y);
~Discard(); ~Discard();
void Redraw(wxDC& dc); void Redraw(wxDC& dc);
void GetTopCardPos(int& x, int& y); void GetTopCardPos(int& x, int& y);
Card* RemoveTopCard(wxDC& dc, int m_xOffset, int m_yOffset); Card* RemoveTopCard(wxDC& dc, int m_xOffset, int m_yOffset);
}; };
class Game { class Game {
public: public:
Game(int wins, int games, int score); Game(int wins, int games, int score);
virtual ~Game(); virtual ~Game();
void Layout(); void Layout();
void NewPlayer(int wins, int games, int score); void NewPlayer(int wins, int games, int score);
void Deal(); // Shuffle and deal a new game void Deal(); // Shuffle and deal a new game
bool CanYouGo(int x, int y); // can card under (x,y) go somewhere? bool CanYouGo(int x, int y); // can card under (x,y) go somewhere?
bool HaveYouWon(); // have you won the game? bool HaveYouWon(); // have you won the game?
void Undo(wxDC& dc); // Undo the last go void Undo(wxDC& dc); // Undo the last go
void Redo(wxDC& dc); // Redo the last go void Redo(wxDC& dc); // Redo the last go
void Redraw(wxDC& dc); void Redraw(wxDC& dc);
void DisplayScore(wxDC& dc); void DisplayScore(wxDC& dc);
bool LButtonDown(wxDC& dc, int mx, int my); // bool LButtonDown(wxDC& dc, int mx, int my);
void LButtonUp(wxDC& dc, int mx, int my); void LButtonUp(wxDC& dc, int mx, int my);
void LButtonDblClk(wxDC& dc, int mx, int my); void LButtonDblClk(wxDC& dc, int mx, int my);
void MouseMove(wxDC& dc, int mx, int my); void MouseMove(wxDC& dc, int mx, int my);
int GetNumWins() const { return m_numWins; } int GetNumWins() const { return m_numWins; }
int GetNumGames() const { return m_numGames; } int GetNumGames() const { return m_numGames; }
int GetScore() const { return m_currentScore + m_totalScore; } int GetScore() const { return m_currentScore + m_totalScore; }
bool InPlay() const { return m_inPlay; } bool InPlay() const { return m_inPlay; }
private: private:
bool DropCard(int x, int y, Pile* pile, Card* card); bool DropCard(int x, int y, Pile* pile, Card* card);
// can the card at (x, y) be dropped on the pile? // can the card at (x, y) be dropped on the pile?
Pile* WhichPile(int x, int y); // which pile is (x, y) over? Pile* WhichPile(int x, int y); // which pile is (x, y) over?
void DoMove(wxDC& dc, Pile* src, Pile* dest); void DoMove(wxDC& dc, Pile* src, Pile* dest);
bool m_inPlay; // flag indicating that the game has started bool m_inPlay; // flag indicating that the game has started
// undo buffer // undo buffer
struct { struct {
Pile* src; Pile* src;
Pile* dest; Pile* dest;
} m_moves[MaxMoves]; } m_moves[MaxMoves];
int m_moveIndex; // current position in undo/redo buffer int m_moveIndex; // current position in undo/redo buffer
int m_redoIndex; // max move index available for redo int m_redoIndex; // max move index available for redo
// the various piles of cards // the various piles of cards
Pack* m_pack; Pack* m_pack;
Discard* m_discard; Discard* m_discard;
Base* m_bases[10]; Base* m_bases[10];
Foundation* m_foundations[8]; Foundation* m_foundations[8];
// variables to do with dragging cards // variables to do with dragging cards
Pile* m_srcPile; Pile* m_srcPile;
Card* m_liftedCard; Card* m_liftedCard;
int m_xPos, m_yPos; // current coords of card being dragged int m_xPos, m_yPos; // current coords of card being dragged
int m_xOffset, m_yOffset; // card/mouse offset when dragging a card int m_xOffset, m_yOffset; // card/mouse offset when dragging a card
wxBitmap* m_bmap; wxBitmap* m_bmap;
wxBitmap* m_bmapCard; wxBitmap* m_bmapCard;
// variables to do with scoring // variables to do with scoring
int m_numGames; int m_numGames;
int m_numWins; int m_numWins;
int m_totalScore; int m_totalScore;
int m_currentScore; int m_currentScore;
}; };
#endif // _GAME_H_ #endif // _GAME_H_

View File

@ -6,13 +6,13 @@
// Created: 21/07/97 // Created: 21/07/97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze // Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence // Licence: wxWindows licence
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0 // Last modified: 22nd July 1998 - ported to wxWidgets 2.0
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Description: | //| Description: |
//| The base class for holding piles of playing cards. | //| The base class for holding piles of playing cards. |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
#ifdef __GNUG__ #ifdef __GNUG__
@ -46,10 +46,10 @@
#include "wx/app.h" #include "wx/app.h"
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Pile::Pile() | //| Pile::Pile() |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Description: | //| Description: |
//| Initialise the pile to be empty of cards. | //| Initialise the pile to be empty of cards. |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
Pile::Pile(int x, int y, int dx, int dy) Pile::Pile(int x, int y, int dx, int dy)
{ {
@ -59,67 +59,67 @@ Pile::Pile(int x, int y, int dx, int dy)
m_dy = dy; m_dy = dy;
for (m_topCard = 0; m_topCard < NumCards; m_topCard++) 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: | //| Description: |
//| Redraw the pile on the screen. If the pile is empty | //| Redraw the pile on the screen. If the pile is empty |
//| just draw a NULL card as a place holder for the pile. | //| just draw a NULL card as a place holder for the pile. |
//| Otherwise draw the pile from the bottom up, starting | //| Otherwise draw the pile from the bottom up, starting |
//| at the origin of the pile, shifting each subsequent | //| at the origin of the pile, shifting each subsequent |
//| card by the pile's x and y offsets. | //| card by the pile's x and y offsets. |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
void Pile::Redraw(wxDC& dc ) void Pile::Redraw(wxDC& dc )
{ {
FortyFrame *frame = (FortyFrame*) wxTheApp->GetTopWindow(); FortyFrame *frame = (FortyFrame*) wxTheApp->GetTopWindow();
wxWindow *canvas = (wxWindow *) NULL; wxWindow *canvas = (wxWindow *) NULL;
if (frame) if (frame)
{ {
canvas = frame->GetCanvas(); canvas = frame->GetCanvas();
} }
if (m_topCard >= 0) if (m_topCard >= 0)
{ {
if (m_dx == 0 && m_dy == 0) if (m_dx == 0 && m_dy == 0)
{ {
if ((canvas) && (canvas->IsExposed(m_x,m_y,(int)(Card::GetScale()*60),(int)(Card::GetScale()*200)))) 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); m_cards[m_topCard]->Draw(dc, m_x, m_y);
} }
else else
{ {
int x = m_x; int x = m_x;
int y = m_y; int y = m_y;
for (int i = 0; i <= m_topCard; i++) for (int i = 0; i <= m_topCard; i++)
{ {
if ((canvas) && (canvas->IsExposed(x,y,(int)(Card::GetScale()*60),(int)(Card::GetScale()*200)))) if ((canvas) && (canvas->IsExposed(x,y,(int)(Card::GetScale()*60),(int)(Card::GetScale()*200))))
m_cards[i]->Draw(dc, x, y); m_cards[i]->Draw(dc, x, y);
x += (int)Card::GetScale()*m_dx; x += (int)Card::GetScale()*m_dx;
y += (int)Card::GetScale()*m_dy; y += (int)Card::GetScale()*m_dy;
} }
} }
} }
else else
{ {
if ((canvas) && (canvas->IsExposed(m_x,m_y,(int)(Card::GetScale()*60),(int)(Card::GetScale()*200)))) if ((canvas) && (canvas->IsExposed(m_x,m_y,(int)(Card::GetScale()*60),(int)(Card::GetScale()*200))))
Card::DrawNullCard(dc, m_x, m_y); Card::DrawNullCard(dc, m_x, m_y);
} }
} }
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Pile::GetTopCard() | //| Pile::GetTopCard() |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Description: | //| Description: |
//| Return a pointer to the top card in the pile or NULL | //| Return a pointer to the top card in the pile or NULL |
//| if the pile is empty. | //| if the pile is empty. |
//| NB: Gets a copy of the card without removing it from the | //| NB: Gets a copy of the card without removing it from the |
//| pile. | //| pile. |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
Card* Pile::GetTopCard() Card* Pile::GetTopCard()
{ {
@ -127,7 +127,7 @@ Card* Pile::GetTopCard()
if (m_topCard >= 0) if (m_topCard >= 0)
{ {
card = m_cards[m_topCard]; card = m_cards[m_topCard];
} }
return card; return card;
} }
@ -136,10 +136,10 @@ Card* Pile::GetTopCard()
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Pile::RemoveTopCard() | //| Pile::RemoveTopCard() |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Description: | //| Description: |
//| If the pile is not empty, remove the top card from the | //| If the pile is not empty, remove the top card from the |
//| pile and return the pointer to the removed card. | //| pile and return the pointer to the removed card. |
//| If the pile is empty return a NULL pointer. | //| If the pile is empty return a NULL pointer. |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
Card* Pile::RemoveTopCard() Card* Pile::RemoveTopCard()
{ {
@ -147,7 +147,7 @@ Card* Pile::RemoveTopCard()
if (m_topCard >= 0) if (m_topCard >= 0)
{ {
card = m_cards[m_topCard--]; card = m_cards[m_topCard--];
} }
return card; return card;
} }
@ -156,49 +156,49 @@ Card* Pile::RemoveTopCard()
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Pile::RemoveTopCard() | //| Pile::RemoveTopCard() |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Description: | //| Description: |
//| As RemoveTopCard() but also redraw the top of the pile | //| As RemoveTopCard() but also redraw the top of the pile |
//| after the card has been removed. | //| after the card has been removed. |
//| NB: the offset allows for the redrawn area to be in a | //| NB: the offset allows for the redrawn area to be in a |
//| bitmap ready for 'dragging' cards acrosss the screen. | //| bitmap ready for 'dragging' cards acrosss the screen. |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
Card* Pile::RemoveTopCard(wxDC& dc, int xOffset, int yOffset) Card* Pile::RemoveTopCard(wxDC& dc, int xOffset, int yOffset)
{ {
int topX, topY, x, y; int topX, topY, x, y;
GetTopCardPos(topX, topY); GetTopCardPos(topX, topY);
Card* card = RemoveTopCard(); Card* card = RemoveTopCard();
if (card) if (card)
{ {
card->Erase(dc, topX - xOffset, topY - yOffset); card->Erase(dc, topX - xOffset, topY - yOffset);
GetTopCardPos(x, y); GetTopCardPos(x, y);
if (m_topCard < 0) if (m_topCard < 0)
{ {
Card::DrawNullCard(dc, x - xOffset, y - yOffset); Card::DrawNullCard(dc, x - xOffset, y - yOffset);
} }
else else
{ {
m_cards[m_topCard]->Draw(dc, x - xOffset, y - yOffset); m_cards[m_topCard]->Draw(dc, x - xOffset, y - yOffset);
} }
} }
return card; return card;
} }
void Pile::GetTopCardPos(int& x, int& y) void Pile::GetTopCardPos(int& x, int& y)
{ {
if (m_topCard < 0) if (m_topCard < 0)
{ {
x = m_x; x = m_x;
y = m_y; y = m_y;
} }
else else
{ {
x = m_x + (int)Card::GetScale()*m_dx * m_topCard; x = m_x + (int)Card::GetScale()*m_dx * m_topCard;
y = m_y + (int)Card::GetScale()*m_dy * m_topCard; y = m_y + (int)Card::GetScale()*m_dy * m_topCard;
} }
} }
void Pile::AddCard(Card* card) void Pile::AddCard(Card* card)
@ -224,7 +224,7 @@ bool Pile::CanCardLeave(Card* card)
{ {
for (int i = 0; i <= m_topCard; i++) for (int i = 0; i <= m_topCard; i++)
{ {
if (card == m_cards[i]) return true; if (card == m_cards[i]) return true;
} }
return false; return false;
} }
@ -244,21 +244,21 @@ int Pile::CalcDistance(int x, int y)
// to the card, otherwise return NULL // to the card, otherwise return NULL
Card* Pile::GetCard(int x, int y) Card* Pile::GetCard(int x, int y)
{ {
int cardX; int cardX;
int cardY; int cardY;
GetTopCardPos(cardX, cardY); GetTopCardPos(cardX, cardY);
for (int i = m_topCard; i >= 0; i--) for (int i = m_topCard; i >= 0; i--)
{ {
if (x >= cardX && x <= cardX + Card::GetWidth() && if (x >= cardX && x <= cardX + Card::GetWidth() &&
y >= cardY && y <= cardY + Card::GetHeight()) y >= cardY && y <= cardY + Card::GetHeight())
{ {
return m_cards[i]; return m_cards[i];
} }
cardX -= (int)Card::GetScale()*m_dx; cardX -= (int)Card::GetScale()*m_dx;
cardY -= (int)Card::GetScale()*m_dy; cardY -= (int)Card::GetScale()*m_dy;
} }
return 0; return 0;
} }
@ -266,22 +266,22 @@ Card* Pile::GetCard(int x, int y)
// return the origin of the pile. // return the origin of the pile.
void Pile::GetCardPos(Card* card, int& x, int& y) void Pile::GetCardPos(Card* card, int& x, int& y)
{ {
x = m_x; x = m_x;
y = m_y; y = m_y;
for (int i = 0; i <= m_topCard; i++) for (int i = 0; i <= m_topCard; i++)
{ {
if (card == m_cards[i]) if (card == m_cards[i])
{ {
return; return;
} }
x += (int)Card::GetScale()*m_dx; x += (int)Card::GetScale()*m_dx;
y += (int)Card::GetScale()*m_dy; y += (int)Card::GetScale()*m_dy;
} }
// card not found in pile, return origin of pile // card not found in pile, return origin of pile
x = m_x; x = m_x;
y = m_y; y = m_y;
} }
@ -294,7 +294,7 @@ bool Pile::Overlap(int x, int y)
if (x >= cardX - Card::GetWidth() && x <= cardX + Card::GetWidth() && if (x >= cardX - Card::GetWidth() && x <= cardX + Card::GetWidth() &&
y >= cardY - Card::GetHeight() && y <= cardY + Card::GetHeight()) y >= cardY - Card::GetHeight() && y <= cardY + Card::GetHeight())
{ {
return true; return true;
} }
return false; return false;
} }

View File

@ -6,28 +6,28 @@
// Created: 21/07/97 // Created: 21/07/97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze // Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence // Licence: wxWindows licence
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0 // Last modified: 22nd July 1998 - ported to wxWidgets 2.0
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
//| Description: | //| Description: |
//| The base class for holding piles of playing cards. | //| The base class for holding piles of playing cards. |
//| This is the basic building block for card games. A pile | //| This is the basic building block for card games. A pile |
//| has a position on the screen and an offset for each | //| has a position on the screen and an offset for each |
//| card placed on it e.g. a pack has no offset, but the | //| card placed on it e.g. a pack has no offset, but the |
//| discard pile may be fanned out across the screen. | //| discard pile may be fanned out across the screen. |
//| | //| |
//| The pile knows how to draw itself, though this may be | //| The pile knows how to draw itself, though this may be |
//| overridden if the default layout needs to be changed. | //| overridden if the default layout needs to be changed. |
//| One or more cards can be removed from the top of a pile, | //| 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. | //| and single cards can be added to the top of a pile. |
//| Functions are provided which redraw the screen when | //| Functions are provided which redraw the screen when |
//| cards are added or removed. | //| cards are added or removed. |
//| | //| |
//| Cards know which way up they are and how to draw | //| Cards know which way up they are and how to draw |
//| themselves. Piles are lists of cards. Piles know which | //| themselves. Piles are lists of cards. Piles know which |
//| cards they contain and where they are to be drawn. | //| cards they contain and where they are to be drawn. |
//+-------------------------------------------------------------+ //+-------------------------------------------------------------+
#ifndef _PILE_H_ #ifndef _PILE_H_
#define _PILE_H_ #define _PILE_H_
@ -41,41 +41,41 @@ const int NumCards = 2 * PackSize;
//----------------------------------------------------------------// //----------------------------------------------------------------//
class Pile { class Pile {
public: public:
Pile(int x, int y, int dx = 0, int dy = 0); Pile(int x, int y, int dx = 0, int dy = 0);
virtual ~Pile(); virtual ~Pile();
// General functions // General functions
virtual void ResetPile() { m_topCard = -1; } virtual void ResetPile() { m_topCard = -1; }
virtual void Redraw(wxDC& pDC); virtual void Redraw(wxDC& pDC);
// Card query functions // Card query functions
virtual Card* GetCard(int x, int y); // Get pointer to card at x, y virtual Card* GetCard(int x, int y); // Get pointer to card at x, y
Card* GetTopCard(); // Get pointer to top card Card* GetTopCard(); // Get pointer to top card
virtual void GetCardPos(Card* card, int& x, int& y); virtual void GetCardPos(Card* card, int& x, int& y);
// Get position of a card // Get position of a card
virtual void GetTopCardPos(int& x, int& y); virtual void GetTopCardPos(int& x, int& y);
// Get position of the top card // Get position of the top card
int GetNumCards() { return m_topCard + 1; } // Number of cards in pile 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? 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 int CalcDistance(int x, int y); // calculates the square of the distance
// of a card at (x,y) from the top of the pile // of a card at (x,y) from the top of the pile
// Functions removing one or more cards from the top of a pile // Functions removing one or more cards from the top of a pile
virtual bool CanCardLeave(Card* card); virtual bool CanCardLeave(Card* card);
Card* RemoveTopCard(); Card* RemoveTopCard();
virtual Card* RemoveTopCard(wxDC& pDC, int xOffset = 0, int yOffset = 0); virtual Card* RemoveTopCard(wxDC& pDC, int xOffset = 0, int yOffset = 0);
// Functions to add a card to the top of a pile // Functions to add a card to the top of a pile
virtual bool AcceptCard(Card*) { return false; } virtual bool AcceptCard(Card*) { return false; }
virtual void AddCard(Card* card); // Add card to top of pile virtual void AddCard(Card* card); // Add card to top of pile
virtual void AddCard(wxDC& pDC, Card* card); // Add card + redraw it virtual void AddCard(wxDC& pDC, Card* card); // Add card + redraw it
void SetPos(int x,int y) {m_x = x;m_y = y;}; void SetPos(int x,int y) {m_x = x;m_y = y;};
protected: protected:
int m_x, m_y; // Position of the pile on the screen int m_x, m_y; // Position of the pile on the screen
int m_dx, m_dy; // Offset when drawing the pile int m_dx, m_dy; // Offset when drawing the pile
Card* m_cards[NumCards]; // Array of cards in this pile Card* m_cards[NumCards]; // Array of cards in this pile
int m_topCard; // Array index of the top card int m_topCard; // Array index of the top card
}; };
#endif // _PILE_H_ #endif // _PILE_H_

View File

@ -6,7 +6,7 @@
// Created: 21/07/97 // Created: 21/07/97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze // Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence // Licence: wxWindows licence
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0 // Last modified: 22nd July 1998 - ported to wxWidgets 2.0
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -16,26 +16,26 @@
class PlayerSelectionDialog : public wxDialog class PlayerSelectionDialog : public wxDialog
{ {
public: public:
PlayerSelectionDialog(wxWindow* parent, ScoreFile* file); PlayerSelectionDialog(wxWindow* parent, ScoreFile* file);
virtual ~PlayerSelectionDialog(); virtual ~PlayerSelectionDialog();
const wxString& GetPlayersName(); const wxString& GetPlayersName();
void ButtonCallback(wxCommandEvent& event); void ButtonCallback(wxCommandEvent& event);
void SelectCallback(wxCommandEvent& event); void SelectCallback(wxCommandEvent& event);
void OnSize(wxSizeEvent& event); void OnSize(wxSizeEvent& event);
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
protected: protected:
friend void SelectCallback(wxListBox&, wxCommandEvent&); friend void SelectCallback(wxListBox&, wxCommandEvent&);
void OnCloseWindow(wxCloseEvent& event); void OnCloseWindow(wxCloseEvent& event);
private: private:
ScoreFile* m_scoreFile; ScoreFile* m_scoreFile;
wxString m_player; wxString m_player;
wxButton* m_OK; wxButton* m_OK;
wxButton* m_cancel; wxButton* m_cancel;
wxTextCtrl* m_textField; wxTextCtrl* m_textField;
}; };
#endif #endif

View File

@ -6,7 +6,7 @@
// Created: 21/07/97 // Created: 21/07/97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze // Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence // Licence: wxWindows licence
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0 // Last modified: 22nd July 1998 - ported to wxWidgets 2.0
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -16,17 +16,17 @@
class ScoreDialog : public wxDialog class ScoreDialog : public wxDialog
{ {
public: public:
ScoreDialog(wxWindow* parent, ScoreFile* file); ScoreDialog(wxWindow* parent, ScoreFile* file);
virtual ~ScoreDialog(); virtual ~ScoreDialog();
void Display(); void Display();
protected: protected:
void OnCloseWindow(wxCloseEvent& event); void OnCloseWindow(wxCloseEvent& event);
private: private:
ScoreFile* m_scoreFile; ScoreFile* m_scoreFile;
wxButton* m_OK; wxButton* m_OK;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };

View File

@ -6,7 +6,7 @@
// Created: 21/07/97 // Created: 21/07/97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 1993-1998 Chris Breeze // Copyright: (c) 1993-1998 Chris Breeze
// Licence: wxWindows licence // Licence: wxWindows licence
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Last modified: 22nd July 1998 - ported to wxWidgets 2.0 // Last modified: 22nd July 1998 - ported to wxWidgets 2.0
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -17,19 +17,19 @@
class ScoreFile { class ScoreFile {
public: public:
ScoreFile(const wxString& appName); ScoreFile(const wxString& appName);
virtual ~ScoreFile(); virtual ~ScoreFile();
void GetPlayerList( wxArrayString &list ); void GetPlayerList( wxArrayString &list );
wxString GetPreviousPlayer() const; wxString GetPreviousPlayer() const;
void ReadPlayersScore(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); void WritePlayersScore(const wxString& player, int wins, int games, int score);
private: private:
long CalcCheck(const wxString& name, int p1, int p2, int p3); long CalcCheck(const wxString& name, int p1, int p2, int p3);
wxString m_configFilename; wxString m_configFilename;
wxConfig* m_config; wxConfig* m_config;
}; };
#endif #endif