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
// 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
/////////////////////////////////////////////////////////////////////////////
@ -39,35 +39,35 @@ BEGIN_EVENT_TABLE(FortyCanvas, wxScrolledWindow)
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;
}
@ -78,79 +78,79 @@ Write the current player's score back to the score file
*/
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);
}
}
}
/*
@ -158,113 +158,113 @@ Called when the main frame is closed
*/
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()

View File

@ -6,7 +6,7 @@
// 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
/////////////////////////////////////////////////////////////////////////////
@ -21,38 +21,38 @@ class PlayerSelectionDialog;
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

View File

@ -6,17 +6,17 @@
// 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__
@ -54,64 +54,64 @@ int Card::m_width = 50;
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
{
@ -121,10 +121,10 @@ Card::Card(int value, WayUp way_up) :
//+-------------------------------------------------------------+
//| Card::SetScale() |
//| Card::SetScale() |
//+-------------------------------------------------------------+
//| Description: |
//| Scales the cards |
//| Description: |
//| Scales the cards |
//+-------------------------------------------------------------+
void Card::SetScale(double scale)
{
@ -134,10 +134,10 @@ 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()
{
@ -145,262 +145,436 @@ 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);
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;
dc.DrawRoundedRectangle(
x + 4, y + 4,
m_width - 8, m_height - 8,
2
);
}
else
{
wxMemoryDC memoryDC;
memoryDC.SelectObject(*m_symbolBmap);
memoryDC.SelectObject(*m_symbolBmap);
// dc.SetBackgroundMode(wxTRANSPARENT);
// 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;
}
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 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;
}
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 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);
// 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;
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 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 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 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);
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);
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;
}
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 );
}
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()

View File

@ -6,29 +6,29 @@
// 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 };
@ -43,32 +43,32 @@ class Card {
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_

View File

@ -6,7 +6,7 @@
// 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
/////////////////////////////////////////////////////////////////////////////
@ -38,21 +38,21 @@
#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;
@ -74,131 +74,131 @@ FortyApp::~FortyApp()
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"));
// 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* 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* 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"));
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"));
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);
SetMenuBar(m_menuBar);
if (largecards)
Card::SetScale(1.3);
if (largecards)
Card::SetScale(1.3);
m_canvas = new FortyCanvas(this, wxDefaultPosition, size);
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 );
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
topsizer->Add( m_canvas, 1, wxEXPAND | wxALL, 0);
SetSizer( topsizer );
topsizer->SetSizeHints( this );
CreateStatusBar();
CreateStatusBar();
}
FortyFrame::~FortyFrame()
@ -218,13 +218,13 @@ void FortyFrame::OnCloseWindow(wxCloseEvent& event)
void
FortyFrame::NewGame(wxCommandEvent&)
{
m_canvas->NewGame();
m_canvas->NewGame();
}
void
FortyFrame::Exit(wxCommandEvent&)
{
Close(true);
Close(true);
}
void
@ -262,35 +262,35 @@ FortyFrame::About(wxCommandEvent&)
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

View File

@ -6,7 +6,7 @@
// 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
/////////////////////////////////////////////////////////////////////////////
@ -18,16 +18,16 @@ class FortyApp: public wxApp
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;
@ -35,34 +35,39 @@ class FortyFrame: public wxFrame
{
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;
};
//----------------------------------------------------------------------------

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@
// 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
/////////////////////////////////////////////////////////////////////////////
@ -23,13 +23,13 @@ const int MaxMoves = 800;
//---------------------------------------//
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); }
};
@ -38,9 +38,9 @@ public:
//----------------------------------------------------------//
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);
};
@ -49,9 +49,9 @@ public:
//----------------------------------------------------//
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);
};
@ -60,77 +60,77 @@ public:
//--------------------------------------//
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 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
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
// 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];
// 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
// 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;
wxBitmap* m_bmap;
wxBitmap* m_bmapCard;
// variables to do with scoring
int m_numGames;
int m_numWins;
int m_totalScore;
int m_currentScore;
// variables to do with scoring
int m_numGames;
int m_numWins;
int m_totalScore;
int m_currentScore;
};
#endif // _GAME_H_

View File

@ -6,13 +6,13 @@
// 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__
@ -46,10 +46,10 @@
#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)
{
@ -59,67 +59,67 @@ 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();
}
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);
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()
{
@ -127,7 +127,7 @@ Card* Pile::GetTopCard()
if (m_topCard >= 0)
{
card = m_cards[m_topCard];
card = m_cards[m_topCard];
}
return card;
}
@ -136,10 +136,10 @@ Card* Pile::GetTopCard()
//+-------------------------------------------------------------+
//| 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()
{
@ -147,7 +147,7 @@ Card* Pile::RemoveTopCard()
if (m_topCard >= 0)
{
card = m_cards[m_topCard--];
card = m_cards[m_topCard--];
}
return card;
}
@ -156,49 +156,49 @@ Card* Pile::RemoveTopCard()
//+-------------------------------------------------------------+
//| 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;
int topX, topY, x, y;
GetTopCardPos(topX, topY);
Card* card = RemoveTopCard();
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);
}
}
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;
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)
@ -224,7 +224,7 @@ bool Pile::CanCardLeave(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;
}
@ -244,21 +244,21 @@ int Pile::CalcDistance(int x, int y)
// to the card, otherwise return NULL
Card* Pile::GetCard(int x, int y)
{
int cardX;
int cardY;
GetTopCardPos(cardX, cardY);
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;
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;
}
@ -266,22 +266,22 @@ Card* Pile::GetCard(int x, int y)
// return the origin of the pile.
void Pile::GetCardPos(Card* card, int& x, int& y)
{
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;
}
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;
// card not found in pile, return origin of pile
x = m_x;
y = m_y;
}
@ -294,7 +294,7 @@ bool Pile::Overlap(int x, int y)
if (x >= cardX - Card::GetWidth() && x <= cardX + Card::GetWidth() &&
y >= cardY - Card::GetHeight() && y <= cardY + Card::GetHeight())
{
return true;
return true;
}
return false;
}

View File

@ -6,28 +6,28 @@
// 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_
@ -41,41 +41,41 @@ const int NumCards = 2 * PackSize;
//----------------------------------------------------------------//
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_

View File

@ -6,7 +6,7 @@
// 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
/////////////////////////////////////////////////////////////////////////////
@ -16,26 +16,26 @@
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

View File

@ -6,7 +6,7 @@
// 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
/////////////////////////////////////////////////////////////////////////////
@ -16,17 +16,17 @@
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()
};

View File

@ -6,7 +6,7 @@
// 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
/////////////////////////////////////////////////////////////////////////////
@ -17,19 +17,19 @@
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