Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Piece.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef PIECE_H
#define PIECE_H
#include <QBrush>
#include <vector>
class Piece
{
public:
std::vector<std::vector<int> > PieceArray;
int PieceColor;
int X, Y;
};
#endif // PIECE_H
13 changes: 8 additions & 5 deletions TetrisTask.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ CONFIG += c++17
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
gamefield.cpp \
figures.cpp \
logic.cpp \
main.cpp \
tetris.cpp
mainwindow.cpp

HEADERS += \
gamefield.h \
tetris.h
Piece.h \
figures.h \
logic.h \
mainwindow.h

FORMS += \
tetris.ui
mainwindow.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
Expand Down
84 changes: 84 additions & 0 deletions figures.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include "figures.h"
Figures::Figures()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Блоки Include Отделяем от всего остального пустой строкой

{
}
Figures::~Figures()
{
}
Comment on lines +2 to +7

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Скобки либо везде не переносим (как принято у нас в стиле), либо везде переносим, если принципиально, но всегда в одном стиле. Исправьте во всем проекте в единый стиль.

std::vector<std::vector<int> > Figures::getFigure(int figure, int state) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Методы отделяем друг от друга пустой строкой. Лишний пробел <int> > -> <int>>

if ( figure < 1 ) figure = 1;
else if ( figure > 7 ) figure = 7;
if ( state < 1 ) state = 1;
else if ( state > 4 ) state = 4;
std::vector<std::vector<int> > v;
for ( int i = 0; i < 4; i++ ) {
Comment on lines +9 to +14

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1, 4, 7 и т.д. в коде ниже - магические значения. Что это ? Как понять? Выделите в поля / переменные.

std::vector<int> a;
for ( int j = 0; j < 4; j++ ) {
if ( figure == 1 ) {
a.push_back(Figures::figure1_1[i][j]);
} else if ( figure == 2 ) {
if ( state == 1 ) {
a.push_back(Figures::figure2_1[i][j]);
} else if ( state == 2 ) {
a.push_back(Figures::figure2_2[i][j]);
} else if ( state == 3 ) {
a.push_back(Figures::figure2_3[i][j]);
} else if ( state == 4 ) {
a.push_back(Figures::figure2_4[i][j]);
}
} else if ( figure == 3 ) {
if ( state == 1 ) {
a.push_back(Figures::figure3_1[i][j]);
} else if ( state == 2 ) {
a.push_back(Figures::figure3_2[i][j]);
} else if ( state == 3 ) {
a.push_back(Figures::figure3_3[i][j]);
} else if ( state == 4 ) {
a.push_back(Figures::figure3_4[i][j]);
}
} else if ( figure == 4 ) {
if ( state == 1 ) {
a.push_back(Figures::figure4_1[i][j]);
} else if ( state == 2 ) {
a.push_back(Figures::figure4_2[i][j]);
} else if ( state == 3 ) {
a.push_back(Figures::figure4_3[i][j]);
} else if ( state == 4 ) {
a.push_back(Figures::figure4_4[i][j]);
}
} else if ( figure == 5 ) {
if ( state == 1 ) {
a.push_back(Figures::figure5_1[i][j]);
} else if ( state == 2 ) {
a.push_back(Figures::figure5_2[i][j]);
} else if ( state == 3 ) {
a.push_back(Figures::figure5_3[i][j]);
} else if ( state == 4 ) {
a.push_back(Figures::figure5_4[i][j]);
}
} else if ( figure == 6 ) {
if ( state == 1 ) {
a.push_back(Figures::figure6_1[i][j]);
} else if ( state == 2 ) {
a.push_back(Figures::figure6_2[i][j]);
} else if ( state == 3 ) {
a.push_back(Figures::figure6_3[i][j]);
} else if ( state == 4 ) {
a.push_back(Figures::figure6_4[i][j]);
}
} else if ( figure == 7 ) {
if ( state == 1 ) {
a.push_back(Figures::figure7_1[i][j]);
} else if ( state == 2 ) {
a.push_back(Figures::figure7_2[i][j]);
} else if ( state == 3 ) {
a.push_back(Figures::figure7_1[i][j]);
} else if ( state == 4 ) {
a.push_back(Figures::figure7_2[i][j]);
}
}
Comment on lines +19 to +79

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Весь блок явно должен быть левее по отступам.

}
v.push_back(a);
}
return v;
}
153 changes: 153 additions & 0 deletions figures.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#ifndef FIGURES_H
#define FIGURES_H

#include <vector>
class Figures
Comment on lines +4 to +5

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пустая строка между подключениями и прочим.

{
public:
Figures();
virtual ~Figures();
int figure1_1[4][4] = {
{ 0, 1, 1, 0 },
{ 0, 1, 1, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
};
int figure2_1[4][4] = {
{ 0, 0, 1, 1 },
{ 0, 1, 1, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
};
int figure2_2[4][4] = {
{ 0, 1, 0, 0 },
{ 0, 1, 1, 0 },
{ 0, 0, 1, 0 },
{ 0, 0, 0, 0 }
};
int figure2_3[4][4] = {
{ 0, 0, 1, 1 },
{ 0, 1, 1, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
};
int figure2_4[4][4] = {
{ 0, 1, 0, 0 },
{ 0, 1, 1, 0 },
{ 0, 0, 1, 0 },
{ 0, 0, 0, 0 }
};
int figure3_1[4][4] = {
{ 0, 1, 1, 0 },
{ 0, 1, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 0, 0, 0 }
};
int figure3_2[4][4] = {
{ 0, 1, 1, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
};
int figure3_3[4][4] = {
{ 0, 0, 1, 0 },
{ 0, 0, 1, 0 },
{ 0, 1, 1, 0 },
{ 0, 0, 0, 0 }
};
int figure3_4[4][4] = {
{ 0, 1, 0, 0 },
{ 0, 1, 1, 1 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
};
int figure4_1[4][4] = {
{ 0, 1, 1, 0 },
{ 0, 0, 1, 1 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
};
int figure4_2[4][4] = {
{ 0, 0, 1, 0 },
{ 0, 1, 1, 0 },
{ 0, 1, 0, 0 },
{ 0, 0, 0, 0 }
};
int figure4_3[4][4] = {
{ 0, 1, 1, 0 },
{ 0, 0, 1, 1 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
};
int figure4_4[4][4] = {
{ 0, 0, 1, 0 },
{ 0, 1, 1, 0 },
{ 0, 1, 0, 0 },
{ 0, 0, 0, 0 }
};
int figure5_1[4][4] = {
{ 0, 0, 1, 0 },
{ 0, 1, 1, 1 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
};
int figure5_2[4][4] = {
{ 0, 1, 0, 0 },
{ 0, 1, 1, 0 },
{ 0, 1, 0, 0 },
{ 0, 0, 0, 0 }
};
int figure5_3[4][4] = {
{ 0, 1, 1, 1 },
{ 0, 0, 1, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
};
int figure5_4[4][4] = {
{ 0, 0, 1, 0 },
{ 0, 1, 1, 0 },
{ 0, 0, 1, 0 },
{ 0, 0, 0, 0 }
};
int figure6_1[4][4] = {
{ 0, 1, 1, 0 },
{ 0, 0, 1, 0 },
{ 0, 0, 1, 0 },
{ 0, 0, 0, 0 }
};
int figure6_2[4][4] = {
{ 0, 0, 0, 1 },
{ 0, 1, 1, 1 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
};
int figure6_3[4][4] = {
{ 0, 1, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 1, 1, 0 },
{ 0, 0, 0, 0 }
};
int figure6_4[4][4] = {
{ 0, 1, 1, 1 },
{ 0, 1, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
};
int figure7_1[4][4] = {
{ 1, 1, 1, 1 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
};
int figure7_2[4][4] = {
{ 0, 1, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 1, 0, 0 }
};
std::vector<std::vector<int> > getFigure(int figure, int state);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Методы с большой буквы

protected:
private:
Comment on lines +149 to +150

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем тут эти модификаторы, если они пустые?

};

#endif // FIGURES_H
32 changes: 0 additions & 32 deletions gamefield.cpp

This file was deleted.

36 changes: 0 additions & 36 deletions gamefield.h

This file was deleted.

Loading