Tetris game on mikroTFT touchscreen and LPC1768

Dependencies:   Tetris

Dependents:   Tetris

Revision:
4:107d1d5a642e
Parent:
3:36de55e63fdf
--- 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;