Untitled
#include <SFML/Graphics.hpp> #include <cstdlib> // std::rand, std::srand #include <ctime> // std::time #include "Tetromino.hpp" using namespace sf; extern const int N; // Sử dụng biến toàn cục đã khai báo trong Game.cpp Point a[4], b[4], c[4]; int figures[7][4] = { 1,3,5,7, // I 2,4,5,7, // Z 3,5,4,6, // S 3,5,4,7, // T 2,3,5,7, // L 3,5,7,6, // J 2,3,4,5, // O }; void resetTetromino(int& colorNum, int& nextColorNum, int& nextTemo) { colorNum = 1 + rand() % 7; int n = rand() % 7; int offset = rand() % 6; 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 checkTetromino(int field[23][10]) { for (int i = 0; i < 4; i++) { if (a[i].x < 0 || a[i].x >= N || a[i].y >= 23) return false; else if (field[a[i].y][a[i].x]) return false; } return true; } bool isDraw() { for (int i = 0; i < 4; i++) if (a[i].y < 3) return false; return true; } bool checkI() { for (int i = 0; i < 4; i++) { if (c[i].y != 1) return false; } return true; } bool checkO() { return (c[0].y == 0 && c[1].y == 1 && c[2].y == 0 && c[3].y == 1); }
Leave a Comment