예제 #1
0
        /// <summary>
        /// This method is reponsible for starting the game
        /// </summary>
        /// <param name="selValue">Value, indicating the selected word category in the dropdown list on the main screen</param>
        /// <returns></returns>
        public ActionResult StartGame(string selValue)
        {
            GameCoordinator gameCoordinator = new GameCoordinator();

            Word wordQuery;

            if (selValue != null)
            {
                // Get random word from the provided Category
                wordQuery = words.All().Where(x => x.Category.Name == selValue).OrderBy(x => Guid.NewGuid()).First();
            }
            else
            {
                // Get the first category from the database and get random word from this category
                selValue  = categories.All().Select(x => x.Name).ToList().First();
                wordQuery = words.All().Where(x => x.Category.Name == selValue)
                            .OrderBy(x => Guid.NewGuid()).First();
            }

            gameCoordinator.StartGame(this.User.Identity.GetUserId(), wordQuery.Value,
                                      wordQuery.Clue, categories.All().Select(x => x.Name).ToList(), selValue);

            return(View("../Game/Game", gameCoordinator.ViewModel));
        }