Skip to content

GO - #1

Open
FrankyShelloy wants to merge 13 commits into
mainfrom
pr
Open

GO#1
FrankyShelloy wants to merge 13 commits into
mainfrom
pr

Conversation

@FrankyShelloy

Copy link
Copy Markdown
Owner

No description provided.

@danillo19 danillo19 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Проверь все на утечки памяти, пули че то никак не удаляются. Давай еще добавим еще одни тип Вражеского Танка камикадзе, который при встрече с игроком взрывается и наносит урон

Comment thread include/EnemyTank.h Outdated
Comment on lines +24 to +26
static constexpr qreal kSpeed = 30.0;
static constexpr qreal kWidth = 32.0;
static constexpr qreal kHeight = 32.0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

что значит тут префикс k? Почему static переменные, а не тупо const или вообще private? Тут инкапсуляция немного хромает

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Comment thread include/EnemyTank.h Outdated
Comment on lines +50 to +57
// Легкий
class LightEnemy : public EnemyTank {
public:
explicit LightEnemy(qreal x, qreal y);
qreal GetSpeed() const override { return 1.5; }
protected:
void UpdatePixmap() override;
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

в отдельные файлы

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Comment thread include/EnemyTank.h Outdated
qreal GetSpeed() const override { return 0.8; }
protected:
void UpdatePixmap() override;
QList<Bullet*> Fire(Direction dir) override;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Почему сырой указатель? А не от Qt или стандартный умный?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Comment thread include/GameScane.h Outdated
Comment on lines +12 to +17
class Tank;
class Wall;
class BrickWall;
class Bullet;
class EnemyTank;
class Bonus;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

лайк

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Comment thread include/GameScane.h Outdated
void UpdateBonuses();

bool IsCollidingWithSolidWall(const QRectF& rect) const;
BrickWall* IsCollidingWithBrickWall(const QRectF& rect) const;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is предполагает возврат true/false, такой метод надо называть FindCollidingBrickWall

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Comment thread src/Tank.cpp Outdated
Comment on lines +93 to +106
switch (m_direction) {
case Direction::Up:
painter.drawLine(center, center, center, center - kTankGunLength);
break;
case Direction::Down:
painter.drawLine(center, center, center, center + kTankGunLength);
break;
case Direction::Left:
painter.drawLine(center, center, center - kTankGunLength, center);
break;
case Direction::Right:
painter.drawLine(center, center, center + kTankGunLength, center);
break;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

давай часть сложных свитчей перепишем на map + lambda или std::function. Суть в чем:

  1. Делаешь мапу/мапы
std::unordered_map<Direction, std::function<...>> painterHandlers;

painterHandlers.put(Direction::Up, [](...) {painter.drawLine(center, center, center, center - kTankGunLength);}) // кладем лямбду

...
  1. Используем:
auto hander = painterHandlers.find(direction)
if handler != painterHandlers.end() { 
    handler(...);
...
}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Comment thread src/Wall.cpp
Comment on lines +26 to +37
painter.setPen(Qt::NoPen);
painter.setBrush(Qt::black);
const struct { int x; int y; } rivets[] = {
{4, 4}, {12, 4}, {4, 12}, {12, 12},
{20, 4}, {28, 4}, {20, 12}, {28, 12},
{4, 20}, {12, 20}, {4, 28}, {12, 28},
{20, 20},{28, 20},{20, 28}, {28, 28}
};
for (const auto& r : rivets) {
painter.drawEllipse(r.x - kRivetRadius, r.y - kRivetRadius,
2 * kRivetRadius, 2 * kRivetRadius);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

вынеси в метод по типу InitRivets и тд

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Comment thread include/GameScene.h

private:

void keyPressEvent(QKeyEvent* event) override;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

а где используется?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

gamescane, enter , выстрел и тд

Comment thread include/GameScene.h
private:

void keyPressEvent(QKeyEvent* event) override;
void keyReleaseEvent(QKeyEvent* event) override;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

вынеси в отдельный контроллер это. Обычно че делают, преобразуют евенты Qt в свои модельные события, по типу GoUp, DirectionUp, PlayerClick и тд. Контроллер это обрабатывает и меняет модель, т.е GameModel

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Comment thread include/Tank.h
Comment on lines +20 to +30
void Update();
void Move();
auto GetFutureRect(Direction dir) const -> QRectF;
auto GetDirection() const -> Direction;


private:
void UpdatePixmap();

Direction m_direction { Direction::Up };
static constexpr qreal kSpeed = 2.0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Танк и модель и вью, себя и рисует и танцует, надо разделить либо вынести в GameScene его отрисовку. В Tank должна быть сущность, по типу скорости, здоровья, урона, брони, логи урона и тд. Отрисовка не его задача.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@danillo19 danillo19 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Так и не увидел удаления пуль, если не согласен, пиши в ответах на комменты мои, порешаем

Comment thread src/Bullet.cpp

#include "GlobalConstants.h"

Bullet::Bullet(qreal x, qreal y, Direction direction, BulletOwner owner)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Скинь замер памяти мне, либо ссылку на доку или скрин дебага объектов, не вижу удаления пуль.

Comment thread src/EnemyTank.cpp
}

void EnemyTank::DrawGun(QPainter& painter, int center, int gunLength) const {
using Handler = std::function<void(QPainter&, int, int)>;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

лайк, но обычно это если переиспользуется switch в нескольких местах, но ок

Comment thread src/GameModel.cpp Outdated
Comment on lines +50 to +58
Bullet* GameModel::AddBullet(std::unique_ptr<Bullet> b) { bullets.push_back(std::move(b)); return bullets.back().get(); }
std::vector<Bullet*> GameModel::GetBullets() const { std::vector<Bullet*> out; out.reserve(bullets.size()); for (const auto& p: bullets) out.push_back(p.get()); return out; }
void GameModel::RemoveBullet(Bullet* b) { auto it = std::find_if(bullets.begin(), bullets.end(), [b](const std::unique_ptr<Bullet>& p){ return p.get() == b; }); if (it != bullets.end()) bullets.erase(it); }
void GameModel::ClearBullets() { bullets.clear(); }
size_t GameModel::GetBulletsCount() const { return bullets.size(); }
Bullet* GameModel::GetBulletAt(size_t i) const { return bullets[i].get(); }

Bullet* GameModel::AddEnemyBullet(std::unique_ptr<Bullet> b) { enemyBullets.push_back(std::move(b)); return enemyBullets.back().get(); }
std::vector<Bullet*> GameModel::GetEnemyBullets() const { std::vector<Bullet*> out; out.reserve(enemyBullets.size()); for (const auto& p: enemyBullets) out.push_back(p.get()); return out; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

форматирование поплыло

Comment thread src/GameScane.cpp Outdated
int type = QRandomGenerator::global()->bounded(0, 4);
std::unique_ptr<EnemyTank> uptr;
switch (type) {
case 0:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

в enum

Comment thread src/GameScane.cpp Outdated
if (m_model) m_model->ModifyScore(delta);
}

void GameScane::keyPressEvent(QKeyEvent* event) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

кажется называется GameScene

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

...

Comment thread src/GameScane.cpp Outdated
Comment on lines +628 to +631
m_livesText->setPlainText(QString("Lives: %1").arg(lives));
m_livesText->setDefaultTextColor(Qt::white);
m_livesText->setFont(QFont("Arial", 16, QFont::Bold));
m_livesText->setPos(5, 5);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

4 строки можно в метод вынести

Comment thread src/TwinShooterEnemy.cpp
if (dir == Direction::Up || dir == Direction::Down) {
qreal bx1 = pos.x() + GetWidth() / 2 - 8;
qreal bx2 = pos.x() + GetWidth() / 2 + 8;
qreal by = (dir == Direction::Up) ? pos.y() - 3 : pos.y() + GetHeight() - 3;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

под такое коммент надо, магия какая то)

@danillo19 danillo19 mentioned this pull request Dec 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants