QTfrontend/hedgehogerWidget.cpp
changeset 150 d9e8a336195c
parent 147 52a3c431db8a
child 153 dc10da2a73f9
--- a/QTfrontend/hedgehogerWidget.cpp	Sat Sep 16 15:15:30 2006 +0000
+++ b/QTfrontend/hedgehogerWidget.cpp	Sat Sep 16 17:24:41 2006 +0000
@@ -3,32 +3,38 @@
 #include <QMouseEvent>
 #include <QPainter>
 
-int overallHedgehogs=0;
+#include "frameTeam.h"
 
 CHedgehogerWidget::CHedgehogerWidget(QWidget * parent) :
-  QWidget(parent), numHedgehogs(4)
+  QWidget(parent)
 {
-  overallHedgehogs+=numHedgehogs;
+  if(parent) {
+    pOurFrameTeams=dynamic_cast<FrameTeams*>(parent->parentWidget());
+  }
+  if(pOurFrameTeams->overallHedgehogs+4>pOurFrameTeams->maxHedgehogsPerGame) {
+    numHedgehogs=pOurFrameTeams->maxHedgehogsPerGame-pOurFrameTeams->overallHedgehogs;
+  } else numHedgehogs=4;
+  pOurFrameTeams->overallHedgehogs+=numHedgehogs;
 }
 
 CHedgehogerWidget::~CHedgehogerWidget()
 {
-  overallHedgehogs-=numHedgehogs;
+  pOurFrameTeams->overallHedgehogs-=numHedgehogs;
 }
 
 void CHedgehogerWidget::mousePressEvent ( QMouseEvent * event )
 {
   if(event->button()==Qt::LeftButton) {
     event->accept();
-    if(numHedgehogs < 8 && overallHedgehogs<18) {
+    if(numHedgehogs < 8 && pOurFrameTeams->overallHedgehogs<18) {
       numHedgehogs++;
-      overallHedgehogs++;
+      pOurFrameTeams->overallHedgehogs++;
     }
   } else if (event->button()==Qt::RightButton) {
     event->accept();
     if(numHedgehogs > 3) {
       numHedgehogs--;
-      overallHedgehogs--;
+      pOurFrameTeams->overallHedgehogs--;
     }
   } else {
     event->ignore();