Untitled
unknown
plain_text
18 days ago
1.2 kB
2
Indexable
Never
#include "Tetromino.h" #include <cstdlib> Tetromino::Tetromino() { generateNext(); } void Tetromino::generateNext() { int n = rand() % 7; int offset = rand() % 6; colorNum = 1 + rand() % 7; for (int i = 0; i < 4; i++) { a[i].y = figures[n][i] % 2; a[i].x = figures[n][i] / 2 + offset; } nextColorNum = 1 + rand() % 7; nextTemo = rand() % 7; for (int i = 0; i < 4; i++) { c[i].y = figures[nextTemo][i] % 2; c[i].x = figures[nextTemo][i] / 2; } } bool Tetromino::checkCollision(int field[23][10]) { for (int i = 0; i < 4; i++) { if (a[i].x < 0 || a[i].x >= 10 || a[i].y >= 23 || field[a[i].y][a[i].x]) { return false; } } return true; } void Tetromino::rotate() { Point p = a[1]; for (int i = 0; i < 4; i++) { int x = a[i].y - p.y; int y = a[i].x - p.x; a[i].x = p.x - x; a[i].y = p.y + y; } } void Tetromino::move(int dx) { for (int i = 0; i < 4; i++) { b[i] = a[i]; a[i].x += dx; } } void Tetromino::drop() { for (int i = 0; i < 4; i++) { b[i] = a[i]; a[i].y += 1; } }
Leave a Comment