Skip to content

Commit

Permalink
Formatting with Google C++ Style
Browse files Browse the repository at this point in the history
  • Loading branch information
Flying-Tom committed Feb 13, 2022
1 parent 2e4b76d commit 03df2e2
Show file tree
Hide file tree
Showing 63 changed files with 2,535 additions and 2,679 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@
Qt >= 5.12

Ubuntu
- `qt5-default`
- `qtmultimedia5`
```
apt update
apt install cmake make g++ qt5-default qtmultimedia5-dev
```

Windows

Expand Down
38 changes: 20 additions & 18 deletions include/bullet/bullet.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
#ifndef BULLET_H
#define BULLET_H
// Copyright 2022 Flying-Tom
#ifndef INCLUDE_BULLET_BULLET_H_
#define INCLUDE_BULLET_BULLET_H_

#include <common.h>
#include <enemy/enemy.h>
#include <map.h>
#include <gamemap.h>

class Bullet : public QObject, public QGraphicsItem {
Q_OBJECT
Q_INTERFACES(QGraphicsItem)
public:
Bullet();
QRectF boundingRect() const override;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
void advance(int phase) override;
enum { Type = UserType + 4 };
int type() const override;
virtual void moveForward();
Q_OBJECT
Q_INTERFACES(QGraphicsItem)
public:
Bullet();
QRectF boundingRect() const override;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
QWidget* widget) override;
void advance(int phase) override;
enum { Type = UserType + 4 };
int type() const override;
virtual void moveForward();

protected:
QImage image;
qreal atk;
qreal speed;
protected:
QImage image;
qreal atk;
qreal speed;
};

#endif // BULLET_H
#endif // INCLUDE_BULLET_BULLET_H_
24 changes: 13 additions & 11 deletions include/bullet/gunbullet.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#ifndef GUNBULLET_H
#define GUNBULLET_H
// Copyright 2022 Flying-Tom
#ifndef INCLUDE_BULLET_GUNBULLET_H_
#define INCLUDE_BULLET_GUNBULLET_H_

#include "bullet.h"
#include "enemy/enemy.h"
#include <bullet/bullet.h>
#include <enemy/enemy.h>

class GunBullet : public Bullet {
public:
GunBullet(qreal atk);
QRectF boundingRect() const override;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
void advance(int phase) override;
void moveForward() override;
public:
explicit GunBullet(qreal atk);
QRectF boundingRect() const override;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
QWidget* widget) override;
void advance(int phase) override;
void moveForward() override;
};

#endif // GUNBULLET_H
#endif // INCLUDE_BULLET_GUNBULLET_H_
30 changes: 16 additions & 14 deletions include/bullet/laser.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
#ifndef LASER_H
#define LASER_H
// Copyright 2022 Flying-Tom
#ifndef INCLUDE_BULLET_LASER_H_
#define INCLUDE_BULLET_LASER_H_

#include "bullet.h"
#include "enemy/enemy.h"
#include <bullet/bullet.h>
#include <enemy/enemy.h>

class Laser : public Bullet {
public:
Laser(GameItem* parent, qreal atk);
~Laser();
QRectF boundingRect() const override;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
void advance(int phase) override;
public:
Laser(GameItem* parent, qreal atk);
~Laser();
QRectF boundingRect() const override;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
QWidget* widget) override;
void advance(int phase) override;

protected:
GameItem* parent;
int counter;
protected:
GameItem* parent;
int counter;
};

#endif // LASER_H
#endif // INCLUDE_BULLET_LASER_H_
42 changes: 22 additions & 20 deletions include/bullet/missile.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
#ifndef MISSILE_H
#define MISSILE_H
// Copyright 2022 Flying-Tom
#ifndef INCLUDE_BULLET_MISSILE_H_
#define INCLUDE_BULLET_MISSILE_H_

#include "bullet.h"
#include <bullet/bullet.h>

class Missile : public Bullet {
public:
Missile(QPointer<GameItem> atkTarget, qreal atk);
~Missile();
QRectF boundingRect() const override;
QPainterPath shape() const override;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
void advance(int phase) override;
void moveForward() override;
void bombing();
public:
Missile(QPointer<GameItem> atkTarget, qreal atk);
~Missile();
QRectF boundingRect() const override;
QPainterPath shape() const override;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
QWidget* widget) override;
void advance(int phase) override;
void moveForward() override;
void bombing();

private:
QPointer<GameItem> atkTarget;
qreal atkAngle;
private:
QPointer<GameItem> atkTarget;
qreal atkAngle;

QGraphicsEllipseItem* bombArea;
bool isBombing;
qreal bombRadius;
QMovie movie;
QGraphicsEllipseItem* bombArea;
bool isBombing;
qreal bombRadius;
QMovie movie;
};

#endif // MISSILE_H
#endif // INCLUDE_BULLET_MISSILE_H_
81 changes: 37 additions & 44 deletions include/common.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#ifndef COMMON_H
#define COMMON_H
// Copyright 2022 Flying-Tom
#ifndef INCLUDE_COMMON_H_
#define INCLUDE_COMMON_H_

class GameItem;
class Enemy;
class Tower;
class Map;
class GameMap;
class InfoPanel;
class Game;
class MainWindow;

#include <qmath.h>
#include <string.h>

#include <QDebug>
#include <QFile>
#include <QGraphicsEllipseItem>
Expand Down Expand Up @@ -40,53 +44,42 @@ class MainWindow;
#include <QVector>
#include <QtWidgets>
#include <iostream>
#include <qmath.h>
#include <set>
#include <string.h>
#include <vector>

template <typename Val>
class GameValue {
private:
Val curValue;
Val maxValue;
private:
Val curValue;
Val maxValue;

public:
GameValue()
{
curValue = Val();
maxValue = Val();
};
GameValue(Val cur, Val max)
{
curValue = cur;
maxValue = max;
}
~GameValue() { }
inline const Val& getCurValue() const { return curValue; };
inline void setCurValue(const Val& newCurValue)
{
curValue = newCurValue;
if (curValue < Val())
curValue = Val();
if (curValue > maxValue)
curValue = maxValue;
};
inline void changeCurValue(Val delta) { setCurValue(curValue + delta); };
inline const Val& getMaxValue() const { return maxValue; };
inline void setMaxValue(const Val& newMaxValue) { maxValue = newMaxValue; };
public:
GameValue() {
curValue = Val();
maxValue = Val();
}
GameValue(Val cur, Val max) {
curValue = cur;
maxValue = max;
}
~GameValue() {}
inline const Val& getCurValue() const { return curValue; }
inline void setCurValue(const Val& newCurValue) {
curValue = newCurValue;
if (curValue < Val()) curValue = Val();
if (curValue > maxValue) curValue = maxValue;
}
inline void changeCurValue(Val delta) { setCurValue(curValue + delta); }
inline const Val& getMaxValue() const { return maxValue; }
inline void setMaxValue(const Val& newMaxValue) { maxValue = newMaxValue; }
};

class InfoMsg : public QWidget {
public:
InfoMsg(QWidget* parent)
: QWidget(parent) {};
void paintEvent(QPaintEvent* e) override
{
Q_UNUSED(e)
QPainter p(this);
p.drawImage(QRectF(-10, -10, 358, 242), QImage(":/images/messagebox.png"));
};
public:
explicit InfoMsg(QWidget* parent) : QWidget(parent) {}
void paintEvent(QPaintEvent* e) override {
Q_UNUSED(e)
QPainter p(this);
p.drawImage(QRectF(-10, -10, 358, 242), QImage(":/images/messagebox.png"));
};
};

#endif // COMMON_H
#endif // INCLUDE_COMMON_H_
17 changes: 9 additions & 8 deletions include/enemy/blackwarrior.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#ifndef BLACKWARRIOR_H
#define BLACKWARRIOR_H
// Copyright 2022 Flying-Tom
#ifndef INCLUDE_ENEMY_BLACKWARRIOR_H_
#define INCLUDE_ENEMY_BLACKWARRIOR_H_

#include "enemy.h"
#include "game.h"
#include <enemy/enemy.h>
#include <game.h>

class BlackWarrior : public Enemy {
public:
BlackWarrior(Game* game, QList<QPointF>& path);
QPainterPath shape() const override;
public:
BlackWarrior(Game* game, QList<QPointF>* path);
QPainterPath shape() const override;
};

#endif // BLACKWARRIOR_H
#endif // INCLUDE_ENEMY_BLACKWARRIOR_H_
19 changes: 10 additions & 9 deletions include/enemy/cowardplane.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#ifndef COWARDPLANE_H
#define COWARDPLANE_H
// Copyright 2022 Flying-Tom
#ifndef INCLUDE_ENEMY_COWARDPLANE_H_
#define INCLUDE_ENEMY_COWARDPLANE_H_

#include "enemy.h"
#include "game.h"
#include <enemy/enemy.h>
#include <game.h>

class CowardPlane : public Enemy {
public:
CowardPlane(Game* game, QList<QPointF>& path);
QPainterPath shape() const override;
void advance(int phase) override;
public:
CowardPlane(Game* game, QList<QPointF>* path);
QPainterPath shape() const override;
void advance(int phase) override;
};

#endif // COWARDPLANE_H
#endif // INCLUDE_ENEMY_COWARDPLANE_H_
21 changes: 11 additions & 10 deletions include/enemy/dragon.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#ifndef DRAGON_H
#define DRAGON_H
// Copyright 2022 Flying-Tom
#ifndef INCLUDE_ENEMY_DRAGON_H_
#define INCLUDE_ENEMY_DRAGON_H_

#include "enemy.h"
#include "game.h"
#include <enemy/enemy.h>
#include <game.h>

class Dragon : public Enemy {
public:
Dragon(Game* game, QList<QPointF>& path);
~Dragon();
QRectF boundingRect() const override;
QPainterPath shape() const override;
public:
Dragon(Game* game, QList<QPointF>* path);
~Dragon();
QRectF boundingRect() const override;
QPainterPath shape() const override;
};

#endif // DRAGON_H
#endif // INCLUDE_ENEMY_DRAGON_H_
Loading

0 comments on commit 03df2e2

Please sign in to comment.