File: pile.h

package info (click to toggle)
wxwidgets3.0 3.0.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 120,464 kB
  • sloc: cpp: 896,633; makefile: 52,303; ansic: 21,971; sh: 5,713; python: 2,940; xml: 1,534; perl: 264; javascript: 33
file content (80 lines) | stat: -rw-r--r-- 3,681 bytes parent folder | download | duplicates (10)
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
/////////////////////////////////////////////////////////////////////////////
// Name:        pile.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
/////////////////////////////////////////////////////////////////////////////
//+-------------------------------------------------------------+
//| 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_
#include "card.h"

const int NumCards = 2 * PackSize;


//----------------------------------------------------------------//
// A class defining a pile of cards with a position on the screen //
//----------------------------------------------------------------//
class Pile {
public:
    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);

    // 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 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
};

#endif // _PILE_H_