-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstarblock.cc
executable file
·98 lines (82 loc) · 2.25 KB
/
starblock.cc
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
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include "coordinate.h"
#include "starblock.h"
#include "block.h"
#include "history.h"
using namespace std;
// Constructor that sets type
StarBlock::StarBlock() : block{'*'} {}
// Initializer
void StarBlock::initialize(string** board, int level_num, bool &gameOver) {
level = level_num;
if(board[3][6]!=" "){ //game over.
gameOver = true;
}
else{
blockCoord[0]=new Coordinate;
blockCoord[0]->setCoord(3, 6);
// Set other coordinates as 0 default: NEVER check/use them
blockCoord[1]=new Coordinate;
blockCoord[1]->setCoord(0, 0);
blockCoord[2]=new Coordinate;
blockCoord[2]->setCoord(0, 0);
blockCoord[3]=new Coordinate;
blockCoord[3]->setCoord(0, 0);
}
}
// Default destructor
StarBlock::~StarBlock() {}
// Needed to ensure class is not abstract
void StarBlock::clockwise(string** board) {}
// Needed to ensure class is not abstract
void StarBlock::anticlockwise(string** board) {}
void StarBlock::updateBoard(std::string** board) {
Coordinate *c = blockCoord[0]; // Only looks at first coordinate
int x = c->getX(c);
int y = c->getY(c);
board[x][y] = "*";
}
void StarBlock::drop(map<int, int> returnRows, string** board, vector<history*> &ongrid, int level, bool &gameOver) {
returnRows=updateRows(returnRows, board);
history *h=new history();
vector<Coordinate*> v=h->accessGrid();
int maxRow=3;
for(int i=1;i<=bottomRow-maxRow;i++){
int delta=i;
int count=0;
//determine the new coordinates.
Coordinate *c = blockCoord[0];
int x=c->getX(c);
int newX=x+delta;
int y=c->getY(c); //y-coord stays the same.
if(board[newX][y]==" "){
++count;
}
if(count==1){}
else {
Coordinate *c=blockCoord[0];
int x=c->getX(c);
int y=c->getY(c);
int newX=x+delta-1;
board[x][y]=" "; //the previous coordinates of the block are set to empty.
blockCoord[0]->setCoord(newX, y);
v.push_back(blockCoord[0]);
break;
}
if(i==bottomRow-maxRow){
Coordinate *c=blockCoord[0];
int x=c->getX(c);
int y=c->getY(c);
int newX=x+bottomRow-maxRow;
board[x][y]=" "; //the previous coordinates of the block are set to empty.
blockCoord[0]->setCoord(newX, y);
v.push_back(blockCoord[0]);
break;
}
}
h->accessGrid()=v;
ongrid.push_back(h);
}