Exemplo n.º 1
0
        public static int ScoreGame(string input, GamesEnum gameType = GamesEnum.TenPin)
        {
            IGame myGame = BuildGame(gameType);

            myGame.ParseGameScore(input);
            return(myGame.GetTotalScore());
        }
Exemplo n.º 2
0
 public static string GetGameName(GamesEnum game)
 {
     return(game switch
     {
         GamesEnum.Oblivion => Constants.Constants.GameNameOblivion,
         GamesEnum.Fallout => Constants.Constants.GameNameFallout3,
         GamesEnum.NewVegas => Constants.Constants.GameNameNewVegas,
         GamesEnum.Skyrim => Constants.Constants.GameNameSkyrim,
         _ => "",
     });
Exemplo n.º 3
0
        private static IGame BuildGame(GamesEnum gameType)
        {
            switch (gameType)
            {
            case GamesEnum.FivePin:
                return(new FivePin());

            default:
                return(new TenPin());
            }
        }
Exemplo n.º 4
0
        public IList <QuestionPair> InitializeGame(int dictionaryId, int userId, GamesEnum gameId, int count)
        {
            var questions   = GetQuestionsIds(dictionaryId, userId, gameId, count).ToList();
            var gameSession = InitializeBaseGame(dictionaryId, userId, gameId);
            var result      = questions.Select(x => new QuestionPair
            {
                GameSessionId = gameSession.Id,
                TranslationId = x
            })
                              .ToList();

            return(result);
        }
Exemplo n.º 5
0
        public GameSession InitializeBaseGame(int dictionaryId, int userId, GamesEnum gameId)
        {
            var gameSession = new GameSession
            {
                DictionaryId = dictionaryId,
                UserId       = userId,
                GameId       = (int)gameId,
                DateStart    = DateTime.Now
            };

            GameSessionsRepository.Insert(gameSession);
            GameSessionsRepository.Save();

            return(gameSession);
        }
Exemplo n.º 6
0
        public Game(GamesEnum games, MainViewModel mainViewModel)
        {
            this.mainViewModel = mainViewModel;
            this.GetGamesEnum  = games;
            if (games == GamesEnum.Dice)
            {
                GameViewModel = new DiceViewModel(this);
                LogicGame     = new Logic.Dice(GameViewModel);
                page          = new Pages.Dice(GameViewModel as DiceViewModel);
            }
            else if (games == GamesEnum.Lottery)
            {
                GameViewModel = new LotteryViewModel(this);
                LogicGame     = new Logic.Lottery(GameViewModel);
                page          = new Pages.Lottery(GameViewModel as LotteryViewModel);
            }

            GameButton.Content         = LogicGame.Name;
            GameButton.Command         = new Command((obj) => { mainViewModel.ActuallyBody = page; });
            mainViewModel.ActuallyBody = page;
            mainViewModel.AddButtons(GameButton);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Metoda wybierająca pytania dla wybranego słownika, użytkownika oraz gry
        /// Sposób wyboru:
        /// - wszystkie odpowiedzi dla danego słownika, użytkownika oraz gry
        /// - pobranie słowek ze słownika, dla których nie ma odpowiedzi
        /// - pogrupowanie po pytaniu (słówku)
        /// - wyliczenie liczby odpowiedzi na dane pytanie
        /// - wyliczenie stosunku poprawnych odpowiedzi do błędnych odpowiedzi
        /// - sortowanie po liczbe odpowiedzi (od najmniejszej)
        /// - następne sortowanie po ratio (od największego - najgorszy wynik)
        /// - ostatnie "sortowanie" to rozrzucenie pytań, aby zmienić ich kolejność na losową
        /// - wybór min(count, liczbaPytanWSlowniku) pierwszych pytań z listy
        /// - zwrócenie listy idków pytań
        /// </summary>
        /// <param name="dictionaryId">Id słownika</param>
        /// <param name="userId">Id użytkownika</param>
        /// <param name="gameId">Id gry</param>
        /// <param name="count">Max liczba pytań</param>
        /// <returns>List idków słówek do pytania</returns>
        private IList <int> GetQuestionsIds(int dictionaryId, int userId, GamesEnum gameId, int count)
        {
            var answeredQuestions = Context.GameSessionTranslations
                                    .Where(x => x.GameSession.GameId == (int)gameId)
                                    .Where(x => x.GameSession.UserId == userId)
                                    .Where(x => x.GameSession.DictionaryId == dictionaryId)
                                    .Select(x => new { x.TranslationId, x.Correct })
                                    .ToList();

            var ids = answeredQuestions.Select(x => x.TranslationId).ToList();
            var notAnsweredQuestions = Context.Translations
                                       .Where(x => x.DictionaryId == dictionaryId && !ids.Contains(x.Id))
                                       .Select(x => new { TranslationId = x.Id, Correct = false })
                                       .ToList();

            answeredQuestions.AddRange(notAnsweredQuestions);

            var result = answeredQuestions
                         .GroupBy(x => x.TranslationId, (k, v) => new
            {
                TranslationId = k,
                Answers       = v.Count(),
                // zabezpieczenie przed dzieleniem przez 0
                Ratio = (decimal)(v.Count(y => y.Correct) + 1) / (v.Count(y => !y.Correct) + 1)
            })
                         .OrderBy(x => x.Answers)
                         .ThenByDescending(x => x.Ratio)
                         .ThenBy(x => Guid.NewGuid())
                         .ToList();

            var maxElements = Math.Min(count, result.Count);

            return(result
                   .Take(maxElements)
                   .Select(x => x.TranslationId)
                   .ToList());
        }
Exemplo n.º 8
0
        /// <summary>
        /// Removes ExtractLocations that are not relevant to game
        /// </summary>
        /// <returns></returns>
        public static List <ExtractLocation> FilterForGame(this List <ExtractLocation> list, GamesEnum game)
        {
            switch (game)
            {
            case GamesEnum.Fallout:
                list.Remove(ExtractLocation.DataObsePlugins);
                list.Remove(ExtractLocation.DataNvsePlugins);
                return(list);

            case GamesEnum.NewVegas:
                list.Remove(ExtractLocation.DataObsePlugins);
                list.Remove(ExtractLocation.DataFosePlugins);
                return(list);

            case GamesEnum.Oblivion:
                return(list);

            case GamesEnum.Skyrim:
                list.Remove(ExtractLocation.DataObsePlugins);
                list.Remove(ExtractLocation.DataNvsePlugins);
                list.Remove(ExtractLocation.DataFosePlugins);
                return(list);

            default:
                return(list);
            }
        }
Exemplo n.º 9
0
 public void AddGame(GamesEnum game)
 {
     games.Add(new Game(game, this));
 }