Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Tetris by
Diff: Block.cpp
- Revision:
- 4:107d1d5a642e
- Parent:
- 3:36de55e63fdf
diff -r 36de55e63fdf -r 107d1d5a642e Block.cpp
--- a/Block.cpp Sat Mar 11 19:50:03 2017 +0000
+++ b/Block.cpp Sat Mar 18 14:45:16 2017 +0000
@@ -3,11 +3,17 @@
#include "playGround.h"
#include "Piece.h"
#include "Field.h"
+#include "Define.h"
+#include <ctime>
+
+// Constructor of the object. Gives the random form and
+// defines the position on the field
Block::Block()
-{
+{
+ srand (clock());
if (nextForm > 6)
- nextForm = rand() % 7;
+ nextForm = (rand() + 1) % 7;
form = nextForm;
nextForm = rand() % 7;
angle = rand() % 4;
@@ -15,10 +21,15 @@
y = -1;
}
+// Destructor of an object
+
Block::~Block()
{
}
+// Check possibility of rotating of a block and
+// rotate it if it is possible
+
void Block::rotateLeft()
{
if ( !CheckRotateLeft() ) {
@@ -39,6 +50,9 @@
}
}
+// Check possibility of moving the block and
+// moves it if it is possible
+
void Block::moveLeft()
{
if ( !CheckLeft() )
@@ -51,6 +65,11 @@
x++;
}
+// Check possibility to move block one level below. Checks both, frame and
+// blocks on the field ( separately ).
+// Returns 1 if it is not possible and
+// 0 if it is possible.
+
bool Block::CheckBottom()
{
int xx, yy;
@@ -67,6 +86,11 @@
return 0;
}
+// Check possibility to move block to the left. Checks both, frame and
+// blocks on the field ( separately ).
+// Returns 1 if it is not possible and
+// 0 if it is possible.
+
bool Block::CheckLeft()
{
int xx, yy;
@@ -83,6 +107,11 @@
return 0;
}
+// Check possibility to move block to the right. Checks both, frame and
+// blocks on the field ( separately ).
+// Returns 1 if it is not possible and
+// 0 if it is possible.
+
bool Block::CheckRight()
{
int xx, yy;
@@ -99,6 +128,11 @@
return 0;
}
+// Check possibility of rotation counter clockwise Checks both, frame and
+// blocks on the field ( separately ).
+// Returns 1 if it is not possible and
+// 0 if it is possible.
+
bool Block::CheckRotateLeft()
{
int xx, yy;
@@ -110,11 +144,16 @@
return 1;
if ( (Piece[form][( abs(angle + 1) ) % 4][xx][yy] != 0) && (( xx + x == 1 ) || ( xx + x == MAXX + 1 )) )
return 1;
- }
+ }
}
return 0;
}
+// Check possibility of rotation clockwise Checks both, frame and
+// blocks on the field ( separately ).
+// Returns 1 if it is not possible and
+// 0 if it is possible.
+
bool Block::CheckRotateRight()
{
int xx, yy;
