Beispiel #1
0
        private List <Puzzle> QueryWithState(Level.LevelRef lref, PuzzleSolvedState[] states)
        {
            var typeStr      = lref.type.ToString();
            var solvedStr    = lref.cc.ToCompactString();
            var storedStates = DbStoredStates(states);

            var  sb    = new StringBuilder().Append('(');
            bool first = true;

            foreach (var st in storedStates)
            {
                if (!first)
                {
                    sb.Append(',');
                }
                sb.Append((int)st);
                first = false;
            }
            sb.Append(')');
            var result = connection.Query <Puzzle>(
                "SELECT * FROM Puzzle WHERE type = ? AND SolvedConfig = ? AND SolvedState in " + sb.ToString() + " ORDER BY SolvedState;",
                typeStr, solvedStr);

            return(result);
        }
Beispiel #2
0
 override public void SetLevelPlayed(Level.LevelRef lref)
 {
     connection.InsertOrReplace(new LevelPlayed {
         LevelRef  = lref.ToCompactString(),
         Timestamp = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond
     });
 }
Beispiel #3
0
        override public SolvedStats GetLevelStats(Level.LevelRef lref)
        {
            var count = new Dictionary <PuzzleSolvedState, int>();

            count[PuzzleSolvedState.Unsolved] = 0;
            count[PuzzleSolvedState.Ok]       = 0;
            count[PuzzleSolvedState.Good]     = 0;
            count[PuzzleSolvedState.Perfect]  = 0;

            foreach (var ps in solvedState)
            {
                var puzzle = ps.Key;
                var state  = ps.Value;
                if (lref.Equals(puzzle.LevelRef))
                {
                    count[state]++;
                }
            }

            return(new SolvedStats(
                       count[PuzzleSolvedState.Unsolved],
                       count[PuzzleSolvedState.Ok],
                       count[PuzzleSolvedState.Good],
                       count[PuzzleSolvedState.Perfect]));
        }
Beispiel #4
0
        override public SolvedStats GetLevelStats(Level.LevelRef lref)
        {
            string q         = "SELECT DISTINCT SolvedState, count(*) AS Num FROM Puzzle WHERE type = ? AND SolvedConfig = ? GROUP BY SolvedState;";
            var    typeStr   = lref.type.ToString();
            var    solvedStr = lref.cc.ToCompactString();
            var    results   = connection.Query <StatQuery>(q, new object[] { typeStr, solvedStr });

            return(FillStats(results));
        }
Beispiel #5
0
        /// <summary>
        /// returns a list of the puzzles whose state matches any of the listed ones.
        /// </summary>
        /// <param name="lref"></param>
        /// <param name="states"></param>
        /// <returns></returns>
        override public int PuzzlesWithState(Level.LevelRef lref, params PuzzleSolvedState[] states)
        {
            int count = 0;

            foreach (var puzzle in solvedState.Keys)
            {
                if (puzzle.LevelRef.Equals(lref) && Array.IndexOf(states, solvedState[puzzle]) != -1)
                {
                    count++;
                }
            }
            return(count);
        }
Beispiel #6
0
 abstract public void SetLevelPlayed(Level.LevelRef lref);
Beispiel #7
0
 abstract public SolvedStats GetLevelStats(Level.LevelRef lref);
Beispiel #8
0
 abstract public int PuzzlesWithState(Level.LevelRef lref, params PuzzleSolvedState[] states);
Beispiel #9
0
 /// <summary>
 /// returns a list of the puzzles whose state matches any of the listed ones.
 /// </summary>
 /// <param name="lref"></param>
 /// <param name="states"></param>
 /// <returns></returns>
 override public int PuzzlesWithState(Level.LevelRef lref, params PuzzleSolvedState[] states)
 {
     return(QueryWithState(lref, states).Count());
 }
Beispiel #10
0
 override public void SetLevelPlayed(Level.LevelRef lref)
 {
     levelsPlayed.Add(lref);
 }