Exemple #1
0
        static void Main(string[] args)
        {
            #region Pre-Preparazione liste
            /* Creazione ed aggiunta degl'handler nella lista degl'handler. */
            List <IUIHandler> handlers = new List <IUIHandler>();
            UIConsoleHandler  cnsHnd   = new UIConsoleHandler();
            handlers.Add(cnsHnd);

            /* Creazione del dizionario d'anagrammi locale (già popolato nella classe). */
            //List<IAnagramRepo> anagramRepos = new List<IAnagramRepo>();
            LocalAnagramRepo localRepo    = new LocalAnagramRepo();
            IAnagramRepo     selectedRepo = localRepo;


            /* Creazione e popolamento della lista dei gameplay. */
            List <IGameplay> gameplays = new List <IGameplay>();
            Training         training  = new Training();
            gameplays.Add(training);
            Challenge challenge = new Challenge();
            gameplays.Add(challenge);
            #endregion

            foreach (IUIHandler handler in handlers)
            {
                handler.WriteStringToUI("Anagrammi!");
                handler.WriteStringToUI("");

                /* Visualizza modalità. */
                handler.WriteStringToUI("Modalità disponibili:");
                handler.WriteStringToUI("Codice\tNome\tDescrizione");
                foreach (IGameplay gameplayMode in gameplays)
                {
                    handler.WriteStringToUI($"- {gameplayMode.Code.ToLower()}\t{gameplayMode.Name}");
                    handler.WriteStringToUI($"\t\t{gameplayMode.Description}");
                    handler.WriteStringToUI($"");
                }

                /* Scelta modalità. */
                IGameplay selectedGameplay = SelectGameplay(gameplays, handler);
                selectedGameplay.RunGameplay(selectedRepo, handlers);
            }



            /*
             * cnsHnd.WriteStringToUI("Scrittura tramite handler");
             *
             * string test01 = cnsHnd.AskForString("prova");
             * cnsHnd.WriteStringToUI(test01);
             *
             * cnsHnd.WriteStringToUI(cnsHnd.AskForString("Richiesta d\'input"));
             */


            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.Write("Premere [Invio] per uscire ... ");
            Console.ReadLine();
        }
Exemple #2
0
        public void RunGameplay(IAnagramRepo chosenRepo, List <IUIHandler> usedUIHandlers)
        {
            foreach (IUIHandler handler in usedUIHandlers)
            {
                string inWord = "?";
                while (inWord != "000")
                {
                    handler.WriteStringToUI($" ");
                    handler.WriteStringToUI($"Modalità {Name}: {Description}");
                    handler.WriteStringToUI($" ");

                    inWord = handler.AskForString("Immettere una parola (immettere «000» per uscire dalla modalità) ...");

                    if (inWord == "000")
                    {
                        break;
                    }

                    List <string> anagramList = new List <string>();
                    anagramList = chosenRepo.ReturnFullAnagramList();
                    anagramList = chosenRepo.FromWordToAnagramList(inWord);

                    handler.WriteStringToUI($"Lista d\'anagrammi di «{inWord}»:");

                    foreach (string anagram in anagramList)
                    {
                        handler.WriteStringToUI($" {anagram}");
                    }
                }
            }
        }
Exemple #3
0
        public void RunGameplay(IAnagramRepo chosenRepo, List <IUIHandler> usedUIHandlers)
        {
            foreach (IUIHandler handler in usedUIHandlers)
            {
                string inWord = "?";
                while (inWord != "000")
                {
                    handler.WriteStringToUI($" ");
                    handler.WriteStringToUI($"Modalità {Name}: {Description}");
                    handler.WriteStringToUI($" ");

                    string givenWord = chosenRepo.GetRandomWord_WichHasAnagrams();



                    requestMoment  = DateTime.Now;
                    inWord         = handler.AskForString($"Immettere un anagramma della parola «{givenWord}» (immettere «000» per uscire dalla modalità) ...");
                    responseMoment = DateTime.Now;

                    if (inWord == "000")
                    {
                        break;
                    }

                    if (chosenRepo.TheseAreAnagrams(givenWord, inWord))
                    {
                        int points = CalculateGainedPoints(requestMoment, responseMoment, pointScale, sAvailableMaxTime, out int elapsedSeconds);
                        handler.WriteStringToUI($"Anagramma trovato in {elapsedSeconds}!");
                        handler.WriteStringToUI($"Guadagnati {points} punti!");
                    }
                    else
                    {
                        handler.WriteStringToUI("Anagramma non trovato!");
                    }


                    List <string> anagramList = new List <string>();
                    anagramList = chosenRepo.ReturnFullAnagramList();
                    anagramList = chosenRepo.FromWordToAnagramList(inWord);

                    handler.WriteStringToUI($"Lista d\'anagrammi di «{inWord}»:");

                    foreach (string anagram in anagramList)
                    {
                        handler.WriteStringToUI($" {anagram}");
                    }
                }
            }
        }