示例#1
0
        internal void Update(Level sender)
        {
            Debug.WriteLine("Update start");
            using (var db = new GameContext())
            {
                BaseGame changeLevel = new BaseGame();
                switch (sender.RuleMode)
                {
                case "RuleAddition":
                    GameAddition additionLevel = db.GamesAddition.Single(p => p.BeginRange == sender.BeginRange &&
                                                                         p.EndRange == sender.EndRange);
                    changeLevel = additionLevel;
                    db.GamesAddition.Single(p => p.GameAdditionId == (additionLevel.GameAdditionId + 1)).IsOpen = true;
                    break;

                case "RuleMultiplication":
                    GameMultiplication multiplicationLevel = db.GamesMultiplication.Single(p => p.BeginRange == sender.BeginRange &&
                                                                                           p.EndRange == sender.EndRange);
                    changeLevel = multiplicationLevel;
                    db.GamesMultiplication.Single(p => p.GameMultiplicationId == (multiplicationLevel.GameMultiplicationId + 1)).IsOpen = true;
                    break;

                default:
                    break;
                }
                changeLevel.Raiting = sender.Raiting;
                db.SaveChanges();
            }
            Debug.WriteLine("Update end");
        }
示例#2
0
        private LevelViewModel GetNextLevel()
        {
            Level          currentLevel = (Level)level;
            LevelViewModel result       = new LevelViewModel(currentLevel);
            BaseGame       baseGame     = new BaseGame();

            using (var db = new GameContext())
            {
                switch (currentLevel.RuleMode)
                {
                case "RuleAddition":
                    GameAddition additionLevel = db.GamesAddition.Single(p => p.BeginRange == currentLevel.BeginRange &&
                                                                         p.EndRange == currentLevel.EndRange);
                    baseGame = db.GamesAddition.Single(p => p.GameAdditionId == (additionLevel.GameAdditionId + 1));
                    break;

                case "RuleMultiplication":
                    GameMultiplication multiplicationLevel = db.GamesMultiplication.Single(p => p.BeginRange == currentLevel.BeginRange &&
                                                                                           p.EndRange == currentLevel.EndRange);
                    baseGame = db.GamesMultiplication.Single(p => p.GameMultiplicationId == (multiplicationLevel.GameMultiplicationId + 1));
                    break;

                default:
                    break;
                }
            }
            if (baseGame != new BaseGame())
            {
                Level nextLevel = new Level(baseGame.IsOpen, baseGame.Raiting, baseGame.BeginRange, baseGame.EndRange);
                result = new LevelViewModel(nextLevel);
            }
            return(result);
        }