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