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
Block.cpp@0:645509d95b8d, 2017-02-20 (annotated)
- Committer:
- sergun2311
- Date:
- Mon Feb 20 14:14:30 2017 +0000
- Revision:
- 0:645509d95b8d
- Child:
- 1:b4aa36ae11ac
Tetris - Physics
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| sergun2311 | 0:645509d95b8d | 1 | #include "Block.h" |
| sergun2311 | 0:645509d95b8d | 2 | #include "mbed.h" |
| sergun2311 | 0:645509d95b8d | 3 | #include "playGround.h" |
| sergun2311 | 0:645509d95b8d | 4 | #include "Piece.h" |
| sergun2311 | 0:645509d95b8d | 5 | #include "Field.h" |
| sergun2311 | 0:645509d95b8d | 6 | |
| sergun2311 | 0:645509d95b8d | 7 | Block::Block() { |
| sergun2311 | 0:645509d95b8d | 8 | form = rand() % 7; |
| sergun2311 | 0:645509d95b8d | 9 | angle = rand() % 4; |
| sergun2311 | 0:645509d95b8d | 10 | x = 4 + rand() % 2; |
| sergun2311 | 0:645509d95b8d | 11 | y = 0; |
| sergun2311 | 0:645509d95b8d | 12 | } |
| sergun2311 | 0:645509d95b8d | 13 | |
| sergun2311 | 0:645509d95b8d | 14 | Block::~Block() { |
| sergun2311 | 0:645509d95b8d | 15 | |
| sergun2311 | 0:645509d95b8d | 16 | } |
| sergun2311 | 0:645509d95b8d | 17 | |
| sergun2311 | 0:645509d95b8d | 18 | void Block::rotateLeft() { |
| sergun2311 | 0:645509d95b8d | 19 | angle--; |
| sergun2311 | 0:645509d95b8d | 20 | } |
| sergun2311 | 0:645509d95b8d | 21 | |
| sergun2311 | 0:645509d95b8d | 22 | void Block::rotateRight() { |
| sergun2311 | 0:645509d95b8d | 23 | angle++; |
| sergun2311 | 0:645509d95b8d | 24 | } |
| sergun2311 | 0:645509d95b8d | 25 | |
| sergun2311 | 0:645509d95b8d | 26 | bool Block::CheckBottom() |
| sergun2311 | 0:645509d95b8d | 27 | { |
| sergun2311 | 0:645509d95b8d | 28 | int xx, yy; |
| sergun2311 | 0:645509d95b8d | 29 | for ( xx = 0 ; xx < 5 ; xx++ ) { |
| sergun2311 | 0:645509d95b8d | 30 | for (yy = 0 ; yy < 5 ; yy++ ) { |
| sergun2311 | 0:645509d95b8d | 31 | if ( (Piece[form][angle][xx][yy] != 0) |
| sergun2311 | 0:645509d95b8d | 32 | && (Field[y + yy - 1][x + xx - 2] != 0) && |
| sergun2311 | 0:645509d95b8d | 33 | ( y + yy - 3 > 0 ) ) |
| sergun2311 | 0:645509d95b8d | 34 | return 1; |
| sergun2311 | 0:645509d95b8d | 35 | if ( (Piece[form][angle][xx][yy] != 0) && ( yy + y == 13 ) ) |
| sergun2311 | 0:645509d95b8d | 36 | return 1; |
| sergun2311 | 0:645509d95b8d | 37 | } |
| sergun2311 | 0:645509d95b8d | 38 | } |
| sergun2311 | 0:645509d95b8d | 39 | return 0; |
| sergun2311 | 0:645509d95b8d | 40 | } |
