Tetris game on mikroTFT touchscreen and LPC1768

Dependencies:   Tetris

Dependents:   Tetris

Revision:
1:b4aa36ae11ac
Parent:
0:645509d95b8d
Child:
2:6b6986c3d2bd
--- a/Block.cpp	Mon Feb 20 14:14:30 2017 +0000
+++ b/Block.cpp	Sat Feb 25 23:52:28 2017 +0000
@@ -3,38 +3,91 @@
 #include "playGround.h"
 #include "Piece.h"
 #include "Field.h"
-    
-Block::Block() {
+
+Block::Block()
+{
     form = rand() % 7;
     angle = rand() % 4;
     x = 4 + rand() % 2;
-    y = 0;
-}      
+    y = -1;
+}
+
+Block::~Block()
+{
+}
 
-Block::~Block() {
-    
+void Block::rotateLeft()
+{
+    if ( angle == 0 )  
+        angle = 3;
+    else
+        angle = ( abs(angle - 1) ) % 4;
 }
-     
-void Block::rotateLeft() {
-    angle--;
-}  
+
+void Block::rotateRight()
+{
+    if ( angle == 3 )  
+        angle = 0;
+    else
+        angle = ( abs(angle + 1) ) % 4;
+}
 
-void Block::rotateRight() {
-    angle++;
-}   
+void Block::moveLeft()
+{
+    if ( !CheckLeft() )
+        x--;
+}
+
+void Block::moveRight()
+{
+    if ( !CheckRight() )
+        x++;
+}
 
 bool Block::CheckBottom()
 {
     int xx, yy;
     for ( xx = 0 ; xx < 5 ; xx++ ) {
-        for (yy = 0 ; yy < 5 ; yy++ )  {        
-            if ( (Piece[form][angle][xx][yy] != 0)   
-                && (Field[y + yy - 1][x + xx - 2] != 0) &&
-                ( y + yy - 3 > 0 ) ) 
-                return 1; 
-            if ( (Piece[form][angle][xx][yy] != 0) && ( yy + y == 13 ) )          
+        for (yy = 0 ; yy < 5 ; yy++ )  {
+            if ( (Piece[form][angle][xx][yy] != 0)
+                    && (Field[y + yy - 1][x + xx - 2] != 0) &&
+                    ( y + yy - 1 > 0 ) )
+                return 1;
+            if ( (Piece[form][angle][xx][yy] != 0) && ( yy + y == 13 ) )
                 return 1;
         }
     }
     return 0;
-}  
+}
+
+bool Block::CheckLeft()
+{
+    int xx, yy;
+    for ( xx = 0 ; xx < 5 ; xx++ ) {
+        for (yy = 0 ; yy < 5 ; yy++ )  {
+            if ( (Piece[form][angle][xx][yy] != 0)
+                    && (Field[y + yy - 1][x + xx - 3] != 0) &&
+                    ( y + yy - 3 > 0 ) )
+                return 1;
+            if ( (Piece[form][angle][xx][yy] != 0) && ( xx + x == 2 )  )
+                return 1;
+        }
+    }
+    return 0;
+}
+
+bool Block::CheckRight()
+{
+    int xx, yy;
+    for ( xx = 0 ; xx < 5 ; xx++ ) {
+        for (yy = 0 ; yy < 5 ; yy++ )  {
+            if ( (Piece[form][angle][xx][yy] != 0)
+                    && (Field[y + yy - 1][x + xx - 1] != 0) &&
+                    ( y + yy - 3 > 0 ) )
+                return 1;
+            if ( (Piece[form][angle][xx][yy] != 0) && ( (xx + x) == 11) ) 
+                return 1;
+        }
+    }
+    return 0;
+}
\ No newline at end of file