Example #1
0
        static void Main(string[] args)
        {
            using (HangmanContext db = new HangmanContext())
            {
                while (true)
                {
                    Console.WriteLine("If you don't want to add words then press Backspace, else to continue - any button.");
                    ConsoleKeyInfo key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.Backspace)
                    {
                        Console.Clear();
                        break;
                    }
                    Console.WriteLine("There are words in database:");
                    var words = db.Words.ToList();
                    foreach (Words w in words)
                    {
                        Console.WriteLine($"{w.Id} - {w.Word}");
                    }
                    Console.WriteLine("Enter the words to add to the database.");
                    Words wordAdd = new Words {
                        Word = Console.ReadLine().ToUpper()
                    };
                    db.Words.Add(wordAdd);
                    Console.Clear();
                }
                db.SaveChanges();
                Console.Clear();
                //Random word selection
                Words  selectionWord = new Words();
                Random rand          = new Random();
                int    toSkip        = rand.Next(1, db.Words.Count());
                db.Words.Skip(toSkip).Take(1).First();
                selectionWord = db.Words.OrderBy(r => Guid.NewGuid()).Skip(toSkip).Take(1).First();
                string tempWord = selectionWord.Word;
                tempWord = tempWord.ToUpper();
                foreach (char letter in tempWord)
                {
                    _word.Add(letter);
                }
            }
            Console.Clear();
            //The main cycle of the game. Guessing letters
            bool retry = true;

            while (retry)
            {
                Console.WriteLine("You have {0} attemps. Word length is {1}", mistakes, _word.Count);
                Console.WriteLine("You have already entered these letters: {0}", enteredChar);
                retry = selectionLetter(retry);
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            using  (var ctx = new HangmanContext())
            {
                IUiMassageFactory massageFactory = new UiMassageFactory();
                var welcomeChoice = massageFactory.WelcomeMessage();

                if (welcomeChoice == choiceZaidimas)
                {
                    IGameService gameService = new GameService();
                    gameService.Begin();
                }
                if (welcomeChoice == choiceStatistika)
                {
                    IStatisticsService service = new StatisticsService();
                    service.Begin();
                }
            }
        }