Some code refactoring

This commit is contained in:
2015-06-07 18:24:03 +03:00
parent dec3cecfdb
commit b23d11ae46
2 changed files with 16 additions and 15 deletions

View File

@@ -60,20 +60,21 @@ void generateWordInfo(GridType &grid, std::vector<WordInfo> &winfos){
bool exist = false;
for (size_t j = 0; j < grid.at(0).size(); ++j){
for (size_t i = 0; i < grid.size(); ++i){
if (grid.at(i).at(j) == CELL_CLEAR){
if (((j == 0) || (grid.at(i).at(j - 1) != CELL_CLEAR)) &&
(j != grid.at(0).size() - 1))
if (grid.at(i).at(j+1) == CELL_CLEAR){
if ( grid.at(i).at(j) == CELL_CLEAR ){
if ( ((j == 0) || (grid.at(i).at(j - 1) != CELL_CLEAR)) &&
(j != grid.at(0).size() - 1) )
if ( grid.at(i).at(j+1) == CELL_CLEAR ){
size_t cur_len = 1;
bool cont = true;
while ((j + cur_len < grid.at(0).size()) && cont){
while ( (j + cur_len < grid.at(0).size()) && cont ){
++cur_len;
if (grid.at(i).at(j+cur_len-1) != CELL_CLEAR){
if ( grid.at(i).at(j+cur_len-1) != CELL_CLEAR ){
cont = false;
--cur_len;
}
}
exist = true;
exist = true;
WordInfo t;
t.x = i;
t.y = j;
@@ -83,19 +84,19 @@ void generateWordInfo(GridType &grid, std::vector<WordInfo> &winfos){
winfos.push_back(t);
}
if (((i ==0) || (grid.at(i - 1).at(j) != CELL_CLEAR)) &&
(i != grid.size() - 1))
if (grid.at(i + 1).at(j) == CELL_CLEAR){
if ( ((i ==0) || (grid.at(i - 1).at(j) != CELL_CLEAR)) &&
(i != grid.size() - 1) )
if ( grid.at(i + 1).at(j) == CELL_CLEAR ){
size_t cur_len = 1;
bool cont = true;
while ((i + cur_len < grid.size()) && cont){
++cur_len;
if (grid.at(i+cur_len-1).at(j) != CELL_CLEAR){
cont = false;
cur_len--;
--cur_len;
}
}
exist = true;
exist = true;
WordInfo t;
t.x = i;
t.y = j;
@@ -104,7 +105,7 @@ void generateWordInfo(GridType &grid, std::vector<WordInfo> &winfos){
t.direct = true;
winfos.push_back(t);
}
if (exist){
if ( exist ){
exist = false;
++cur_ind;
}

View File

@@ -68,12 +68,12 @@ void MainFrame::OnbtnPathClick(wxCommandEvent &event) {
wxFileDialog dlgOpen(this, wxT("Открыть файл кроссворда"), wxEmptyString, wxEmptyString,
wxT("Файлы кроссворда (*.cross)|*.cross"), wxFD_OPEN|wxFD_FILE_MUST_EXIST);
if (dlgOpen.ShowModal() == wxID_CANCEL)
if ( dlgOpen.ShowModal() == wxID_CANCEL )
return;
// proceed loading the file chosen by the user;
// this can be done with e.g. wxWidgets input streams:
wxFileInputStream input_stream(dlgOpen.GetPath());
if (!input_stream.IsOk()) {
if ( !input_stream.IsOk() ) {
wxLogError(wxT("Cannot open file ")+dlgOpen.GetPath());
return;
}