Skip to content

Commit 033fa51

Browse files
committed
displaying kill
1 parent e1137c3 commit 033fa51

6 files changed

+28
-14
lines changed

JewelBoard.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void JewelBoard::createInitialJewelsBoard()
4747

4848
void JewelBoard::kill(BoardPos pos)
4949
{
50-
50+
getJewel(pos).getModel().setColor(Jewel::NO_COLOR);
5151
}
5252

5353
void JewelBoard::load(std::unique_ptr<LoaderParams> const &pParams)

JewelObject.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void JewelObject::load(std::unique_ptr<LoaderParams> const &pParams)
4646
// draw the object to the screen
4747
void JewelObject::draw()
4848
{
49+
if(getModel().getColor() != Jewel::NO_COLOR)
4950
TextureManager::Instance()->drawFrame(m_textureID, (Uint32)m_pixel.getX(), (Uint32)m_pixel.getY(),
5051
m_width, m_height, m_currentRow, getModel().getColor());
5152
//TheGame::Instance()->getRenderer(), m_angle, m_alpha);

model/Board.h

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class Board : public BoardCallback
2525
*/
2626
Board(BoardCallback &callback);
2727

28-
2928
template<class F>
3029
inline void forAllPos(F const &funct)
3130
{

model/JewelStrike.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
#include "JewelStrike.h"
99
#include "Jewel.h"
1010

11-
JewelStrike::JewelStrike(Board &board)
12-
:m_board(board)
11+
JewelStrike::JewelStrike(Board &board, BoardCallback * callback)
12+
:m_board(board), m_callback(callback)
1313
{
1414
}
1515

1616

17+
1718
bool JewelStrike::findMatch(BoardPos newPos, Jewel::COLOR newColor, BoardPos ignorePos) const
1819
{
1920
bool match = false;
@@ -47,10 +48,13 @@ bool JewelStrike::findMatch(BoardPos newPos, Jewel::COLOR newColor, BoardPos ign
4748
}
4849
if (len[0] + len[1] >= MIN_LEN)
4950
{
50-
for (short l = -len[1]; l < len[0]; l++)
51+
if (m_callback)
5152
{
52-
m_board.kill(cur);
53-
cur += directions[d];
53+
for (short l = -len[1]; l < len[0]; l++)
54+
{
55+
m_callback->kill(cur);
56+
cur += directions[d];
57+
}
5458
}
5559
match = true;
5660
}

model/JewelStrike.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@ class JewelStrike
2323
*/
2424
constexpr static short MIN_LEN = 3;
2525

26-
JewelStrike(Board &board);
2726
/**
28-
* @brief findMatch
27+
* @brief JewelStrike
28+
* @param board
29+
* @param callback
30+
*/
31+
JewelStrike(Board &board, BoardCallback * callback = NULL);
32+
33+
/**
34+
* @brief findMatch if callback, its kill() will be called for detected strikes
2935
* @param newPos
3036
* @param newColor
3137
* @param ignorePos in case of a swap, don't check the position color, as for sure it does
@@ -35,7 +41,8 @@ class JewelStrike
3541
bool findMatch(BoardPos newPos, Jewel::COLOR newColor, BoardPos ignorePos = BoardPos()) const;
3642

3743
private:
38-
Board &m_board;
44+
Board& m_board;
45+
BoardCallback* m_callback;
3946
};
4047

4148
#endif // JEWELSTRIKE_H

model/JewelSwap.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ bool JewelSwap::isValid() const
3838
{
3939
if (m_validated)
4040
return m_valid;
41-
JewelStrike strike(m_board);
42-
m_valid = strike.findMatch(m_positions[0], m_board.getJewel(m_positions[1]).getColor(), m_positions[1]);
43-
//order important to avoid shortcut (maybe 2 parallel strikes are formed)
44-
m_valid = strike.findMatch(m_positions[1], m_board.getJewel(m_positions[0]).getColor(), m_positions[0]) || m_valid;
41+
JewelStrike strike(m_board, &m_board);
42+
m_valid = false;
43+
for (int i = 0; i < 2; i++)
44+
{
45+
if (strike.findMatch(m_positions[i], m_board.getJewel(m_positions[1 - i]).getColor(), m_positions[1 - i]))
46+
m_valid = true;
47+
}
4548
m_validated = true;
4649
if (!m_valid)
4750
LOG_DEBUG("Swap " << m_positions[0] << "-" << m_positions[1] <<" not valid because it would not form a strike");

0 commit comments

Comments
 (0)