int main() { InitGraphics(800,600); // inicjalizuj okno graficzne settextstyle(DEFAULT_FONT, HORIZ_DIR, 2); // styl tekstu dla calej gry if(SaveEmpty() == 1) MakePlaceholderSave(); // DEKLARACJA ZMIENNYCH: int X = getmaxx(); // maxymalna szerokosc okna graficznego int Y = getmaxy(); // maksymalna wysokosc okna graficznego char mainMenu[4][40] = { {"Korwin kontra Lewacy z Marsa"}, {"Nowa Gra"}, {"Kontynuuj"}, {"Wyjdz"} }; // tablica z elementami menu glownego int chosen; // zmienna przechowujaca wybrana opcje bool gameOn = 1; // status programu; doyslnie 1 - dziala, 0 - zakonczony int diff_level; // poziom trudnosci gry do { cleardevice(); chosen = Menu(mainMenu, 3, X/2, Y/2); switch(chosen) { case 1: ChooseDifficulty(&diff_level,X/2,Y/2); new_game(diff_level, X, Y, 0); break; case 2: if(SaveEmpty() == 1) { DisplayNoGameSaved(X/2, Y/2); } else new_game(diff_level, X, Y, 1); break; case 3: gameOn = 0; break; } }while(gameOn == 1); }
void ScriptInstance::Save() { ScriptObject::ActiveInstance active(this); /* Don't save data if the script didn't start yet or if it crashed. */ if (this->engine == NULL || this->engine->HasScriptCrashed()) { SaveEmpty(); return; } HSQUIRRELVM vm = this->engine->GetVM(); if (this->is_save_data_on_stack) { _script_sl_byte = 1; SlObject(NULL, _script_byte); /* Save the data that was just loaded. */ SaveObject(vm, -1, SQUIRREL_MAX_DEPTH, false); } else if (!this->is_started) { SaveEmpty(); return; } else if (this->engine->MethodExists(*this->instance, "Save")) { HSQOBJECT savedata; /* We don't want to be interrupted during the save function. */ bool backup_allow = ScriptObject::GetAllowDoCommand(); ScriptObject::SetAllowDoCommand(false); try { if (!this->engine->CallMethod(*this->instance, "Save", &savedata, MAX_SL_OPS)) { /* The script crashed in the Save function. We can't kill * it here, but do so in the next script tick. */ SaveEmpty(); this->engine->CrashOccurred(); return; } } catch (Script_FatalError e) { /* If we don't mark the script as dead here cleaning up the squirrel * stack could throw Script_FatalError again. */ this->is_dead = true; this->engine->ThrowError(e.GetErrorMessage()); this->engine->ResumeError(); SaveEmpty(); /* We can't kill the script here, so mark it as crashed (not dead) and * kill it in the next script tick. */ this->is_dead = false; this->engine->CrashOccurred(); return; } ScriptObject::SetAllowDoCommand(backup_allow); if (!sq_istable(savedata)) { ScriptLog::Error(this->engine->IsSuspended() ? "This script took too long to Save." : "Save function should return a table."); SaveEmpty(); this->engine->CrashOccurred(); return; } sq_pushobject(vm, savedata); if (SaveObject(vm, -1, SQUIRREL_MAX_DEPTH, true)) { _script_sl_byte = 1; SlObject(NULL, _script_byte); SaveObject(vm, -1, SQUIRREL_MAX_DEPTH, false); this->is_save_data_on_stack = true; } else { SaveEmpty(); this->engine->CrashOccurred(); } } else { ScriptLog::Warning("Save function is not implemented"); _script_sl_byte = 0; SlObject(NULL, _script_byte); } }