summaryrefslogtreecommitdiff
path: root/noncore/games/mindbreaker/mindbreaker.h
blob: 3132e800ae1e354d94f65bc49a26164fd13dd4df (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**********************************************************************
** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
**
** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/

#ifndef MINDBREAKER_H
#define MINDBREAKER_H

#include <qwidget.h>
#include <qmainwindow.h>
#include <qimage.h>
#include <qvector.h>
#include <qcanvas.h>
#include <qlabel.h>

static const int panel_height = 26;
static const int panel_width = 180;

static const int title_height = 25;
static const int title_width = 180;

static const int bin_margin = 10;
static const int peg_size = 20;
static const int answerpeg_size = 13;

static const int first_peg_x_diff = 21;
static const int first_peg_y_diff = ((panel_height - peg_size) >> 1);
static const int peg_spacing = 30;

static const int answerpegx = 152;
static const int answerpegy = 2;
static const int answerpeg_diff = 9;

static const int board_height = (title_height + (panel_height * 9));
static const int board_width = (panel_width + (bin_margin * 2) + peg_size);

class Peg;
class QToolButton;
class QTimer;

class MindBreakerBoard : public QCanvasView // QWidget
{
    Q_OBJECT
public:
    MindBreakerBoard(QWidget *parent=0, const char *name=0, int wFlags=0 );
    ~MindBreakerBoard();

    void getScore(int *, int *);

    void resizeEvent(QResizeEvent*);
    void fixSize();

signals:
    void scoreChanged(int, int);

public slots:
    void clear();
    void resetScore();

private slots:
    void doFixSize();

protected:
    void contentsMousePressEvent(QMouseEvent *);
    void contentsMouseMoveEvent(QMouseEvent *);
    void contentsMouseReleaseEvent(QMouseEvent *);

private:
    QCanvas cnv;

    void readConfig();
    void writeConfig();

    void drawBackground();
    void checkGuess();
    void checkScores();
    void placeGuessPeg(int pos, int pegId);

    QImage panelImage;
    QImage titleImage;

    Peg *moving;
    Peg *current_highlight;
    QPoint moving_pos;

    // the game stuff 
    int answer[4];
    int current_guess[4];
    int past_guesses[4*9];
    int current_go;

    int null_press;
    QPoint null_point;
    bool copy_press;
    Peg *copy_peg;
    bool game_over;

    int total_turns;
    int total_games;

    QTimer *widthTimer;
};

class MindBreaker : public QMainWindow // QWidget
{
    Q_OBJECT
public:
    MindBreaker(QWidget *parent=0, const char *name=0, int wFlags=0 );
    static QString appName() { return QString::fromLatin1("mindbreaker"); }
public slots:
    void setScore(int, int);

protected:
    void resizeEvent( QResizeEvent * );

private:
    QCanvas canvas;
    MindBreakerBoard *board;
    QToolButton *score;

};


#endif