summaryrefslogtreecommitdiffstats
path: root/katomic/feld.h
blob: 668dbdf22654eee20e084164ca46862c45307f29 (plain)
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
110
111
112
113
114
115
116
117
/****************************************************************
**
** Definition of Feld class,
**
****************************************************************/

#ifndef FELD_H
#define FELD_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tqwidget.h>
#include <tqpoint.h>
#include <tqpainter.h>
#include <tqpixmap.h>
#include <tqmessagebox.h>

#include <kscoredialog.h>

#include "atom.h"

#define MAX_UNDO (100)

class KSimpleConfig;
class Molek;

#define FIELD_SIZE 15

class Feld : public TQWidget
{
    Q_OBJECT
  TQ_OBJECT

public:
    Feld (TQWidget *parent=0, const char *name=0);
    ~Feld ();

    enum Direction { None      = 0,
                     MoveUp    = 1,
                     MoveDown  = (-1),
                     MoveLeft  = 2,
                     MoveRight = (-2) };

    void startAnimation (Direction dir);
    void done ();

    void load (const KSimpleConfig& config);

    void setMolek(Molek *_mol) { mol = _mol; }

    void doUndo ();
    void doRedo ();

signals:
    void gameOver(int moves);
    void sendMoves(int moves);
    void enableRedo(bool enable);
    void enableUndo(bool enable);

protected:
    bool checkDone();
    void timerEvent (TQTimerEvent *);
    void paintEvent( TQPaintEvent * );
    void paintMovingAtom();
    void mousePressEvent (TQMouseEvent *);
    void mouseMoveEvent (TQMouseEvent *);
    void emitStatus();

protected:
    struct UndoInfo {
      uint atom;
      int  oldxpos, oldypos;
      int  xpos, ypos;
      Direction dir;
    };

public slots:
	void nextAtom();
        void previousAtom();

private:

    const atom& getAtom(uint index) const;

    void putNonAtom(int, int, Direction, bool brick = false);

    TQPoint *point;
    TQPixmap data;
    TQPixmap sprite;

    Molek *mol;

    uint feld[FIELD_SIZE][FIELD_SIZE];

    // number of movements
    int moves;

    Direction dir;
    int cx, cy;
    int xpos, ypos;
    int anz;
    int frames, framesbak;

    bool anim;
    bool chosen, moving;

    uint undoBegin;
    uint undoSize;
    uint redoSize;
    UndoInfo undo[MAX_UNDO];

    void resetValidDirs();

};

#endif // FELD_H