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