-
Notifications
You must be signed in to change notification settings - Fork 14
Tetris_Blinova #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Tetris_Blinova #14
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| QT += core gui | ||
|
|
||
| greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | ||
|
|
||
| CONFIG += c++17 | ||
|
|
||
| # You can make your code fail to compile if it uses deprecated APIs. | ||
| # In order to do so, uncomment the following line. | ||
| #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 | ||
|
|
||
| SOURCES += \ | ||
| figure.cpp \ | ||
| griddrawer.cpp \ | ||
| main.cpp \ | ||
| mainwindow.cpp \ | ||
| nextfigure.cpp \ | ||
| tetris.cpp | ||
|
|
||
| HEADERS += \ | ||
| figure.h \ | ||
| griddrawer.h \ | ||
| mainwindow.h \ | ||
| nextfigure.h \ | ||
| tetris.h | ||
|
|
||
| # Default rules for deployment. | ||
| qnx: target.path = /tmp/$${TARGET}/bin | ||
| else: unix:!android: target.path = /opt/$${TARGET}/bin | ||
| !isEmpty(target.path): INSTALLS += target |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| #include "figure.h" | ||
|
|
||
| figure::figure() | ||
| { | ||
| m_x = 0; | ||
| m_y = 0; | ||
| m_condition = 0; | ||
| m_color = QColor(Qt::red); | ||
| m_data = {{{1}}}; | ||
| } | ||
|
|
||
| int figure::x() const | ||
| { | ||
| return m_x; | ||
| } | ||
|
|
||
| void figure::setX(int newX) | ||
| { | ||
| m_x = newX; | ||
| } | ||
|
|
||
| int figure::y() const | ||
| { | ||
| return m_y; | ||
| } | ||
|
|
||
| void figure::setY(int newY) | ||
| { | ||
| m_y = newY; | ||
| } | ||
|
|
||
| int figure::condition() const | ||
| { | ||
| return m_condition; | ||
| } | ||
|
|
||
| void figure::setCondition(int newCondition) | ||
| { | ||
| m_condition = newCondition; | ||
| } | ||
|
|
||
| QColor figure::color() const | ||
| { | ||
| return m_color; | ||
| } | ||
|
|
||
| void figure::setColor() | ||
| { | ||
| QRandomGenerator *rg = QRandomGenerator::global(); | ||
| int randomNumber = rg->bounded(0, 6); | ||
|
|
||
| QVector<QColor> colorRand = {Qt::red, Qt::blue, Qt::green, Qt::yellow, Qt::cyan, Qt::magenta}; | ||
| m_color = colorRand[randomNumber]; | ||
| } | ||
|
|
||
| void figure::setSpecificColor(QColor color_) | ||
| { | ||
| m_color = color_; | ||
| } | ||
|
|
||
| QVector<QVector<QVector<bool>>> figure::data() const | ||
| { | ||
| return m_data; | ||
| } | ||
|
|
||
| void figure::setData() | ||
| { | ||
| QRandomGenerator *rg = QRandomGenerator::global(); | ||
| int randomNumber = rg->bounded(1, 7); | ||
| switch (randomNumber) { | ||
| case 1: | ||
| m_data = {{{1,1,1,1}}, {{1},{1},{1},{1}}}; | ||
| break; | ||
| case 2: | ||
| m_data = {{{1,0},{1,1},{1,0}}, | ||
| {{1,1,1},{0,1,0}}, | ||
| {{0,1},{1,1},{0,1}}, | ||
| {{0,1,0},{1,1,1}} | ||
| }; | ||
| break; | ||
| case 3: | ||
| m_data = {{{1,1},{1,0},{1,0}}, | ||
| {{1,1,1},{0,0,1}}, | ||
| {{0,1},{0,1},{1,1}}, | ||
| {{1,0,0},{1,1,1}} | ||
| }; | ||
| break; | ||
| case 4: | ||
| m_data = {{{1,1},{0,1},{0,1}}, | ||
| {{0,0,1},{1,1,1}}, | ||
| {{1,0},{1,0},{1,1}}, | ||
| {{1,1,1},{1,0,0}} | ||
| }; | ||
| break; | ||
| case 5: | ||
| m_data = {{{1,0},{1,1},{0,1}}, | ||
| {{0,1,1},{1,1,0}} | ||
| }; | ||
| break; | ||
| case 6: | ||
| m_data = {{{0,1},{1,1},{1,0}}, | ||
| {{1,1,0},{0,1,1}} | ||
| }; | ||
| break; | ||
| default: | ||
| break; | ||
|
Comment on lines
+71
to
+106
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. case должны быть на одну табуляцию правее от switch |
||
| } | ||
| } | ||
|
|
||
| void figure::setSpecificData(QVector<QVector<QVector<bool>>> data_){ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Постфикс "_" для параметров методов не нужен. Пробел перед { (касается всего проекта, унифицируйте написание скобок и поправьте отступы) |
||
| m_data = data_; | ||
| } | ||
|
|
||
| void figure::nextCondition(){ | ||
| setCondition((condition() + 1)%data().size()); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Отделить пробелами % |
||
| } | ||
|
|
||
| void figure::prevCondition(){ | ||
| setCondition((condition() + data().size()- 1)%data().size()); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #ifndef FIGURE_H | ||
| #define FIGURE_H | ||
|
|
||
| #include <QObject> | ||
| #include <QColor> | ||
| #include <QVector> | ||
| #include <QRandomGenerator> | ||
|
|
||
| class figure : public QObject | ||
| { | ||
| Q_OBJECT | ||
| Q_PROPERTY(int x READ x WRITE setX) | ||
| Q_PROPERTY(int y READ y WRITE setY) | ||
| Q_PROPERTY(int condition READ condition WRITE setCondition) | ||
|
|
||
| public: | ||
| figure(); | ||
| int x() const; | ||
| void setX(int newX); | ||
| int y() const; | ||
|
Comment on lines
+18
to
+20
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Методы все же с глаголов начинаются. Можно было бы оставить x и у, если бы мы говорили про структуры, но для классов лучше getX getY |
||
| void setY(int newY); | ||
| int condition() const; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getСondition |
||
| void setCondition(int newCondition); | ||
| QColor color() const; | ||
| void setColor(); | ||
| QVector<QVector<QVector<bool>>> data() const; | ||
| void setData(); | ||
| void setSpecificColor(QColor color_); | ||
| void setSpecificData(QVector<QVector<QVector<bool>>> data_); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Постфикс _ не нужен, как и в строке выше. |
||
| void nextCondition(); | ||
| void prevCondition(); | ||
|
Comment on lines
+30
to
+31
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Методы почти всегда что-то делают -> именуются глаголами или начинаются с глаголов. |
||
|
|
||
| private: | ||
| int m_x; | ||
| int m_y; | ||
| int m_condition; | ||
| QColor m_color; | ||
| QVector<QVector<QVector<bool>>> m_data; | ||
|
Comment on lines
+34
to
+38
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. В нашей нотации (по google) приватные поля именуются все же с постфиксом "_". |
||
| }; | ||
|
|
||
| #endif // FIGURE_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #include "griddrawer.h" | ||
|
|
||
| GridDrawer::GridDrawer(QWidget *parent):QWidget(parent), m_columns(3), m_rows(4), m_sizeCell(30) | ||
| { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Раз начали внутри кода не переносить скобки, то они не переносятся и в методах. Везде в одном стиле. |
||
| for (int i = 0; i < m_columns; i++) { | ||
| QVector<QColor> cellsRow = {}; | ||
| for (int j = 0; j < m_rows; j++) { | ||
| cellsRow.push_back(Qt::gray); | ||
| } | ||
| cellColors.push_back(cellsRow); | ||
| } | ||
| } | ||
|
|
||
| int GridDrawer::columns() const | ||
| { | ||
| return m_columns; | ||
| } | ||
|
|
||
| void GridDrawer::setColumns(int newColumns) | ||
| { | ||
| m_columns = newColumns; | ||
| cellColors.clear(); | ||
| for (int i = 0; i < m_columns; i++) { | ||
| QVector<QColor> cellsRow = {}; | ||
| for (int j = 0; j < rows(); j++) { | ||
| cellsRow.push_back(Qt::gray); | ||
| } | ||
| cellColors.push_back(cellsRow); | ||
| } | ||
| } | ||
|
|
||
| int GridDrawer::rows() const | ||
| { | ||
| return m_rows; | ||
| } | ||
|
|
||
| void GridDrawer::setRows(int newRows) | ||
| { | ||
| m_rows = newRows; | ||
| cellColors.clear(); | ||
| for (int i = 0; i < columns(); i++) { | ||
| QVector<QColor> cellsRow = {}; | ||
| for (int j = 0; j < m_rows; j++) { | ||
| cellsRow.push_back(Qt::gray); | ||
| } | ||
| cellColors.push_back(cellsRow); | ||
| } | ||
| } | ||
|
|
||
| int GridDrawer::sizeCell() const | ||
| { | ||
| return m_sizeCell; | ||
| } | ||
|
|
||
| void GridDrawer::setSizeCell(int newSizeCell) | ||
| { | ||
| m_sizeCell = newSizeCell; | ||
| } | ||
|
|
||
| QVector<QVector<QColor>> GridDrawer::getCellColors() const | ||
| { | ||
| return cellColors; | ||
| } | ||
|
|
||
| void GridDrawer::setCellColors(const QVector<QVector<QColor> > &newGetCellColors) | ||
| { | ||
| cellColors = newGetCellColors; | ||
| } | ||
|
|
||
| void GridDrawer::draw(QPainter *painter) { | ||
| int cellWidth = m_sizeCell; | ||
| int cellHeight = m_sizeCell; | ||
|
|
||
| for (int i = 0; i < m_columns; i++) { | ||
| for (int j = 0; j < m_rows; j++) { | ||
| painter->setPen(Qt::white); | ||
| painter->setBrush(cellColors[i][j]); | ||
| painter->drawRect(i * cellWidth, j * cellHeight, cellWidth, cellHeight); | ||
| } | ||
| } | ||
| this->update(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #ifndef GRIDDRAWER_H | ||
| #define GRIDDRAWER_H | ||
|
|
||
| #include <QWidget> | ||
| #include <QVector> | ||
| #include <QPainter> | ||
|
|
||
| class GridDrawer : public QWidget { | ||
| Q_OBJECT | ||
| Q_PROPERTY(int columns READ columns WRITE setColumns) | ||
| Q_PROPERTY(int rows READ rows WRITE setRows) | ||
| Q_PROPERTY(int sizeCell READ sizeCell WRITE setSizeCell) | ||
|
|
||
| public: | ||
| GridDrawer(QWidget *parent = 0); | ||
|
|
||
| int columns() const; | ||
| void setColumns(int newColumns); | ||
|
|
||
| int rows() const; | ||
| void setRows(int newRows); | ||
|
|
||
| int sizeCell() const; | ||
| void setSizeCell(int newSizeCell); | ||
|
|
||
| QVector<QVector<QColor> > getCellColors() const; | ||
| void setCellColors(const QVector<QVector<QColor> > &newGetCellColors); | ||
|
|
||
| void draw(QPainter *painter); | ||
|
|
||
| private: | ||
| int m_columns; | ||
| int m_rows; | ||
| int m_sizeCell; | ||
|
Comment on lines
+32
to
+34
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Опять же, в нашей нотации приватные поля именуются не с префиксом "m_", а с постфиксом "_" |
||
| QVector<QVector<QColor>> cellColors; | ||
| }; | ||
|
|
||
| #endif // GRIDDRAWER_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| #include "mainwindow.h" | ||
| #include <QApplication> | ||
|
|
||
| #include "tetris.h" | ||
| int main(int argc, char *argv[]) | ||
| { | ||
| QApplication a(argc, argv); | ||
| MainWindow w; | ||
| w.show(); | ||
|
|
||
| int main(int argc, char *argv[]) { | ||
| QApplication a(argc, argv); | ||
| Tetris w; | ||
| w.show(); | ||
| return a.exec(); | ||
| return a.exec(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Классы с большой буквы.