Debian Codegraph @

TetrisAttack/src/CPlayingField.h

raw
1 #ifndef _CPLAYINGFIELD_
2 #define _CPLAYINGFIELD_
3
4 #include <vector>
5 #include "oodle.h"
6 #include "CBlock.h"
7 #include "CBlockSet.h"
8 #include "CCursor.h"
9 #include "CBLockLoc.h"
10 #include "CTetrisTheme.h"
11
12 using namespace std;
13
14 //! Class to handle each of the two playing fields
15 class CPlayingField
16 {
17 public:
18 CPlayingField(CVector pos, CBlockSet &set, CTetrisTheme* t, int speed);
19 ~CPlayingField();
20
21 void draw(CSurface& s); //! Draw the playing field
22
23 // Game mechanics
24 void swap(); //! Swaps the blocks under the cursor
25 void moveCursor(int dX, int dY, double sec); //! Move cursor to new location in certain amt. of time
26 void moveCursorAbs(int x, int y, double sec);
27
28 // Maintainence
29 void setBackground(const string& fileName); //! Set background of playing field
30 void addBlock(int x, int y, BlockType type); //! Add a block to the playing field
31 void addBlock(int x, int y, bool active, BlockType type);
32 void setBlockAnim(int x, int y, const string &name);
33 void appendBlockEffect(int x, int y, int duration, CEffect::Effects effect);
34 int addEventAllBlocks(CSequencedEvent *e);
35 void appendBlockEvent(int x, int y, CSequencedEvent* e);
36 void removeBlock(int x, int y); //! Remove a block
37 void removeBlockEffect(CBlock* ptr, CSyncBlockerEvent* sync);
38 void removeList( list<CPoint> &toRemove, CSyncBlockerEvent* sync );
39 bool blockExists(int x, int y);
40 void moveBlock(int x1, int y1, int x2, int y2);
41 void moveBlockRelBoardCords(int x, int y, int dX, int dY, double speed) { if (blockExists(x, y)) blocks[x][y]->moveRelBoardCords(dX, dY, speed); }
42 int getBlockX(CBlock *b);
43 int getBlockY(CBlock *b);
44 bool isGameOver() { return gameOver; }
45 bool isGameWon() { return gameWon; }
46 // Loading Boards
47 void load(int stage, int index);
48 void reLoadLevel() { load(lStage, lIndex); }
49 int getStage() { return lStage; }
50 int getLvl() { return lIndex; }
51 CVector getPos() { return pos; }
52 //Misc
53 bool boardCords(CVector p, int &x, int &y);
54 void clear();
55
56 const static int FIELD_WIDTH = 6;
57 const static int FIELD_HEIGHT = 12;
58 private:
59
60 int width, height;
61 int moveUpOffset;
62 // Game mechanics
63 void checkBlocks(); //! Checks for blocks, combos, etc. (TODO: Some way to handle chains)
64 void applyGravity(); //! Checks for floating blocks, gives them a velocity downwards
65 void moveDown(); //! Moves a block down into
66 void moveUp();
67 bool checkBounds(int x, int y);
68 void setMoves(int m);
69 bool isEmpty();
70 bool allActive();
71 bool allFallen();
72 // CSurface* background; //! Surface to hold the background of this field
73 CBlock* blocks[FIELD_WIDTH][FIELD_HEIGHT]; //! 2-d array of pointers to block objects
74 CBlockSet& blockSet; //! Block set to get blocks from
75 CCursor cursor; //! Cursor sprite
76 // vector<CGarbageBlock*> garbage; //! vector that holds pointers to the garbage blocks in CPlayingField::blocks
77 vector<CBlockLoc> clearedBlockLocations; //! vector that holds locations of blocks just cleared (used for quickly finding if there are any combos or if it cleared garbage)
78 list<CBlock*> freeBlocks; //! list that holds CBlocks that have been freed from the playing field, but that still need to be drawn
79 Uint32 grav;
80 CVector pos; //! Vector that holds location of upper-lefthand corner of the playing field
81 CRect rect; //! Rect that defines playing field's bounds
82 CTimer moveUpTimer; //! Timer to track when it is time to move the blocks up
83 int moves;
84 int numBlocks;
85 CText movesTxt;
86 CText stageTxt;
87 CText gameOverTxt;
88 int lStage, lIndex;
89 bool gameOver, gameWon;
90 CColor txtColor;
91 CTetrisTheme* theme;
92 };
93
94 #endif