-
Notifications
You must be signed in to change notification settings - Fork 0
/
LevelManager.h
executable file
·89 lines (71 loc) · 2.1 KB
/
LevelManager.h
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
//
// Created by Anders on 13.12.2015.
//
#ifndef INNLEVERING3_LEVELMANAGER_H
#define INNLEVERING3_LEVELMANAGER_H
// own libs
#include "BrickFactory.h"
#include "GameManager.h"
class BrickFactory;
struct Brick;
// brick structs
typedef struct Coordinate {
byte value;
byte x;
byte y;
} Coordinate;
typedef struct ActiveBrick {
Brick* brick;
byte color;
Coordinate visualRepresentation[5][5];
};
typedef enum BrickDirection {
Right,
Left,
Normal
} BrickDirection;
// bucket size
#define BUCKET_WIDTH 10
#define BUCKET_HEIGHT 18
// game options
#define BRICK_HEIGHT_OFFSET_AT_START 3
// bucket structs
typedef struct BucketContainer {
char value;
byte color;
} BucketContainer;
typedef struct TetrisBucket {
BucketContainer bucket[BUCKET_HEIGHT][BUCKET_WIDTH];
} TetrisBucket;
class LevelManager {
public:
LevelManager();
void setBrickFactory(BrickFactory& brickFactory) { this->brickFactory = &brickFactory; }
void initializeNewGame();
void spawnNewBrick();
byte moveBrick(BrickDirection brickDirection, int& score);
void rotateBrick();
void resetHighestFilledRow() { highestFilledRow = 0; }
TetrisBucket* getTetrisBucket() { return &tetrisBucket; }
byte getWidth() const { return BUCKET_WIDTH; }
byte getHeight() const { return BUCKET_HEIGHT; }
byte getHighestFilledRow() const { return highestFilledRow; }
BrickDirection getBrickDirection() const { return brickDirection; }
ActiveBrick* getBrick() { return ¤tBrick; }
ActiveBrick* getNextBrick() { return &nextBrick; }
private:
BrickFactory* brickFactory;
TetrisBucket tetrisBucket;
ActiveBrick currentBrick;
ActiveBrick nextBrick;
BrickDirection brickDirection;
byte highestFilledRow;
// initialization functions
void initializeTetrisBucket();
// gameloop functions
boolean checkEnteredBucket() const;
void checkForCollision(BrickDirection brickDirection, byte i, byte j,
byte& collision, byte& wallCollision) const;
void applyMovement(BrickDirection brickDirection, byte& wallCollision);
};
#endif