コード例 #1
0
void GamePlayScene::loadGameState(const std::vector<char> *data) {
	union change {
		int i;
		unsigned char buf[4];
	} itoc;
	itoc.buf[0] = data->at(0);
	itoc.buf[1] = data->at(1);
	itoc.buf[2] = data->at(2);
	itoc.buf[3] = data->at(3);
	loadPuzzle(itoc.i);
	m_sudoku->loadGameFromBuffer(data);

	AbstractCommand *cmd;
	int pos = SUDOKU_SIZE * SUDOKU_SIZE * 3 + 4;

	while (pos < data->size()) {
		cmd = AbstractCommand::loadFromBuffer(this, data, pos);
		m_logStack.push_back(cmd);
		if (cmd->isPuzzleCmd()) {
			m_undoStack.push_back(cmd->clone());
		}
		pos += cmd->getCommandBufSize();
	}

	m_puzzleLayer->resetValues();
	m_inputLayer->setUndoButton(hasSomethingToUndo());
	m_inputLayer->setNumberCompleted();
}
コード例 #2
0
ファイル: game.c プロジェクト: jeremysrand/a2sudoku
bool loadGame(tUpdatePosCallback callback)
{
    bool isValid = false;
    bool result = false;
    FILE *saveFile= fopen(SAVE_GAME_FILE, "rb");
    
    if (saveFile == NULL) {
#ifdef LOAD_GAME_DEBUG
        printf("Cannot open save game file\n");
        cgetc();
#endif
        return false;
    }
    
    if ((fread(&isValid, sizeof(isValid), 1, saveFile) != 1) ||
        (!isValid)) {
        fclose(saveFile);
#ifdef LOAD_GAME_DEBUG
        printf("Save is not valid\n");
        cgetc();
#endif
        return false;
    }
    
    if (fread(&theGame, sizeof(theGame), 1, saveFile) != 1) {
        fclose(saveFile);
        deleteGame();
#ifdef LOAD_GAME_DEBUG
        printf("Unable to read game from save\n");
        cgetc();
#endif
        return false;
    }
    
    theGame.callback = callback;
    
    // The saved start time is an elapsed time.  Convert it back into a start time relative to now.
    if (theGame.startTime != 0xffffffff) {
        theGame.startTime = _systime() - theGame.startTime;
    }
    
    theGame.puzzle = loadPuzzle(saveFile);
    
    fclose(saveFile);
    deleteGame();
    
    if (theGame.puzzle == NULL) {
#ifdef LOAD_GAME_DEBUG
        printf("Unable to read puzzle from save\n");
        cgetc();
#endif
        return false;
    }
    
    return true;
}
コード例 #3
0
ファイル: game.cpp プロジェクト: 0-wiz-0/einstein-puzzle
Game::Game(std::istream &stream)
{
    pleaseWait();

    loadPuzzle(solvedPuzzle, stream);
    loadRules(rules, stream);
    memcpy(savedSolvedPuzzle, solvedPuzzle, sizeof(solvedPuzzle));
    savedRules = rules;
    possibilities = new Possibilities(stream);
    puzzle = new Puzzle(iconSet, solvedPuzzle, possibilities);
    verHints = new VertHints(iconSet, rules, stream);
    horHints = new HorHints(iconSet, rules, stream);
    watch = new Watch(stream);
    hinted = true;
}
コード例 #4
0
ファイル: main.c プロジェクト: mattrajca/sudoku-solver
int main (int argc, const char * argv[]) {
	if (argc != 2) {
		printf("Usage: sudoku /path/to/puzzle.txt\n");
		
		return EXIT_SUCCESS;
	}
	
	char realPath[PATH_MAX + 1];
	char *res = realpath(argv[1], realPath);
	
	if (!res) {
		printf("Invalid puzzle path!\n");
		
		return EXIT_FAILURE;
	}
	
	if (!loadPuzzle(realPath)) {
		printf("Couldn't load the puzzle!\n");
		
		return EXIT_FAILURE;
	}
	
	if (solve(0, 0)) {
		printf("Solution:\n\n");
		
		for (int row = 0; row < kRows; row++) {
			for (int col = 0; col < kCols; col++) {
				printf("%d ", grid[row][col]);
			}
			
			printf("\n");
		}
	}
	else
		printf("No solution!\n");
	
	return EXIT_SUCCESS;
}
コード例 #5
0
ファイル: CTownHandler.cpp プロジェクト: DjWarmonger/vcmi
CFaction * CTownHandler::loadFromJson(const JsonNode &source)
{
	auto  faction = new CFaction();

	faction->name = source["name"].String();

	VLC->modh->identifiers.requestIdentifier ("creature", source["commander"],
		[=](si32 commanderID)
		{
			faction->commander = CreatureID(commanderID);
		});

	faction->creatureBg120 = source["creatureBackground"]["120px"].String();
	faction->creatureBg130 = source["creatureBackground"]["130px"].String();

	faction->nativeTerrain = ETerrainType(vstd::find_pos(GameConstants::TERRAIN_NAMES,
		source["nativeTerrain"].String()));
	int alignment = vstd::find_pos(EAlignment::names, source["alignment"].String());
	if (alignment == -1)
		faction->alignment = EAlignment::NEUTRAL;
	else
		faction->alignment = static_cast<EAlignment::EAlignment>(alignment);

	if (!source["town"].isNull())
	{
		faction->town = new CTown;
		faction->town->faction = faction;
		loadTown(*faction->town, source["town"]);
	}
	else
		faction->town = nullptr;

	if (!source["puzzleMap"].isNull())
		loadPuzzle(*faction, source["puzzleMap"]);

	return faction;
}