示例#1
0
        override public void SetPlayed(core.Puzzle puzzle)
        {
            var dbPuzzle = GetPuzzle(puzzle);

            dbPuzzle.LastPlayed = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            connection.Update(dbPuzzle);
        }
示例#2
0
 private static Puzzle CoreToDBPuzzle(core.Puzzle puzzle, int solvedState)
 {
     return(new Puzzle {
         Type = puzzle.level.type.ToString(),
         SolvedConfig = puzzle.level.solved.ToCompactString(),
         InitialConfig = puzzle.initial.ToCompactString(),
         SolvedState = solvedState
     });
 }
示例#3
0
        /// <summary>
        /// if the puzzle is not present in the db, it's because it was never played,
        /// and therefore it's unsolved
        /// </summary>
        /// <param name="puzzle"></param>
        /// <returns></returns>
        override public PuzzleSolvedState GetPuzzleState(core.Puzzle puzzle)
        {
            Puzzle dbPuzzle = GetPuzzle(puzzle);

            if (dbPuzzle == null)
            {
                return(PuzzleSolvedState.Unsolved);
            }
            return(GetState(dbPuzzle.SolvedState));
        }
示例#4
0
        private Puzzle GetPuzzle(core.Puzzle puzzle)
        {
            var config    = puzzle.initial.ToCompactString();
            var typeStr   = puzzle.level.type.ToString();
            var solvedStr = puzzle.level.solved.ToCompactString();

            var result = connection.Query <Puzzle>("SELECT * FROM Puzzle WHERE InitialConfig = ? AND type = ? AND SolvedConfig = ? LIMIT 1",
                                                   config, typeStr, solvedStr);

            return(result.Count() == 0 ? null : result.First());
        }
示例#5
0
 /// <summary>
 /// Updates the solved state of the puzzle in the db
 /// </summary>
 /// <param name="puzzle"></param>
 /// <param name="state"></param>
 override public void SetPuzzleState(core.Puzzle puzzle, PuzzleSolvedState state)
 {
     try {
         Puzzle dbPuzzle    = GetPuzzle(puzzle);
         var    storedState = GetStoredState(state);
         if (dbPuzzle != null)
         {
             dbPuzzle.SolvedState = storedState;
             connection.Update(dbPuzzle);
         }
         else
         {
             dbPuzzle = CoreToDBPuzzle(puzzle, storedState);
             connection.Insert(dbPuzzle);
         }
     } catch (Exception e) {
         Debug.LogError("Could not set puzzle state in DB: " + e.Message);
     }
 }
示例#6
0
 abstract public void SetPlayed(core.Puzzle puzzle);
示例#7
0
 abstract public PuzzleSolvedState GetPuzzleState(core.Puzzle puzzle);
示例#8
0
 abstract public void SetPuzzleState(core.Puzzle puzzle, PuzzleSolvedState state);
示例#9
0
        /// <summary>
        /// Updates the solved state of the puzzle in the db
        /// </summary>
        /// <param name="puzzle"></param>
        /// <param name="state"></param>

        override public void SetPuzzleState(core.Puzzle puzzle, PuzzleSolvedState state)
        {
            solvedState[puzzle] = state;
        }
示例#10
0
 override public void SetPlayed(core.Puzzle puzzle)
 {
     played.Add(puzzle);
 }
示例#11
0
 /// <summary>
 /// if the puzzle is not present in the db, it's because it was never played,
 /// and therefore it's unsolved
 /// </summary>
 /// <param name="puzzle"></param>
 /// <returns></returns>
 override public PuzzleSolvedState GetPuzzleState(core.Puzzle puzzle)
 {
     return(solvedState[puzzle]);
 }