Esempio n. 1
0
        public static void NewGame()
        {
            Console.Clear();

            if (!gameContinue)
            {
                Console.WriteLine("Введите ваш никнейм");
                playerName = Console.ReadLine().Trim(' ');
                Console.Clear();

                Console.WriteLine("Введите уровень от 5 до 28");

                Field.lvl = ReadLvl();
                Console.Clear();

                Console.Write("Идёт создание карты филвордов...");

                field = Field.FillField();
                Console.Clear();

                quessedWords      = new char[Field.xLenght, Field.yLenght];
                numOfQuessedWords = 0;

                for (int i = 0; i < Field.xLenght; i++)
                {
                    for (int j = 0; j < Field.yLenght; j++)
                    {
                        Console.SetCursorPosition(i, j);
                        Console.Write(field[i, j]);
                    }
                }
            }
            else
            {
                for (int i = 0; i < Field.xLenght; i++)
                {
                    for (int j = 0; j < Field.yLenght; j++)
                    {
                        if (quessedWords[i, j] == '*')
                        {
                            PrintingColoredChar(i, j, "green");
                        }
                        else
                        {
                            PrintingColoredChar(i, j, "black");
                        }
                    }
                }
                gameContinue = false;
            }



            for (int i = 0; i < 1; i++)
            {
                Console.SetCursorPosition(0, i + Field.yLenght + 1);
                Console.Write(Field.fieldWords1[i]);
            }


            Console.SetCursorPosition(0, 0);

            ConsoleKeyInfo key;
            int            x           = 0;
            int            y           = 0;
            string         currentWord = null;


            bool stopFor = false;

            bool wordIsQuessed = true;
            int  firstLetter   = 0;


            char[,] thisTry = new char[Field.xLenght, Field.yLenght];
            bool enter = false;


            for (; ;)
            {
                if (stopFor)
                {
                    Console.SetCursorPosition(Field.xLenght + 1, 0);
                    Console.Write("Правильно!");
                    Continue.DeleteFile();
                    Records.Read();
                    if (Records.names.Contains(playerName))
                    {
                        for (int i = 0; i < Records.names.Count; i++)
                        {
                            if (Records.names[i] == playerName)
                            {
                                Records.points[i] += Field.xLenght * Field.yLenght;
                                break;
                            }
                        }
                    }
                    else
                    {
                        Records.names.Add(playerName);
                        Records.points.Add(Field.xLenght * Field.yLenght);
                    }
                    Records.WriteInFile();
                    break;
                }

                Console.SetCursorPosition(x, y);
                key = Console.ReadKey();

                if (quessedWords[x, y] != '*' && !enter)
                {
                    PrintingColoredChar(x, y, "black");
                }
                else if (enter)
                {
                    PrintingColoredChar(x, y, "red");
                }
                else if (quessedWords[x, y] == '*')
                {
                    PrintingColoredChar(x, y, "green");
                }


                switch (key.Key)
                {
                case ConsoleKey.UpArrow:
                    if (IsEnterInFieldArea(x, y - 1) && thisTry[x, y - 1] != '*')
                    {
                        if (!enter)
                        {
                            PrintingColoredChar(x, y - 1, "blue");
                            y--;
                        }

                        if (enter && quessedWords[x, y - 1] != '*')
                        {
                            y            -= 1;
                            currentWord  += field[x, y];
                            thisTry[x, y] = '*';
                            PrintingColoredChar(x, y, "red");
                            if (firstLetter != Field.numField1[x, y])
                            {
                                wordIsQuessed = false;
                            }
                        }
                    }
                    else
                    {
                        PrintingColoredChar(x, y, "blue");
                    }
                    break;

                case ConsoleKey.DownArrow:
                    if (IsEnterInFieldArea(x, y + 1) && thisTry[x, y + 1] != '*')
                    {
                        if (!enter)
                        {
                            PrintingColoredChar(x, y + 1, "blue");
                            y++;
                        }

                        if (enter && quessedWords[x, y + 1] != '*')
                        {
                            y            += 1;
                            currentWord  += field[x, y];
                            thisTry[x, y] = '*';
                            PrintingColoredChar(x, y, "red");
                            if (firstLetter != Field.numField1[x, y])
                            {
                                wordIsQuessed = false;
                            }
                        }
                    }
                    else
                    {
                        PrintingColoredChar(x, y, "blue");
                    }
                    break;

                case ConsoleKey.LeftArrow:
                    if (IsEnterInFieldArea(x - 1, y) && thisTry[x - 1, y] != '*')
                    {
                        if (!enter)
                        {
                            PrintingColoredChar(x - 1, y, "blue");
                            x--;
                        }

                        if (enter && quessedWords[x - 1, y] != '*')
                        {
                            x            -= 1;
                            currentWord  += field[x, y];
                            thisTry[x, y] = '*';
                            PrintingColoredChar(x, y, "red");
                            if (firstLetter != Field.numField1[x, y])
                            {
                                wordIsQuessed = false;
                            }
                        }
                    }
                    else
                    {
                        PrintingColoredChar(x, y, "blue");
                    }
                    break;

                case ConsoleKey.RightArrow:
                    if (IsEnterInFieldArea(x + 1, y) && thisTry[x + 1, y] != '*')
                    {
                        if (!enter)
                        {
                            PrintingColoredChar(x + 1, y, "blue");
                            x++;
                        }

                        if (enter && quessedWords[x + 1, y] != '*')
                        {
                            x            += 1;
                            currentWord  += field[x, y];
                            thisTry[x, y] = '*';
                            PrintingColoredChar(x, y, "red");

                            if (firstLetter != Field.numField1[x, y])
                            {
                                wordIsQuessed = false;
                            }
                        }
                    }
                    else
                    {
                        PrintingColoredChar(x, y, "blue");
                    }
                    break;

                case ConsoleKey.Enter:
                    if (!enter)
                    {
                        thisTry     = ClearArray();
                        currentWord = null;
                        PrintingColoredChar(x, y, "red");
                        currentWord  += field[x, y];
                        thisTry[x, y] = '*';
                        wordIsQuessed = true;
                        firstLetter   = Field.numField1[x, y];
                    }
                    else
                    {
                        if (Field.fieldWords1.Contains(currentWord) && wordIsQuessed)
                        {
                            numOfQuessedWords++;
                            if (numOfQuessedWords >= Field.fieldWords1.Count)
                            {
                                stopFor = true;
                            }

                            for (int i = 0; i < Field.xLenght; i++)
                            {
                                for (int j = 0; j < Field.yLenght; j++)
                                {
                                    if (thisTry[i, j] == '*')
                                    {
                                        quessedWords[i, j] = '*';
                                    }
                                }
                            }
                        }


                        for (int i = 0; i < Field.xLenght; i++)
                        {
                            for (int j = 0; j < Field.yLenght; j++)
                            {
                                if (quessedWords[i, j] == '*')
                                {
                                    PrintingColoredChar(i, j, "green");
                                }
                                else
                                {
                                    PrintingColoredChar(i, j, "black");
                                }
                            }
                        }

                        currentWord = "";
                        thisTry     = ClearArray();
                    }
                    enter = !enter;
                    break;

                case ConsoleKey.S:
                    Continue.SaveGame();
                    Console.Clear();
                    Program.Main();
                    break;

                default:
                    PrintingColoredChar(x, y, "black");
                    break;
                }
            }



            Console.ReadKey();
            Console.Clear();
            Program.Main();
        }
Esempio n. 2
0
        public static void Main()
        {
            const int RIGHTINDENT = 5;   // отступ справа
            const int UPINDENT    = 5;   // отступ сверху
            const int WIDTH       = 10;  // ширина
            const int LENGHT      = 4;   // длина

            Menu.DrawFrame(RIGHTINDENT, UPINDENT, WIDTH, LENGHT);

            string[] menustrings = { "Новая игра", "Продолжить", "Рейтинг", "Выход" };

            for (int i = 0; i < menustrings.Length; i++)
            {
                Menu.SetCursorAndWrite(menustrings[i], RIGHTINDENT, UPINDENT + i);
            }

            int selectedLine = 0;

            Menu.SelectingString(menustrings[selectedLine], menustrings[selectedLine], RIGHTINDENT, RIGHTINDENT + WIDTH, UPINDENT + selectedLine, UPINDENT);
            ConsoleKeyInfo key;

            for (; ;)
            {
                Console.SetCursorPosition(RIGHTINDENT - 1, UPINDENT + LENGHT + 1);
                key = Console.ReadKey();

                if (key.Key == ConsoleKey.W || key.Key == ConsoleKey.UpArrow && selectedLine != 0)
                {
                    selectedLine--;
                    Menu.SelectingString(menustrings[selectedLine + 1], menustrings[selectedLine], RIGHTINDENT, RIGHTINDENT + WIDTH, UPINDENT + selectedLine + 1, UPINDENT + selectedLine);
                }

                if (key.Key == ConsoleKey.S || key.Key == ConsoleKey.DownArrow && selectedLine != LENGHT - 1)
                {
                    selectedLine++;
                    Menu.SelectingString(menustrings[selectedLine - 1], menustrings[selectedLine], RIGHTINDENT, RIGHTINDENT + WIDTH, UPINDENT + selectedLine - 1, UPINDENT + selectedLine);
                }

                if (key.Key == ConsoleKey.Enter)
                {
                    Console.Clear();
                    switch (selectedLine)
                    {
                    case 0:
                        Continue.DeleteFile();
                        Game.NewGame();

                        break;

                    case 1:
                        Continue.ContinueGame();
                        break;

                    case 2:
                        Records.ReadAndPrint();
                        Console.ReadKey();
                        Console.Clear();
                        Program.Main();
                        break;

                    case 3:
                        Environment.Exit(0);
                        break;
                    }
                }
            }
        }