4 // A simple game inspired by an emacs module
6 /***************************************************************************
7 * Copyright (c) 2007, Nicolas Roffet *
8 * nicolas-kde@roffet.com *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License for more details. *
21 * You should have received a copy of the GNU General Public License *
22 * along with this program; if not, write to the *
23 * Free Software Foundation, Inc., *
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA *
25 ***************************************************************************/
27 #include "kbbgraphicsitemballrepository.h"
31 #include <QGraphicsScene>
34 #include "kbbgraphicsitemonbox.h"
35 #include "kbbgraphicsitemset.h"
36 #include "kbbscalablegraphicwidget.h"
41 // Constructor / Destructor
44 KBBGraphicsItemBallRepository::KBBGraphicsItemBallRepository(KBBScalableGraphicWidget
* parent
, KBBThemeManager
* themeManager
) : KBBGraphicsItem(KBBScalableGraphicWidget::informationBackground
, parent
->scene(), themeManager
)
47 m_themeManager
= themeManager
;
54 m_ballsOutside
= new KBBGraphicsItemSet(parent
->scene());
58 KBBGraphicsItemBallRepository::~KBBGraphicsItemBallRepository()
60 delete m_ballsOutside
;
69 int KBBGraphicsItemBallRepository::ballToTake() const
71 return m_ballsOutside
->anyItemPosition();
75 void KBBGraphicsItemBallRepository::fillBallsOutside(int placed
)
77 int i
= m_columns
*m_rows
;
78 while ((m_ballsOutside
->count()+placed
)<m_ballToPlace
) {
79 if (!(m_ballsOutside
->containsVisible(i
))) {
80 KBBGraphicsItemOnBox
* b
= new KBBGraphicsItemOnBox(KBBScalableGraphicWidget::playerBall
, m_parent
, m_themeManager
, i
, m_columns
, m_rows
);
81 m_ballsOutside
->insert(b
);
82 b
->setPos(x() + ((i
- m_columns
*m_rows
) / m_height
)*KBBScalableGraphicWidget::RATIO
, y() + ((i
- m_columns
*m_rows
) % m_height
)*KBBScalableGraphicWidget::RATIO
);
89 void KBBGraphicsItemBallRepository::newGame(int columns
, int rows
, int balls
)
94 m_ballsOutside
->clear();
96 m_ballToPlace
= balls
;
97 scale(1./m_width
, 1./m_height
);
103 m_width
= balls
/m_height
;
104 if (balls
% m_height
> 0)
107 scale(m_width
/1., m_height
/1.);
109 setPos((-(m_width
+1)*KBBScalableGraphicWidget::RATIO
), KBBScalableGraphicWidget::RATIO
);
115 void KBBGraphicsItemBallRepository::removeBall(int outsidePosition
)
117 m_ballsOutside
->remove(outsidePosition
);
120 #include "kbbgraphicsitemballrepository.moc"