1 | /****************************************************************************
|
---|
2 | ** $Id: gtetrix.h 160 2006-12-11 20:15:57Z dmik $
|
---|
3 | **
|
---|
4 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
|
---|
5 | **
|
---|
6 | ** This file is part of an example program for Qt. This example
|
---|
7 | ** program may be used, distributed and modified without limitation.
|
---|
8 | **
|
---|
9 | *****************************************************************************/
|
---|
10 |
|
---|
11 | #ifndef GTETRIX_H
|
---|
12 | #define GTETRIX_H
|
---|
13 |
|
---|
14 | #include "tpiece.h"
|
---|
15 |
|
---|
16 |
|
---|
17 | class GenericTetrix
|
---|
18 | {
|
---|
19 | public:
|
---|
20 | GenericTetrix(int boardWidth = 10,int boardHeight = 22);
|
---|
21 | virtual ~GenericTetrix();
|
---|
22 |
|
---|
23 | void clearBoard(int fillRandomLines = 0);
|
---|
24 | void revealNextPiece(int revealIt);
|
---|
25 | void updateBoard(int x1,int y1,int x2,int y2,int dontUpdateBlanks = 0);
|
---|
26 | void updateNext(){if (showNext) showNextPiece();}
|
---|
27 | void hideBoard();
|
---|
28 | void showBoard();
|
---|
29 | void fillRandom(int line);
|
---|
30 |
|
---|
31 | void moveLeft(int steps = 1);
|
---|
32 | void moveRight(int steps = 1);
|
---|
33 | void rotateLeft();
|
---|
34 | void rotateRight();
|
---|
35 | void dropDown();
|
---|
36 | void oneLineDown();
|
---|
37 | void newPiece();
|
---|
38 | void removePiece();
|
---|
39 |
|
---|
40 | int noOfClearLines() {return nClearLines;}
|
---|
41 | int getLinesRemoved() {return nLinesRemoved;}
|
---|
42 | int getPiecesDropped() {return nPiecesDropped;}
|
---|
43 | int getScore() {return score;}
|
---|
44 | int getLevel() {return level;}
|
---|
45 | int boardHeight() {return height;}
|
---|
46 | int boardWidth() {return width;}
|
---|
47 |
|
---|
48 | virtual void drawSquare(int x,int y,int value) = 0;
|
---|
49 | virtual void gameOver() = 0;
|
---|
50 |
|
---|
51 | virtual void startGame(int gameType = 0,int fillRandomLines = 0);
|
---|
52 | virtual void drawNextSquare(int x,int y,int value);
|
---|
53 | virtual void pieceDropped(int dropHeight);
|
---|
54 | virtual void updateRemoved(int noOfLines);
|
---|
55 | virtual void updateScore(int newScore);
|
---|
56 | virtual void updateLevel(int newLevel);
|
---|
57 |
|
---|
58 | private:
|
---|
59 | void draw(int x, int y, int value){drawSquare(x,height - y,value);}
|
---|
60 | void removeFullLines();
|
---|
61 | void removeLine(int line);
|
---|
62 | void showPiece();
|
---|
63 | void erasePiece();
|
---|
64 | void internalPieceDropped(int dropHeight);
|
---|
65 | void gluePiece();
|
---|
66 | void showNextPiece(int erase = 0);
|
---|
67 | void eraseNextPiece(){showNextPiece(1);};
|
---|
68 | int canPosition(TetrixPiece &piece); // Returns a boolean value.
|
---|
69 | int canMoveTo(int xPosition, int line); // Returns a boolean value.
|
---|
70 | void moveTo(int xPosition,int line);
|
---|
71 | void position(TetrixPiece &piece);
|
---|
72 | void optimizedMove(int newPos, int newLine,TetrixPiece &newPiece);
|
---|
73 |
|
---|
74 | int &board(int x,int y){return boardPtr[width*y + x];}
|
---|
75 |
|
---|
76 | TetrixPiece currentPiece;
|
---|
77 | TetrixPiece nextPiece;
|
---|
78 | int currentLine;
|
---|
79 | int currentPos;
|
---|
80 | int showNext; // Boolean variable.
|
---|
81 | int nLinesRemoved;
|
---|
82 | int nPiecesDropped;
|
---|
83 | int score;
|
---|
84 | int level;
|
---|
85 | int gameID;
|
---|
86 | int nClearLines;
|
---|
87 | int width;
|
---|
88 | int height;
|
---|
89 | int *boardPtr;
|
---|
90 | };
|
---|
91 |
|
---|
92 |
|
---|
93 | #endif
|
---|