summaryrefslogtreecommitdiffstats
path: root/src/snake.h
blob: b3b84332eadde70dd7b073a175e4a42937ace5b0 (plain) (blame)
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
#ifndef _SNAKE_H_
#define _SNAKE_H_

#include <QList>
#include <QPoint>
#include <QTimer>

class QWidget;
class QPaintEvent;

class Snake;

struct Cell;
struct Ball;
struct Paddle;

class GameCore
{
private:
    QWidget *_widget;
    QTimer *_t;
    int _width, _height;
    QList<Snake*> _snakes;
    QList<Ball*> _balls;
    QList<Paddle*> _paddles;
    int _deaths;
    qint64 _lastMeal;
    qint64 _lastPaddle;
    const Cell **_field;
    const Cell **_field2;

public:
    const Cell *field(int x, int y) const {
        return _field[x + _width * y];
    }
    void setField(int x, int y, const Cell *val);

    int width() const { return _width; }

    int height() const { return _height; }

    GameCore(QWidget *widget);

    virtual ~GameCore();

    void paint(QPaintEvent *event);

    void addFood();

    void scanDir(Snake *snake, int x, int y, const Cell* &what, int &dist);

    void addSnake();

    void addBall();

    void drawPaddleBorders();

    void addBreakoutBlocks();

    void checkPongGameOver();

    void pauseAndResume();
};

#endif