-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.h
109 lines (97 loc) · 2.25 KB
/
mainwindow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPainter>
#include <QObject>
#include <QTime>
#include <QList>
#include <QKeyEvent>
#include <QRandomGenerator>
#include <QTimerEvent>
#include <QFrame>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QDateTime>
#include <QLabel>
#include <QLCDNumber>
#include <QSizePolicy>
#include <QProgressBar>
#include <QDial>
const int BOARD_WIDTH = 800;
const int BOARD_HEIGHT = 600;
const int MAX_TOXICITY = 30000;
struct Point
{
int x, y;
Point();
Point(int new_x, int new_y);
~Point() = default;
friend inline bool operator ==(const Point& lhs, const Point& rhs) {
return (lhs.x == rhs.x && lhs.y == rhs.y);
}
};
class GameBoard : public QFrame
{
Q_OBJECT
public:
GameBoard(QWidget* parent = nullptr);
};
struct Segment : public Point
{
int type;
enum types {none = 0, head, body, fat};
Segment();
Segment(int new_x, int new_y, int new_type);
~Segment() = default;
};
class MainWindow : public QWidget
{
Q_OBJECT
private:
GameBoard* board_;
QLCDNumber* shit_eaten_counter_;
QLCDNumber* score_counter_;
QLCDNumber* speed_counter_;
//QDial* speed_knob_;
QProgressBar* toxic_bar_;
const int DOT_SIZE = 10;
int period_ = 100;
QList<Segment> segments;
QList<Point> shit_list;
Point tomato_location;
QRandomGenerator rannd;
QImage head;
QImage segment;
QImage tomato;
QImage fat;
QImage shit;
int timer_;
int state_;
int score_;
int toxicity_;
QPoint offset_;
enum states {ST_IN_GAME = 1, ST_PAUSED, ST_GAMOVER};
int direction_;
enum directions {D_UP = 1, D_DOWN, D_LEFT, D_RIGHT};
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
void LoadImages();
void StartGame();
void PlaceTomato();
void CheckTomato();
void CheckShit();
void CheckCollision();
void Draw();
void Move();
void ShowGameOver(QPainter& qp);
void DrawSegment(QPainter& qp, const Segment& seg);
protected:
void timerEvent(QTimerEvent* event);
void paintEvent(QPaintEvent* event);
void keyPressEvent(QKeyEvent* event);
void resizeEvent(QResizeEvent* event);
};
#endif // MAINWINDOW_H