-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNBlock.cc
executable file
·56 lines (47 loc) · 1.43 KB
/
NBlock.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
#include "Block.h"
#include "NBlock.h"
#include "Coords.h"
#include "Board.h"
#include <stdexcept>
#include <vector>
using namespace std;
NBlock::NBlock(Board *b,int level) : Block{b, level} {
blockType = 'N';
int startX = theBoard->getStartCoords().getX();
int startY = theBoard->getStartCoords().getY();
// setting its coords with respect to the boards starting coords
theCoords.emplace_back(Coords{startX, startY+3});
theCoords.emplace_back(Coords{startX+1, startY+2});
theCoords.emplace_back(Coords{startX+2, startY+1});
theCoords.emplace_back(Coords{startX+3, startY});
if(!isCoordsFreeOnBoard()) throw out_of_range{"N"};
// updating the board of its final coords
updateBoard();
}
void NBlock::config1(){
presentConfig = 1;
theCoords[0].setY(theCoords[0].getY()+3);
theCoords[1].setY(theCoords[1].getY()+1);
theCoords[2].setY(theCoords[2].getY()-1);
theCoords[3].setY(theCoords[3].getY()-3);
}
void NBlock::config2(){
presentConfig = 2;
theCoords[0].setY(theCoords[0].getY()-3);
theCoords[1].setY(theCoords[1].getY()-1);
theCoords[2].setY(theCoords[2].getY()+1);
theCoords[3].setY(theCoords[3].getY()+3);
}
void NBlock::clockwise() {
clearCoordsOnBoard();
// rotate
if(presentConfig == 1){ config2(); }
else{ config1(); }
// if rotated pos is filled, reverse the rotation
if(!isCoordsFreeOnBoard()){
if(presentConfig==1){config2();}
else{config1();}
}
updateBoard();
}
void NBlock::anticlockwise() { clockwise(); }