2 Mancala - A Historical Board Game
3 Copyright (C) 2009-2010 A.H.M.Mahfuzur Rahman 65mahfuz90@gmail.com
4 Copyright (c) 2010 Reto Zingg g.d0b3rm4n@gmail.com
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 // #include <kdebug.h>
33 #include "ThemeManager.h"
36 Board::Board(GameInfo *gameInfo, ThemeManager *theme)
39 setSharedRenderer(theme);
40 m_gameInfo = gameInfo;
42 setElementId("board");
46 qreal posX,posY,width,height,scaleX,scaleY;
48 posX = sceneBoundingRect().x() + sceneBoundingRect().width() * 0.0125; // 0.15
49 posY = sceneBoundingRect().y() + sceneBoundingRect().height() * 0.03; // 0.8
50 width = 1.16 * sceneBoundingRect().width(); // 0.85
51 // height = width / 1.75 ; // 2.5
52 height = 2.6 * sceneBoundingRect().height();
54 scaleX = width / ( boundingRect().width() );
55 scaleY = height / ( boundingRect().height() ) ;
60 // qDebug() << "posX" << posX;
61 // qDebug() << "posY" << posY;
62 // qDebug() << "scaleX" << scaleX;
63 // qDebug() << "scaleY" << scaleY;
64 // qDebug() << "width" << width;
65 // qDebug() << "height" << height;
66 // qDebug() << "boundingRect width" << boundingRect().width();
67 // qDebug() << "boundingRect height" << boundingRect().height();
68 // qDebug() << "sceneBoundingRect().height()" << sceneBoundingRect().height();
69 // qDebug() << "sceneBoundingRect().width()" << sceneBoundingRect().width();
70 // qDebug() << "sceneBoundingRect().y()" << sceneBoundingRect().y();
71 // qDebug() << "sceneBoundingRect().x()" << sceneBoundingRect().x();
76 //kDebug() << "Destructor of Board";
81 void Board::initialSetup(){
86 void Board::createKalahs(){
88 //If the game supports Kalah(store) then create kalah
89 if(m_gameInfo->numKalahs()){
90 m_leftKalah = new Kalah(m_gameInfo, Kalah::Left, this);
91 m_rightKalah = new Kalah(m_gameInfo, Kalah::Right, this);
96 void Board::createCups(){
100 //kDebug() << "---------Total in the list before first push---------: " << m_cups.count();
101 for(int row = 0; row < m_gameInfo->numRows(); row++){
102 for(int column = 0; column < m_gameInfo->numCupsPerRow(); column++){
103 //appending to the list of cup
104 m_cups << new Cup(m_gameInfo, i++ , this);
110 void Board::manipulateStones(QList<Stone*>& currentStoneList){
112 int j = 0 , stonesPerCupInitially = m_gameInfo->initialStonesPerCup();
114 m_stones = currentStoneList;
117 for(int i = 0; i < stonesPerCupInitially ; i++ ){
118 cup->addStone(m_stones[j++]);
125 int Board::findCupIndex(QPointF position){
129 if(cup->shape().contains( cup->mapFromScene(position) )){
137 void Board::updateChildren(int cupIndex,int kalahIndex,int stoneNo){
139 //kDebug() << "Int3 is called";
141 for(int i = 0 ; i < stoneNo ; i++){
142 //Remove from cup a stone
143 Stone *stone = m_cups[cupIndex]->updateStoneList();
145 if(kalahIndex == Kalah::Left){
146 m_leftKalah->updateStoneList(stone);
148 else m_rightKalah->updateStoneList(stone);
154 //It will remove stone from cupIndex and push it to kalah[index] or cup[index]
155 void Board::updateChildren(int cupIndex,int index,bool isCup){
157 Stone* stone = m_cups[cupIndex]->updateStoneList();
163 slotUpdateChildren();
168 void Board::slotUpdateChildren(){
171 m_cups[m_index]->updateStoneList(m_stone);
174 if(m_index == Kalah::Left)
175 m_leftKalah->updateStoneList(m_stone);
176 else m_rightKalah->updateStoneList(m_stone);