コード例 #1
0
        public static string RandomWordGen(int category)
        {
            string[][] wordsForTheGame = new string[11][]; //11 strings for 11 categories
            wordsForTheGame[0] = File.ReadAllLines
                                     (Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Words\Countries.txt"));
            wordsForTheGame[1] = File.ReadAllLines
                                     (Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Words\City.txt"));
            wordsForTheGame[2] = File.ReadAllLines
                                     (Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Words\River.txt"));
            wordsForTheGame[3] = File.ReadAllLines
                                     (Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Words\Mountains.txt"));
            wordsForTheGame[4] = File.ReadAllLines
                                     (Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Words\Animal.txt"));
            wordsForTheGame[5] = File.ReadAllLines
                                     (Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Words\Plants.txt"));
            wordsForTheGame[6] = File.ReadAllLines
                                     (Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Words\Cars.txt"));
            wordsForTheGame[7] = File.ReadAllLines
                                     (Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Words\Lectors.txt"));
            wordsForTheGame[8] = File.ReadAllLines
                                     (Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Words\islands.txt"));
            wordsForTheGame[9] = File.ReadAllLines
                                     (Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Words\planets.txt"));
            wordsForTheGame[10] = File.ReadAllLines
                                      (Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Words\flowers.txt"));

            int numberOfWord = GameMethods.GiveMeRandomNum((int)0, wordsForTheGame[category].Length - 1); // this is the range of the arrey (0, wordsForTheGame[category].Length - 1)

            return(wordsForTheGame[category][numberOfWord].Trim().ToLower());
        }
コード例 #2
0
        static void Main()
        {
            Console.WindowHeight = 30;
            Console.WindowWidth  = 90;
            Console.BufferHeight = 30;
            Console.BufferWidth  = 90;


            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            Console.InputEncoding  = Encoding.Unicode;
            Console.OutputEncoding = Encoding.Unicode;
            string doYouWantToPlayAgain = "д";

            do
            {
                Console.Clear();
                int temp = GameMethods.StartMenu(); // say HI and play = 1  or  add word = 0
                if (temp == 1)
                {
                    Console.Clear();
                    GameMethods.PrintMenu(); //topics
                }
                else if (temp == 0)          // add word and return to start menu ()
                {
                    bool nextWord = GameMethods.AddWord();
                    while (nextWord)
                    {
                        nextWord = GameMethods.AddWord();
                    }
                    continue;
                }
                string categoryStr;
                int    category;
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.Write("Въведете число от 1 до 11: ");
                do
                {
                    categoryStr = Console.ReadLine();
                    if (!GameMethods.IsValidNum1_11(categoryStr))
                    {
                        Console.Write("Въведете число от 1 до 11: ");
                    }
                } while (!GameMethods.IsValidNum1_11(categoryStr));
                category = int.Parse(categoryStr);


                string theWord = GameMethods.RandomWordGen(category - 1); // random word for hangman
                GameMethods.GamePlay(theWord, category);                  // guess the word

                Console.ResetColor();
                Console.SetCursorPosition(23, 16);
                Console.WriteLine("Нова игра? Д/Н");
                do
                {
                    doYouWantToPlayAgain = Console.ReadLine().ToLower();
                    if (doYouWantToPlayAgain != "н" && doYouWantToPlayAgain != "д")
                    {
                        Console.SetCursorPosition(12, 17);
                        Console.WriteLine("Нова игра? Връщане в главно меню? Д/Н");
                    }
                } while (doYouWantToPlayAgain != "н" && doYouWantToPlayAgain != "д");
            } while (doYouWantToPlayAgain == "д");
        }
コード例 #3
0
        public static void GamePlay(string theWord, int category)
        {
            Console.Clear();
            string[] cetegoryStrMass = { "Държави",
                                         "Градове в България",
                                         "Реки в България",
                                         "Планини",
                                         "Животни",
                                         "Растения",
                                         "Автомобили (марки/модели)",
                                         "Лектори в СофтУни",
                                         "Острови",
                                         "Планети",
                                         "Цветя" };
            char[]   theWordInArrey = theWord.ToCharArray();
            char[]   hidenWordArrey = new char[theWordInArrey.Length];
            int      lettersInWord  = 0;

            for (int i = 0; i < theWordInArrey.Length; i++)
            {
                if (theWordInArrey[i] != ' ')
                {
                    hidenWordArrey[i] = '_';
                    lettersInWord++;
                }
                else
                {
                    hidenWordArrey[i] = ' ';
                }
            }
            Console.ForegroundColor = ConsoleColor.DarkCyan;
            Console.WriteLine(String.Join(" ", hidenWordArrey));
            Console.Write("Въведете буква: ");
            List <string> enterdLetters = new List <string>();
            string        letter        = Console.ReadLine();

            //added validation for input letter
            while (letter.Length > 1 || letter == " " || letter == String.Empty)
            {
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine("Моля, въведете само една буква :)");
                Console.Write("Въведете буква: ");
                letter = Console.ReadLine();
            }
            while (!GameMethods.IsValidLetter(letter))
            {
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine("Моля, въведете буква от А до Я.");
                Console.Write("Въведете буква: ");
                letter = Console.ReadLine();
            }
            enterdLetters.Add(letter);
            int counterForErrors = 0;

            while (true)
            {
                Console.Clear();
                bool guesLetter = false;
                int  howManyLettertAreGuested = 0;
                Console.SetCursorPosition(0, 1);
                Console.WriteLine("Категория: {0}", cetegoryStrMass[category - 1]);
                Console.SetCursorPosition(0, 2);
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine("Въведохте буквите: \n\r{0}", String.Join(", ", enterdLetters));
                for (int i = 0; i < theWordInArrey.Length; i++)
                {
                    char currentEnteredChar = Convert.ToChar(letter);
                    if (currentEnteredChar == theWordInArrey[i])
                    {
                        hidenWordArrey[i] = theWordInArrey[i];
                        guesLetter        = true;
                    }
                    if (hidenWordArrey[i] == theWordInArrey[i] && hidenWordArrey[i] != ' ')
                    {
                        howManyLettertAreGuested++;
                    }
                }
                if (guesLetter == false)
                {
                    counterForErrors++;
                }
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine("Остават Ви {0} грешни опита! \n\r", 9 - counterForErrors);
                Console.WriteLine(String.Join(" ", hidenWordArrey));
                Console.WriteLine();
                GameMethods.DrawingGallowAndHangman(counterForErrors);
                if (counterForErrors == 9)
                {
                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.BackgroundColor = ConsoleColor.DarkRed;
                    Console.SetCursorPosition(15, 15);
                    Console.WriteLine("Играта свърши!!! Обесени сте!!!!");
                    break;
                }
                if (howManyLettertAreGuested == lettersInWord)
                {
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.SetCursorPosition(20, 15);
                    Console.WriteLine("ЧЕСТИТО!!! СПЕЧЕЛИ!!!");
                    GameMethods.PlayMusic();
                    break;
                }
                Console.SetCursorPosition(0, 8);
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.Write("Въведете буква: ");
                letter = Console.ReadLine();
                //added validation for input letter
                while (letter.Length > 1 || letter == " " || letter == String.Empty)
                {
                    Console.ForegroundColor = ConsoleColor.DarkCyan;
                    Console.WriteLine("Моля, въведете само една буква :)");
                    Console.Write("Въведете буква: ");
                    letter = Console.ReadLine();
                }
                while (!GameMethods.IsValidLetter(letter))
                {
                    Console.ForegroundColor = ConsoleColor.DarkCyan;
                    Console.WriteLine("Моля, въведете буква от А до Я.");
                    Console.Write("Въведете буква: ");
                    letter = Console.ReadLine();
                }

                enterdLetters.Add(letter);
            }
        }