]> git.saurik.com Git - wxWidgets.git/blame - demos/forty/game.h
Misc validity fixes to samples/xrc/rc/*.xrc.
[wxWidgets.git] / demos / forty / game.h
CommitLineData
63cafd27
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: game.h
3// Purpose: Forty Thieves patience game
4// Author: Chris Breeze
5// Modified by:
6// Created: 21/07/97
63cafd27 7// Copyright: (c) 1993-1998 Chris Breeze
010216e3 8// Licence: wxWindows licence
63cafd27 9//---------------------------------------------------------------------------
be5a51fb 10// Last modified: 22nd July 1998 - ported to wxWidgets 2.0
63cafd27
JS
11/////////////////////////////////////////////////////////////////////////////
12#ifndef _GAME_H_
13#define _GAME_H_
14#include "card.h"
15#include "pile.h"
16
17const int MaxMoves = 800;
18
19
20//---------------------------------------//
21// A class which holds the pack of cards //
22//---------------------------------------//
23class Pack : public Pile {
24public:
010216e3 25 Pack(int x, int y);
d3c7fc99 26 virtual ~Pack();
010216e3
WS
27 void Redraw(wxDC& dc);
28 void ResetPile() { m_topCard = NumCards - 1; }
29 void Shuffle();
30 void AddCard(Card* card); // Add card
31 void AddCard(wxDC& dc, Card* card) { AddCard(card); Redraw(dc); }
63cafd27
JS
32};
33
34
35//----------------------------------------------------------//
36// A class which holds a base i.e. the initial 10 x 4 cards //
37//----------------------------------------------------------//
38class Base : public Pile {
39public:
010216e3 40 Base(int x, int y);
d3c7fc99 41 virtual ~Base(){}
010216e3 42 bool AcceptCard(Card* card);
63cafd27
JS
43};
44
45
46//----------------------------------------------------//
47// A class which holds a foundation i.e. Ace, 2, 3... //
48//----------------------------------------------------//
49class Foundation : public Pile {
50public:
010216e3 51 Foundation(int x, int y);
d3c7fc99 52 virtual ~Foundation(){}
010216e3 53 bool AcceptCard(Card* card);
63cafd27
JS
54};
55
56
57//--------------------------------------//
58// A class which holds the discard pile //
59//--------------------------------------//
60class Discard : public Pile {
61public:
010216e3 62 Discard(int x, int y);
d3c7fc99 63 virtual ~Discard(){}
010216e3
WS
64 void Redraw(wxDC& dc);
65 void GetTopCardPos(int& x, int& y);
66 Card* RemoveTopCard(wxDC& dc, int m_xOffset, int m_yOffset);
63cafd27
JS
67};
68
69
70class Game {
71public:
010216e3
WS
72 Game(int wins, int games, int score);
73 virtual ~Game();
63cafd27 74
010216e3
WS
75 void Layout();
76 void NewPlayer(int wins, int games, int score);
77 void Deal(); // Shuffle and deal a new game
78 bool CanYouGo(int x, int y); // can card under (x,y) go somewhere?
79 bool HaveYouWon(); // have you won the game?
63cafd27 80
010216e3
WS
81 void Undo(wxDC& dc); // Undo the last go
82 void Redo(wxDC& dc); // Redo the last go
63cafd27 83
010216e3
WS
84 void Redraw(wxDC& dc);
85 void DisplayScore(wxDC& dc);
86 bool LButtonDown(wxDC& dc, int mx, int my);
87 void LButtonUp(wxDC& dc, int mx, int my);
88 void LButtonDblClk(wxDC& dc, int mx, int my);
89 void MouseMove(wxDC& dc, int mx, int my);
63cafd27 90
010216e3
WS
91 int GetNumWins() const { return m_numWins; }
92 int GetNumGames() const { return m_numGames; }
93 int GetScore() const { return m_currentScore + m_totalScore; }
63cafd27 94
010216e3 95 bool InPlay() const { return m_inPlay; }
63cafd27
JS
96
97private:
010216e3
WS
98 bool DropCard(int x, int y, Pile* pile, Card* card);
99 // can the card at (x, y) be dropped on the pile?
100 Pile* WhichPile(int x, int y); // which pile is (x, y) over?
101 void DoMove(wxDC& dc, Pile* src, Pile* dest);
102
103 bool m_inPlay; // flag indicating that the game has started
104
105 // undo buffer
106 struct {
107 Pile* src;
108 Pile* dest;
109 } m_moves[MaxMoves];
110 int m_moveIndex; // current position in undo/redo buffer
111 int m_redoIndex; // max move index available for redo
112
113 // the various piles of cards
114 Pack* m_pack;
115 Discard* m_discard;
116 Base* m_bases[10];
117 Foundation* m_foundations[8];
118
119 // variables to do with dragging cards
120 Pile* m_srcPile;
121 Card* m_liftedCard;
122 int m_xPos, m_yPos; // current coords of card being dragged
123 int m_xOffset, m_yOffset; // card/mouse offset when dragging a card
124
125 wxBitmap* m_bmap;
126 wxBitmap* m_bmapCard;
127
128 // variables to do with scoring
129 int m_numGames;
130 int m_numWins;
131 int m_totalScore;
132 int m_currentScore;
63cafd27
JS
133};
134
135#endif // _GAME_H_