Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New_feature: hightlight conflict numbers. #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ void CBlock::print() const {
<< Color::Modifier() << " "
<< Color::Modifier(Color::BOLD, Color::BG_DEFAULT, Color::FG_RED) << PIPE
<< Color::Modifier() << " ";
else if (number.state == State::CONFLICT)
std::cout << Color::Modifier(Color::BOLD, Color::BG_DEFAULT, Color::FG_RED) << number.value
<< Color::Modifier() << " "
<< Color::Modifier(Color::BOLD, Color::BG_DEFAULT, Color::FG_RED) << PIPE
<< Color::Modifier() << " ";
else
std::cout << number.value << " " << Color::Modifier(Color::BOLD, Color::BG_DEFAULT, Color::FG_RED)
<< PIPE << Color::Modifier() << " ";
Expand All @@ -65,6 +70,9 @@ void CBlock::print() const {
if (number.state == State::ERASED)
std::cout << Color::Modifier(Color::BOLD, Color::BG_DEFAULT, Color::FG_GREEN) << number.value
<< Color::Modifier() << " " << PIPE << " ";
else if (number.state == State::CONFLICT)
std::cout << Color::Modifier(Color::BOLD, Color::BG_DEFAULT, Color::FG_RED) << number.value
<< Color::Modifier() << " " << PIPE << " ";
else
std::cout << number.value << " " << PIPE << " ";
}
Expand Down
1 change: 1 addition & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum class State : int
{
INITED = 0,
ERASED,
CONFLICT,
};

enum class KeyMode : int
Expand Down
2 changes: 2 additions & 0 deletions src/i18n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ I18n::Dict english = {
{I18n::Key::CONGRATULATION, "Congratulation! You Win!"},
{I18n::Key::NOT_COMPLETED, "Sorry, not completed."},
{I18n::Key::ASK_DIFFICULTY, "Select difficulty: 1 Easy 2 Normal 3 Hard"},
{I18n::Key::CONFLICT, "Warning! Conflict exists!"}
};
I18n::Dict chinese = {
{I18n::Key::ASK_KEY_MAP, "设置按键模式: 1 WASD 2 VIM"},
Expand All @@ -29,6 +30,7 @@ I18n::Dict chinese = {
{I18n::Key::CONGRATULATION, "恭喜! 你解开了谜题!"},
{I18n::Key::NOT_COMPLETED, "对不起, 还未完成"},
{I18n::Key::ASK_DIFFICULTY, "设置难度: 1简单 2普通 3困难"},
{I18n::Key::CONFLICT, "警告!存在冲突!"}
};

// Default English
Expand Down
1 change: 1 addition & 0 deletions src/i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class I18n {
CONGRATULATION,
NOT_COMPLETED,
ASK_DIFFICULTY,
CONFLICT
};
using Dict = std::map<Key, std::string>;

Expand Down
20 changes: 18 additions & 2 deletions src/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void CScene::init()
bool CScene::setCurValue(const int nCurValue, int &nLastValue)
{
auto point = _map[_cur_point.x + _cur_point.y * 9];
if (point.state == State::ERASED)
if (point.state == State::ERASED || point.state == State::CONFLICT)
{
nLastValue = point.value;
setValue(nCurValue);
Expand All @@ -138,6 +138,12 @@ void CScene::setValue(const int value)
{
auto p = _cur_point;
this->setValue(p, value);
if (!_column_block[_cur_point.x].isValid() || !_row_block[_cur_point.y].isValid() || !_xy_block[_cur_point.y/3][_cur_point.x/3].isValid()){
_map[_cur_point.x + _cur_point.y * 9].state = State::CONFLICT;
}
else {
_map[_cur_point.x + _cur_point.y * 9].state = State::ERASED;
}
}

// 选择count个格子清空
Expand Down Expand Up @@ -260,7 +266,17 @@ void CScene::play()
else
{
_vCommand.push_back(std::move(oCommand)); // XXX: move without move constructor
int is_conflict = 0;
if (!_column_block[_cur_point.x].isValid() || !_row_block[_cur_point.y].isValid() || !_xy_block[_cur_point.y/3][_cur_point.x/3].isValid()) {
_map[_cur_point.x + _cur_point.y * 9].state = State::CONFLICT;
is_conflict = 1;
}
else {
_map[_cur_point.x + _cur_point.y * 9].state = State::ERASED;
}
show();
if (is_conflict)
message(I18n::Instance().Get(I18n::Key::CONFLICT));
continue;
}
}
Expand Down Expand Up @@ -378,7 +394,7 @@ void CScene::generate()
bool CScene::setPointValue(const point_t &stPoint, const int nValue)
{
auto point = _map[stPoint.x + stPoint.y * 9];
if (State::ERASED == point.state)
if (State::ERASED == point.state || State::CONFLICT == point.state)
{
_cur_point = stPoint;
setValue(nValue);
Expand Down