| 1 |
#include "tetris.h" |
| 2 |
#include <sstream> |
| 3 |
using namespace std; |
| 4 |
|
| 5 |
CBlockSet::CBlockSet(const vector<string> &fileNames) |
| 6 |
{ |
| 7 |
if (fileNames.size() < NUMBLOCKS) |
| 8 |
{ |
| 9 |
_THROWEX(ex_illegalArguments, "Too few filenames provided when attempting to load blockset", "CBlockSet", "CBlockSet", "fileNames = {" << &fileNames << "}"); |
| 10 |
} |
| 11 |
|
| 12 |
for (BlockType i = BLOCK_1; i < NUMBLOCKS; i++) |
| 13 |
{ |
| 14 |
int x = static_cast <int> (i); |
| 15 |
blocks[x] = new CBlock(fileNames[i], 0, 0, 0, 0, ZERO_VECTOR, i); |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
CBlockSet::CBlockSet(const string &prefix) |
| 20 |
{ |
| 21 |
for (BlockType i = BLOCK_1; i < NUMBLOCKS; i++) |
| 22 |
{ |
| 23 |
int x = static_cast <int> (i); |
| 24 |
ostringstream ss; |
| 25 |
ss << prefix << "block" << (x+1); |
| 26 |
|
| 27 |
blocks[x] = new CBlock(ss.str(), 0,0,0,0,ZERO_VECTOR, i); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
CBlockSet::CBlockSet(list<CSurface*> &s) |
| 32 |
{ |
| 33 |
if (s.size() != NUMBLOCKS) |
| 34 |
_THROWEX(ex_illegalArguments, "Number of surfaces does not match number of blocks", |
| 35 |
"CBlockSet", "CBlockSet", "s = " << &s); |
| 36 |
|
| 37 |
list<CSurface*>::iterator i2 = s.begin(); |
| 38 |
for (BlockType i = BLOCK_1; i < NUMBLOCKS; i++) |
| 39 |
{ |
| 40 |
int x = static_cast <int> (i); |
| 41 |
blocks[x] = new CBlock( (*i2), 0,0,0,0,ZERO_VECTOR, i); |
| 42 |
i2++; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
CBlockSet::~CBlockSet() |
| 47 |
{ |
| 48 |
for (BlockType i = BLOCK_1; i < NUMBLOCKS; i++) |
| 49 |
{ |
| 50 |
delete blocks[i]; |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
void CBlockSet::loadBlockAnimation(const string &name, CAnimation* anim, BlockType type) |
| 55 |
{ |
| 56 |
blocks[type]->addAnimation(name, anim); |
| 57 |
} |
| 58 |
|
| 59 |
CBlock* CBlockSet::getBlock(int x, int y, int fieldWidth, int fieldHeight, CVector offset, BlockType type) const |
| 60 |
{ |
| 61 |
CBlock* clone = static_cast<CBlock*> (blocks[type])->getClone(x,y,fieldWidth,fieldHeight, offset); |
| 62 |
return clone; |
| 63 |
} |