QTfrontend/hedgehogerWidget.cpp
author displacer
Fri, 15 Sep 2006 15:45:30 +0000
changeset 147 52a3c431db8a
parent 140 50ccde437ea1
child 150 d9e8a336195c
permissions -rw-r--r--
maximum number of teams and hedgehogs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
133
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
     1
#include "hedgehogerWidget.h"
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
     2
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
     3
#include <QMouseEvent>
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
     4
#include <QPainter>
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
     5
147
52a3c431db8a maximum number of teams and hedgehogs
displacer
parents: 140
diff changeset
     6
int overallHedgehogs=0;
52a3c431db8a maximum number of teams and hedgehogs
displacer
parents: 140
diff changeset
     7
133
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
     8
CHedgehogerWidget::CHedgehogerWidget(QWidget * parent) :
140
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 134
diff changeset
     9
  QWidget(parent), numHedgehogs(4)
133
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    10
{
147
52a3c431db8a maximum number of teams and hedgehogs
displacer
parents: 140
diff changeset
    11
  overallHedgehogs+=numHedgehogs;
52a3c431db8a maximum number of teams and hedgehogs
displacer
parents: 140
diff changeset
    12
}
52a3c431db8a maximum number of teams and hedgehogs
displacer
parents: 140
diff changeset
    13
52a3c431db8a maximum number of teams and hedgehogs
displacer
parents: 140
diff changeset
    14
CHedgehogerWidget::~CHedgehogerWidget()
52a3c431db8a maximum number of teams and hedgehogs
displacer
parents: 140
diff changeset
    15
{
52a3c431db8a maximum number of teams and hedgehogs
displacer
parents: 140
diff changeset
    16
  overallHedgehogs-=numHedgehogs;
133
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    17
}
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    18
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    19
void CHedgehogerWidget::mousePressEvent ( QMouseEvent * event )
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    20
{
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    21
  if(event->button()==Qt::LeftButton) {
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    22
    event->accept();
147
52a3c431db8a maximum number of teams and hedgehogs
displacer
parents: 140
diff changeset
    23
    if(numHedgehogs < 8 && overallHedgehogs<18) {
52a3c431db8a maximum number of teams and hedgehogs
displacer
parents: 140
diff changeset
    24
      numHedgehogs++;
52a3c431db8a maximum number of teams and hedgehogs
displacer
parents: 140
diff changeset
    25
      overallHedgehogs++;
52a3c431db8a maximum number of teams and hedgehogs
displacer
parents: 140
diff changeset
    26
    }
133
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    27
  } else if (event->button()==Qt::RightButton) {
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    28
    event->accept();
147
52a3c431db8a maximum number of teams and hedgehogs
displacer
parents: 140
diff changeset
    29
    if(numHedgehogs > 3) {
52a3c431db8a maximum number of teams and hedgehogs
displacer
parents: 140
diff changeset
    30
      numHedgehogs--;
52a3c431db8a maximum number of teams and hedgehogs
displacer
parents: 140
diff changeset
    31
      overallHedgehogs--;
52a3c431db8a maximum number of teams and hedgehogs
displacer
parents: 140
diff changeset
    32
    }
133
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    33
  } else {
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    34
    event->ignore();
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    35
    return;
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    36
  }
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    37
  repaint();
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    38
}
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    39
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    40
void CHedgehogerWidget::paintEvent(QPaintEvent* event)
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    41
{
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    42
  QImage image(":/res/hh25x25.png");
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    43
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    44
  QPainter painter(this);
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    45
140
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 134
diff changeset
    46
  for(int i=0; i<numHedgehogs; i++) {
133
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    47
    QRect target(11 * i, i % 2, 25, 25);
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    48
    painter.drawImage(target, image);
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    49
  }
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    50
}
140
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 134
diff changeset
    51
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 134
diff changeset
    52
unsigned char CHedgehogerWidget::getHedgehogsNum()
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 134
diff changeset
    53
{
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 134
diff changeset
    54
  return numHedgehogs;
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 134
diff changeset
    55
}