Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

LevelStatus Class Reference

Inheritance diagram for LevelStatus:

Inheritance graph
[legend]
Collaboration diagram for LevelStatus:

Collaboration graph
[legend]

Detailed Description

Status of level after a game.

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)
GameStatecreatePoster () 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)


Constructor & Destructor Documentation

LevelStatus::LevelStatus  ) 
 

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 }


Member Function Documentation

int LevelStatus::compareToBest  ) 
 

Compares this player and the best one.

Returns:
-1 (this is worse), 0 (equals) or 1 (the best)

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 }

GameState * LevelStatus::createPoster  )  const
 

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 }

std::string LevelStatus::getBestAuthor  )  const [inline]
 

Definition at line 29 of file LevelStatus.h.

00029 { return m_bestAuthor; }

int LevelStatus::getBestMoves  )  const [inline]
 

Definition at line 28 of file LevelStatus.h.

00028 { return m_bestMoves; }

std::string LevelStatus::getSolutionFilename const std::string &  codename  )  [static]
 

Definition at line 72 of file LevelStatus.cpp.

00073 {
00074     return "solved/" + codename + ".lua";
00075 }

bool LevelStatus::isComplete  )  const [inline]
 

Definition at line 33 of file LevelStatus.h.

00033 { return m_complete; }

void LevelStatus::prepareRun const std::string &  codename,
const std::string &  poster,
int  bestMoves,
const std::string &  bestAuthor
 

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 }

void LevelStatus::readMoves const std::string &  moves  ) 
 

Definition at line 54 of file LevelStatus.cpp.

00055 {
00056     m_savedMoves = savedMoves;
00057 }

std::string LevelStatus::readSolvedMoves  ) 
 

Read the best solution.

Returns:
saved_moves or empty string

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 }

void LevelStatus::setComplete  )  [inline]
 

Definition at line 32 of file LevelStatus.h.

00032 { m_complete = true; }

void LevelStatus::setRunning bool  value  )  [inline]
 

Definition at line 34 of file LevelStatus.h.

00034 { m_wasRunning = value; }

bool LevelStatus::wasRunning  )  const [inline]
 

Definition at line 35 of file LevelStatus.h.

00035 { return m_wasRunning; }

void LevelStatus::writeSolvedMoves const std::string &  moves  ) 
 

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 }


The documentation for this class was generated from the following files:
Generated on Wed Jun 1 09:55:47 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2