-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiblock.cc
executable file
·66 lines (55 loc) · 1.29 KB
/
iblock.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
#include "iblock.h"
#include "Board.h"
#include "Block.h"
#include "Coords.h"
#include <vector>
#include <stdexcept>
using namespace std;
IBlock::IBlock(Board *b, int level): Block{b, level}
{
blockType = 'I';
Coords startCoords = theBoard->getStartCoords();
for (int i = 0; i < 4; ++i)
{
theCoords.emplace_back(startCoords.getX() , startCoords.getY() + i);
}
if (!isCoordsFreeOnBoard())
{
throw out_of_range("I");
}
updateBoard();
}
void IBlock::config1ToConfig2(){
presentConfig = 1;
int len = theCoords.size();
int tempX = theCoords[3].getX();
for (int i = 0; i < len; ++i){
// updating coordinates of block
int tempY = theCoords[i].getY();
theCoords[i].setX(tempX+3);
theCoords[i].setY(tempY+i);
}
}
void IBlock::config2ToConfig1(){
presentConfig = 2;
int len = theCoords.size();
int tempY = theCoords[0].getY();
for (int i = 0; i < len; ++i){
int tempX = theCoords[i].getX();
theCoords[i].setX(tempX-i);
theCoords[i].setY(tempY);
}
}
void IBlock::clockwise(){
clearCoordsOnBoard();
// rotate
if(presentConfig == 1){ config2ToConfig1(); }
else{ config1ToConfig2(); }
if(!isCoordsFreeOnBoard()){
if(presentConfig==1){config2ToConfig1();}
else{config1ToConfig2();}
}
// finally update the board
updateBoard();
}
void IBlock::anticlockwise() { clockwise(); }