Skip to content

Commit b020b34

Browse files
committed
fixed #167
1 parent 533348b commit b020b34

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
- [ ] (Online mode) Display countdown timer (40 s), waiting for player's move. Reset it when they make a move.
44
- [ ] Record and list all previous moves and captures (for current match), in a scroll panel.
5-
- [ ] highlight cell color blue after clicking a piece, reset when click srcCell = null
5+
- [x] highlight cell color blue after clicking a piece, reset when click srcCell = null
66
- [ ] write unit tests using googletests
77

88
### (Extras) Standard CJK font paths

src/Cell.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,15 @@ const inline sf::Vector2f &Cell::getPos() const
125125
*/
126126
inline void Cell::highlightActive()
127127
{
128+
this->rec.setFillColor(BABY_BLUE);
128129
}
129130

130131
/**
131132
* Restore the original color
132133
*/
133134
inline void Cell::resetColor()
134135
{
136+
this->rec.setFillColor(DARK_BROWN);
135137
}
136138

137139
} // namespace chk

src/managers/GameManager.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ void chk::GameManager::handleCellTap(const chk::PlayerPtr &hunter, const chk::Pl
296296
{
297297
return;
298298
}
299+
// reset color of all previous active cells
300+
std::for_each(this->blockList.begin(), this->blockList.end(), [](const chk::Block &cell) {
301+
if (cell->getIndex() != -1)
302+
{
303+
cell->resetColor();
304+
}
305+
});
299306
// CHECK IF this cell has a Piece
300307
const short pieceId = this->getPieceFromCell(cell->getIndex());
301308
if (pieceId != -1)
@@ -309,15 +316,6 @@ void chk::GameManager::handleCellTap(const chk::PlayerPtr &hunter, const chk::Pl
309316
}
310317
// OTHERWISE, store it in buffer (for a SIMPLE/CAPTURE move next)!
311318
buffer.addItem(pieceId);
312-
// copy original src cell
313-
int copySrcCell = this->sourceCell.value();
314-
// reset old active cell color
315-
const auto it = std::find_if(this->blockList.begin(), this->blockList.end(),
316-
[&](const chk::Block &cell) { cell->getIndex() == copySrcCell; });
317-
if (it != this->blockList.end())
318-
{
319-
320-
}
321319
this->setSourceCell(cell->getIndex());
322320
cell->highlightActive();
323321
}

src/managers/OnlineGameManager.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,13 @@ inline void OnlineGameManager::handleCellTap(const chk::PlayerPtr &hunter, const
398398
{
399399
return;
400400
}
401-
401+
// reset color of all previous active cells
402+
std::for_each(this->blockList.begin(), this->blockList.end(), [](const chk::Block &cell) {
403+
if (cell->getIndex() != -1)
404+
{
405+
cell->resetColor();
406+
}
407+
});
402408
// CHECK IF this cell has a Piece
403409
const short pieceId = this->getPieceFromCell(cell->getIndex());
404410
if (pieceId != -1)
@@ -413,6 +419,7 @@ inline void OnlineGameManager::handleCellTap(const chk::PlayerPtr &hunter, const
413419
// OTHERWISE, store it in buffer (for a simple move, on next turn)
414420
buffer.addItem(pieceId);
415421
this->setSourceCell(cell->getIndex());
422+
cell->highlightActive();
416423
}
417424
else
418425
{

0 commit comments

Comments
 (0)