Skip to content

Commit c8bb433

Browse files
committed
looks perfect. falling directly in strike were before not detected
1 parent 7da4b4b commit c8bb433

6 files changed

+29
-9
lines changed

GameObject.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class GameObject
3030
virtual ~GameObject();
3131

3232
// load from file - int x, int y, int width, int height, std::string textureID, int numFrames, int callbackID = 0, int animSpeed = 0
33-
virtual void load(std::unique_ptr<LoaderParams> const &pParams) {}
33+
virtual void load(std::unique_ptr<LoaderParams> const &) {}
3434

3535
// draw the object
3636
virtual void draw() = 0;

JewelBoard.cpp

+18-6
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ void JewelBoard::update()
200200
m_model.update();
201201
m_jewelsFalling = false;
202202
bool boardChanged = false;
203+
int totalStrikesLen = 0;
203204
forAllPos([&](BoardPos pos)
204205
{
205206
JewelObject &jo = getJewel(pos);
@@ -211,7 +212,7 @@ void JewelBoard::update()
211212
if (pos.m_row > 0 && !jo.isDying() && (jo.isFalling() || jo.isDead()))
212213
{
213214
m_jewelsFalling = true;
214-
BoardPos const upperPos = BoardPos(pos.m_col, pos.m_row - 1);
215+
BoardPos const upperPos = pos.getAbove();
215216
JewelObject &upper = getJewel(upperPos);
216217
if (!upper.isFalling())
217218
{
@@ -224,23 +225,34 @@ void JewelBoard::update()
224225
upper.getPixel() = getJewelPixel(upperPos);
225226
}
226227
}
227-
228228
}
229229
jo.update();
230230
});
231231

232232
bool scored = false;
233-
if (boardChanged)
233+
//@todo call findMatch on falling jewels which are isStable
234+
//(and all jewels in strike also isStable). And then m_jewelsFalling can be removed
235+
if (/*boardChanged &&*/ !m_jewelsFalling)
234236
{
235237
forAllPos([&](BoardPos pos)
236238
{
237239
JewelObject &jo = getJewel(pos);
238240
if (!jo.isFalling())
239-
scored = m_strike.findMatch(pos, getJewel(pos).getModel().getColor()) || scored;
241+
{
242+
int strikesLen;
243+
strikesLen = m_strike.findMatch(pos, getJewel(pos).getModel().getColor());
244+
totalStrikesLen += strikesLen;
245+
scoreAt(pos, strikesLen);
246+
}
240247
}, false);
248+
if (!m_jewelsFalling && totalStrikesLen == 0)
249+
TheGame::Instance()->getMatch().nextTurn();
241250
}
242-
if (!scored && !m_jewelsFalling)
243-
TheGame::Instance()->getMatch().nextTurn();
251+
}
252+
253+
void JewelBoard::scoreAt(BoardPos pos, int numJewels)
254+
{
255+
244256
}
245257

246258
void JewelBoard::clean()

JewelBoard.h

+7
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ class JewelBoard : public GameObject, public BoardCallback
8686
Board const &getModel() const;
8787

8888
private:
89+
/**
90+
* @brief scoreAt manages the scoring
91+
* @param pos
92+
* @param score
93+
*/
94+
void scoreAt(BoardPos pos, int numJewels);
95+
8996
/**
9097
* Just swap the 2 pointers to the Jewels
9198
*/

JewelObject.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ void JewelObject::resurrect()
132132
{
133133
m_bDying = false;
134134
m_bDead = false;
135+
//@todo we should allow direct strike. fo
135136
getModel().setColor(random() % Jewel::NUM_COLORS);
136137
}
137138

model/Board.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void Board::randomize()
5656
do
5757
{
5858
jewel.setColor(random() % Jewel::NUM_COLORS);
59-
} while (strike.findMatch(pos, jewel.getColor()));
59+
} while (strike.findMatch(pos, jewel.getColor()) > 0);
6060
}, true);
6161
}
6262
#ifdef NDEBUG

model/JewelSwap.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bool JewelSwap::isValid() const
4242
m_valid = false;
4343
for (int i = 0; i < 2; i++)
4444
{
45-
if (strike.findMatch(m_positions[i], m_board.getJewel(m_positions[1 - i]).getColor(), m_positions[1 - i]))
45+
if (strike.findMatch(m_positions[i], m_board.getJewel(m_positions[1 - i]).getColor(), m_positions[1 - i]) > 0)
4646
m_valid = true;
4747
}
4848
m_validated = true;

0 commit comments

Comments
 (0)