Definition at line 11 of file LevelStatus.h.
Public Member Functions | |
LevelStatus () | |
void | prepareRun (const std::string &codename, const std::string &poster, int bestMoves, const std::string &bestAuthor) |
GameState * | createPoster () const |
Returns DemoMode or NULL. | |
int | getBestMoves () const |
std::string | getBestAuthor () const |
int | compareToBest () |
Compares this player and the best one. | |
void | setComplete () |
bool | isComplete () const |
void | setRunning (bool value) |
bool | wasRunning () const |
void | readMoves (const std::string &moves) |
std::string | readSolvedMoves () |
Read the best solution. | |
void | writeSolvedMoves (const std::string &moves) |
Write best solution to the file. | |
Static Public Member Functions | |
static std::string | getSolutionFilename (const std::string &codename) |
|
Definition at line 45 of file LevelStatus.cpp. 00046 { 00047 m_bestMoves = -1; 00048 m_complete = false; 00049 m_wasRunning = false; 00050 m_script->registerFunc("status_readMoves", script_status_readMoves); 00051 }
|
|
Compares this player and the best one.
Definition at line 151 of file LevelStatus.cpp. 00152 { 00153 int moves = readSolvedMoves().size(); 00154 int result = 1; 00155 if (m_bestMoves > 0) { 00156 if (m_bestMoves < moves) { 00157 result = -1; 00158 } 00159 else if (m_bestMoves == moves) { 00160 result = 0; 00161 } 00162 } 00163 return result; 00164 }
|
|
Returns DemoMode or NULL.
Definition at line 137 of file LevelStatus.cpp. 00138 { 00139 DemoMode *result = NULL; 00140 if (!m_poster.empty()) { 00141 result = new DemoMode(Path::dataReadPath(m_poster)); 00142 } 00143 return result; 00144 }
|
|
Definition at line 29 of file LevelStatus.h. 00029 { return m_bestAuthor; }
|
|
Definition at line 28 of file LevelStatus.h. 00028 { return m_bestMoves; }
|
|
Definition at line 72 of file LevelStatus.cpp. 00073 { 00074 return "solved/" + codename + ".lua"; 00075 }
|
|
Definition at line 33 of file LevelStatus.h. 00033 { return m_complete; }
|
|
Definition at line 60 of file LevelStatus.cpp. 00062 { 00063 m_complete = false; 00064 m_wasRunning = false; 00065 m_codename = codename; 00066 m_poster = poster; 00067 m_bestMoves = bestMoves; 00068 m_bestAuthor = bestAuthor; 00069 }
|
|
Definition at line 54 of file LevelStatus.cpp. 00055 { 00056 m_savedMoves = savedMoves; 00057 }
|
|
Read the best solution.
Definition at line 88 of file LevelStatus.cpp. 00089 { 00090 m_savedMoves = ""; 00091 00092 Path oldSolution = Path::dataReadPath(getSolutionFilename()); 00093 if (oldSolution.exists()) { 00094 try { 00095 scriptDo("saved_moves=nil"); 00096 scriptInclude(oldSolution); 00097 scriptDo("status_readMoves(saved_moves)"); 00098 } 00099 catch (ScriptException &e) { 00100 LOG_WARNING(e.info()); 00101 } 00102 } 00103 00104 return m_savedMoves; 00105 }
|
|
Definition at line 32 of file LevelStatus.h. 00032 { m_complete = true; }
|
|
Definition at line 34 of file LevelStatus.h. 00034 { m_wasRunning = value; }
|
|
Definition at line 35 of file LevelStatus.h. 00035 { return m_wasRunning; }
|
|
Write best solution to the file. Save moves and models state. Definition at line 112 of file LevelStatus.cpp. 00113 { 00114 std::string prevMoves = readSolvedMoves(); 00115 00116 if (prevMoves.empty() || moves.size() < prevMoves.size()) { 00117 Path file = Path::dataWritePath(getSolutionFilename()); 00118 FILE *saveFile = fopen(file.getNative().c_str(), "w"); 00119 if (saveFile) { 00120 fputs("\nsaved_moves = '", saveFile); 00121 fputs(moves.c_str(), saveFile); 00122 fputs("'\n", saveFile); 00123 fclose(saveFile); 00124 } 00125 else { 00126 LOG_WARNING(ExInfo("cannot save solution") 00127 .addInfo("file", file.getNative()) 00128 .addInfo("moves", moves)); 00129 } 00130 } 00131 }
|